CentOS 7下搭建LAMP并把MySQL单独分离

前端之家收集整理的这篇文章主要介绍了CentOS 7下搭建LAMP并把MySQL单独分离前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

CentOS 7下搭建LAMP并把MysqL单独分离

原文:http://www.linuxidc.com/Linux/2017-05/144037.htm

环境:
系统:CentOS-7-x86_64-Minimal-1611
Apache:httpd-2.4.25.tar
MysqLMysqL-5.7.16.tar
PHPPHP-5.6.30.tar
192.168.57.144:安装MysqL
192.168.57.143:安装Apache+PHP

搭建LAMP平台并实现PHPMysqL读写分离 见 http://www.linuxidc.com/Linux/2017-05/144029.htm
创建相关目录
创建用户
解压安装包
编译安装
(初始化)
链接bin目录
拷贝脚本文件,主配置文件
配置主配置文件
脚本自启动
验证服务
验证对接服务


一・编译安装Apache

yum install lrzsz
cd /usr/local/
tar -zxf httpd-2.4.25.tar.gz

yum install gcc* gcc-c++*
yum install apr* apr-util apr-devel pcre* pcre-devel openssl* openssl-devel -y

编译安装
./configure --prefix=/apps/svr/httpd --enable-so --enable-rewrite --enable-charset-list --enable-cgi
或者:
./configure \
--prefix=/apps/svr/httpd \
--sysconfdir=/apps/conf/\
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-mpm=prefork \
--enable-modules=most \
--enable-mpms-shared=all
echo $?
make
make install

配置http环境变量
ln -s /apps/svr/httpd/bin/* /usr/local/bin/
或者:cat >export PATH=$PATH:/apps/svr/httpd/bin >>/etc/profile
检查配置文件
apachectl -t


设置apache为Linux服务并实现开机自启动
cp /apps/svr/httpd/bin/apachectl /etc/init.d/httpd
或者:设置Apache为Linux服务并实现开机自启动
mv /etc/rc.d/init.d/apachectl /etc/rc.d/init.d/httpd
chmod +x /etc/init.d/httpd

vim /etc/init.d/httpd
#!/bin/sh
#chkconfig:2345 80 80
#description:httpd
#

chkconfig:2345 80 80
2345:是服务识别参数,在级别2345中启动
第一个80:是该服务在第80个启动
第二个80:是该服务在第80个关闭
description:httpd :服务描述信息

chkconfig --add httpd
chkconfig httpd on
chkconfig --list httpd


cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.57.141 www.a.org


cat /apps/svr/httpd/conf/httpd.conf
#ServerName www.example.com:80
ServerName www.a.org


service httpd restart
netstat -anpt |grep httpd

关闭数据库
systemctl stop firewalld


http://www.linuxidc.com/Linux/2017-05/144038.htm

编译安装MysqL-5.7.16

groupadd -r MysqL
useradd -r -g MysqL -s /bin/false -M MysqL

创建MysqL安装文件数据库存储文件、my.cnf文件
mkdir -p /apps/svr/MysqL
mkdir -p /apps/MysqLdb/data
mkdir -p /apps/conf


yum install -y gcc wget make cmake zlib-devel ncurses-devel bison gcc-c++ automake autoconf imake libxml2-devel expat-devel cmake gcc gcc-c++ libaio libaio-devel bzr bison libtool ncurses-devel libxml2-devel expat-devel openssl openssl-devel

下载Boost_1_59_0.tar.gz
wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gz
wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.tar.gz
tar zxvf boost_1_59_0.tar.gz

下载MysqL-5.7.13.tar.gz
wget http://cdn.MysqL.com/Downloads/MysqL-5.7/MysqL-5.7.13.tar.gz
wget https://dev.MysqL.com/get/Downloads/MysqL-5.7/MysqL-5.7.17.tar.gz
tar zxvf MysqL-5.7.17.tar.gz

cd MysqL-5.7.17
cmake . -DCMAKE_INSTALL_PREFIX=/apps/svr/MysqL \
-DMysqL_DATADIR=/apps/MysqLdb/data \
-DSYSCONFDIR=/apps/conf/my.cnf \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_READLINE=1 \
-DWITH_LIBWRAP=0 \
-DMysqL_UNIX_ADDR=/tmp/MysqL.sock \
-DWITH_SSL=system \
-DWITH_ZLIB=system \
-DDOWNLOAD_BOOST=1 \
-DWITH_BOOST=../boost_1_59_0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci


boost_1_59_0 解压放到MysqL上层目录

---------------------------------------------------------------------------------------------------------------------------------
-DCMAKE_INSTALL_PREFIX= 安装根目录
-DCMAKE_INSTALL_PREFIX= unix套接字目录
-DDEFAULT_CHARSET= 默认字符集
-DDEFAULT_COLLATION=默认编码
-DWITH_EXTRA_CHARSETS= 额外的编码,请使用ALL来编译。
-DWITH_MYISAM_STORAGE_ENGINE=1 编译myisam存储引擎,默认的存储引擎,不加也可以
-DWITH_INNOBASE_STORAGE_ENGINE=1 支持InnoDB存储引擎,这个也是默认安装的
-DWITH_READLINE=1 使用readline功能
-DENABLED_LOCAL_INFILE=1 可以使用load data infile命令从本地导入文件
-DMysqL_DATADIR=数据库 数据目录
---------------------------------------------------------------------------------------------------------------------------------

grep processor /proc/cpuinfo 个数x2

make或者:make -j $(grep processor /proc/cpuinfo |wc -l)
make install


cat >export PATH=$PATH:/apps/svr/MysqL/bin >>/etc/profile
Source /etc/profile
或者:ln -s /apps/svr/MysqL/bin /usr/local/bin

chown -R MysqL:MysqL /apps/svr/MysqL
chown -R MysqL:MysqL /apps/conf
chown -R MysqL:MysqL /apps/MysqLdb

rm -rf /etc/my.cnf

导出配置文件
cd MysqL-5.7.16
cp support-files/my-default.cnf /apps/conf/my.cnf
cp support-files/my-default.cnf /etc/


初始化数据库
注:
1 之前版本MysqL_install_db是在MysqL_basedir/script下,5.7放在了MysqL_install_db/bin目录下,且已被废弃
2 "--initialize"会生成一个随机密码(~/.MysqL_secret),而"--initialize-insecure"不会生成密码
3 --datadir目标目录下不能有数据文件


初始化(测试OK):/apps/svr/MysqL/scripts/MysqL_install_db --user=MysqL --basedir=/apps/svr/MysqL/ --datadir=/apps/MysqLdb/data/

查看初始化数据文件:ls /apps/MysqLdb/data 文件列表如下

auto.cnf ib_logfile0 localhost.uplook.com.err MysqL test
ibdata1 ib_logfile1 localhost.uplook.com.pid performance_schema

原文(有问题):/apps/svr/MysqL/bin/MysqLd --initialize --user=MysqL --basedir=/apps/svr/MysqL/ --datadir=/apps/MysqLdb/data/初始化密码#root@localhost: Ml-&jsWy(7j)配置MysqL自动启动cp /apps/svr/MysqL/usr/lib/systemd/system/MysqLd.service /usr/lib/systemd/systemsystemctl enable MysqLd.service或者cp /apps/svr/MysqL/support-files/MysqL.server /etc/init.d/MysqLdchmod +x /etc/init.d/MysqLdchkconfig --add MysqLdchkconfig MysqLd on* MysqLd.pid文件MysqL用户有权限访问。Vi /usr/lib/systemd/system/MysqLd.service改:PIDFile=/apps/svr/MysqL/MysqLd.pid# Start main serviceExecStart=/apps/svr/MysqL/bin/MysqLd--daemonize--pid-file=/apps/conf/MysqL5.7/MysqLd.pid $MysqLD_OPTSdbrootpwd=oneinstack #数据库root密码/usr/local/MysqL/bin/MysqL -e "grant all privileges on *.* to root@'127.0.0.1' identified by \"$dbrootpwd\" with grant option;"/usr/local/MysqL/bin/MysqL -e "grant all privileges on *.* to root@'localhost' identified by \"$dbrootpwd\" with grant option;"更改MysqL登录root用户密码MysqLadmin -u root -p'Ml-&jsWy(7j)' password '2Zs63oQbPxpKYFjn6tyj'创建用户允许143远程(允许PHP链接)grant all on *.* to root@192.168.57.143 identified by '123456';flush privileges;show grants for root@192.168.57.143;select user,host from MysqL.user;安装数据加密等扩展工具(如libmcrypt、mhash、mcrypt) 注意:这三个包mcrypt要最后安装yum install libxml2 libxml2-devel bzip2-devel libcurl-devel -yyum install PHP-mcrypt libmcrypt libmcrypt-devel mhash mhash-devel libevent libevent-devel./configure --prefix=/apps/svr/PHP/ \--with-openssl \--enable-mbstring \--with-freetype-dir \--with-jpeg-dir \--with-png-dir \--with-MysqL \--with-zlib \--enable-xml \--enable-sockets \--with-apxs2=/apps/svr/httpd/bin/apxs \--with-config-file-path=/apps/conf \--with-bz2 \--enable-maintainer-ztsmakemake install#--with-config-file-scan-dir=/apps/conf \#--with-libxml-dir=/usr \#--with-MysqLi=/usr/local/MysqL/bin/MysqL_config \#--with-MysqL添加MysqL模块# --with-apxs2=/usr/local/apache24/bin/apxs 表示编译成模块#--enable-fpm 编译成fastCGI# --enable-maintainer-zts 编译fastCGI不需要选项配置PHP.ini文件:解压的安装包下cp PHP.ini-development /apps/conf/PHP.ini 设置配置文件路径 --with-config-file-path=/apps/conf \short_open_tag = Onasp_tags = On*解析short_open_tag决定是否允许使用 PHP 代码开始标志的缩写形式(<? ?> )。如果要和 XML 结合使用 PHP,可以禁用此选项以便于嵌入使用 <?xml ?> 。否则还可以通过 PHP输出,例如:<?PHP echo '<?xml version="1.0"'; ?> 。如果禁用了,必须使用 PHP 代码开始标志的完整形式(<?PHP ?> )。注意: 本指令也会影响到缩写形式 <?= ,它和 <? echo 等价。使用此缩写需要 short_open_tag 的值为 On。asp_tags除了通常的 <?PHP ?> 标志之外还允许使用 ASP 风格的标志 <% %>。这也包括输出变量值的缩写 <%= $value %>。注意: ASP 风格标志的支持是 3.0.4 版新加的整合apache和PHP编译Apache配置文件httpd.conf,以Apache支持PHP。以及访问的主页面index.PHPvim /apps/conf/httpd.conf添加支持PHP的主页<IfModule dir_module> DirectoryIndex index.PHP index.html</IfModule>加载PHP程序模块文件LoadModule PHP5_module modules/libPHP5.so添加如下二行apache能识别PHP格式页面 AddType application/x-httpd-PHP .PHP AddType application/x-httpd-PHP-source .PHPs查看配置文件是否有语法错误httpd -tSyntax OK重启服务service httpd restart测试PHP与Apache是否正常连接cd /apps/svr/httpd/htdocs/vim index.PHP<?PHPPHPinfo();?>整合PHPMysqL由于MysqLPHP不在同一台服务器,所以添加PHP的扩展模块1、在Apache+PHP服务器上安装MysqL-develyum install MysqL-devel -y2、进入PHP解压包生成配置文件cd /root/PHP-5.6.30/ext/MysqL执行PHPize脚本生成configure文件[root@client MysqL]# pwd/root/PHP-5.6.30/ext/MysqL[root@client MysqL]# /apps/svr/PHP/bin/PHPizeConfiguring for:PHP Api Version: 20131106Zend Module Api No: 20131226Zend Extension Api No: 220131226Cannot find autoconf. Please check your autoconf installation and the$PHP_AUTOCONF environment variable. Then,rerun this script.无法找到autoconf。请检查您的autoconf安装和$PHP_AUTOCONF环境变量。然后,重新运行这个脚本。(*错误缺少 m4 autoconf包* )yum install m4yum install autoconf3、配置 编译安装(安装完成之后再扩展块路径下生成一个MysqL.so模块文件)./configure --with-MysqL --with-PHP-config=/apps/svr/PHP/bin/PHP-config--with-MysqL添加MysqL模块--with-PHP-config=/apps/svr/PHP/bin/PHP-config添加模块所需要的脚本位置makemake installspacer.gif4、添加MysqL.so模块到PHP.ini配置文件(/apps/conf/PHP.ini)[root@client htdocs]# cat /apps/conf/PHP.ini |grep MysqL.soextension=/apps/svr/PHP/lib/PHP/extensions/no-debug-zts-20131226/MysqL.so wKiom1kejiDi0kTlAAAzoQvJWYU480.png测试PHPMysqL(默认root用户登录不需要密码)是否正常连接vim index.PHP<?PHP$conn=MysqL_connect('localhost','root','');if ($conn)echo "Success...";elseecho "Failure!!!";?>下面关于LAMP相关的内容你可能也喜欢:LAMP平台安装Xcache和Memcached加速网站运行 http://www.linuxidc.com/Linux/2015-06/118835.htmCentOS 7下搭建LAMP平台环境 http://www.linuxidc.com/Linux/2015-06/118818.htmCentOS 6.5系统安装配置LAMP(Apache+PHP5+MysqL)服务器环境 http://www.linuxidc.com/Linux/2014-12/111030.htmCentOS 7.2 yum安装LAMP环境 http://www.linuxidc.com/Linux/2016-11/136766.htmUbuntu 14.04 配置 LAMP+PHPMyAdmin PHP(5.5.9)开发环境 http://www.linuxidc.com/Linux/2014-10/107924.htmLAMP结合NFS构建小型博客站点 http://www.linuxidc.com/Linux/2015-08/121029.htmCentOS7下安装部署LAMP环境 http://www.linuxidc.com/Linux/2016-04/130653.htmCentOS 7 上安装(LAMP)服务 Linux,Apache,MysqLPHP http://www.linuxidc.com/Linux/2017-05/143868.htmUbuntu Server 14.04 LTS下搭建LAMP环境图文详解 http://www.linuxidc.com/Linux/2016-12/138758.htmUbuntu Server 16.04下配置LAMP环境 http://www.linuxidc.com/Linux/2016-12/138757.htmCentOS 6.7编译安装LAMP 详解 http://www.linuxidc.com/Linux/2017-03/141244.htmUbuntu 16.04搭建LAMP开发环境 http://www.linuxidc.com/Linux/2016-10/136327.htm本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-05/144037.htm

猜你在找的CentOS相关文章