Centos 7&6分布式lamp平台
- Centos 7&6分布式lamp平台
- 一、环境介绍
- lamp的实现方式
- 本文安装方式
- 二、Centos 7 分布式lamp平台,module方式
- 安装httpd和php
- xcache
- phpMyAdmin
- wordpress
- https的phpMyAdmin
- 环境规划
- 主机2配置mariadb
- 主机1配置httpd&php
- 三、Centos 7 分布式lamp平台,php-fpm(rpm包)方式
- 安装和配置httpd
- xcache
- phpMyAdmin
- wordpress
- 注意事项
- 环境规划
- 主机3配置mariadb
- 主机2配置php-fpm
- 主机1配置httpd
- 四、Centos 7 分布式lamp平台,编译安装方式
- phpMyAdmin
- 环境规划
- 主机1配置httpd
- 主机2配置php-fpm
- 主机3配置mariadb
- 配置应用
一、环境介绍
lamp的实现方式
- module方式 :将php编译成为httpd的模块来使用
- php-fpm方式:将php安装成为一个可以监听在一个端口的服务,即php-fpm方式
- 编译安装:以上两种介绍的都为rpm包方式安装,此处可以编译安装,编译安装时可以选择不同MPM,默认为prfork
本文安装方式
方式 | 主机 | 测试环境 |
---|---|---|
module | 2 | 提供两个虚拟主机,分别提供phpMyAdmin和wordpres进行测试,且phpMyAdmin为https方式 |
php-fpm(rpm包) | 3 | 提供两个虚拟主机,分别提供phpMyAdmin和wordpres进行测试 |
编译安装(php-fpm) | 3 | 提供两个虚拟主机,分别提供phpMyAdmin和wordpres进行测试,并且mpm为非prefork机制(此处测试event模型) |
二、Centos 7 分布式lamp平台,module方式
环境规划
IP | software | 平台 |
---|---|---|
172.18.4.70 | httpd+php | CentOS 7 |
172.18.4.71 | mariadb | CentOS 7 |
主机2配置mariadb
安装# yum install mariadb-server mariadb -y
授权wordpress
MariaDB [(none)]> CREATE DATABASE wpdb;Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON wpdb.* to [email protected]‘172.18.%.%‘ IDENTIFIED BY ‘wpuser‘;Query OK, 0 rows affected (0.12 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.05 sec)
MariaDB [(none)]> SHOW DATABASES;+--------------------+| Database |+--------------------+| information_schema || mysql || performance_schema || wpdb |+--------------------+4 rows in set (0.00 sec)
MariaDB [(none)]> SELECT user,host,password FROM mysql.user WHERE user=‘wpuser‘;+--------+------------+-------------------------------------------+| user | host | password |+--------+------------+-------------------------------------------+| wpuser | 172.18.%.% | *85709C35E2A466A9716D0135ABA9A700002C2DE9 |+--------+------------+-------------------------------------------+1 row in set (0.02 sec)
授权phpMyAdmin可访问的数据库用户
MariaDB [(none)]> CREATE USER [email protected]‘172.18.%.%‘ IDENTIFIED BY ‘pmapasswd‘;Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> GRANT ALL ON *.* TO [email protected]‘172.18.%.%‘ IDENTIFIED BY ‘pmapasswd‘;Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> SHOW GRANTS FOR [email protected]‘172.18.%.%‘;+----------------------------------------------------------------------------------------------------------------------+| Grants for [email protected]%.% |+----------------------------------------------------------------------------------------------------------------------+| GRANT ALL PRIVILEGES ON *.* TO ‘pma‘@‘172.18.%.%‘ IDENTIFIED BY PASSWORD ‘*7E19D0AC9C8C65817A71AC0D9D625CBBB3F3FD9D‘ |+----------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)
主机1配置httpd&php
安装httpd和php
安装httpd和php:此处把php当做httpd的模块
# yum install httpd php php-mysql -y
启动httpd并测试php与mysql
# systemctl start httpd# ss -tnl|grep 80LISTEN 0 128 :::80 :::*
添加mariadb测试用户
MariaDB [(none)]> GRANT ALL ON *.* TO [email protected]‘172.18.%.%‘ IDENTIFIED BY ‘123456‘;Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.01 sec)
添加测试页面# vim /var/www/html/index.phpmysql:<?php $conn = mysql_connect(‘172.18.4.71‘,‘testuser‘,‘123456‘); if ($conn) echo "OK"; else echo "Failure";?><?php phpinfo();?>
通过浏览器访问测试
xcache
xcache可以选择编译安装,但epel源中也有提供,本地使用编译安装,在下面会使用yum安装
1、yum安装的lamp平台且php作为模块时的安装方式
# yum install php-devel -y # tar xf xcache-3.0.3.tar.gz # cd xcache-3.0.3 # phpize # ./configure --enable-xcache # make && make install
安装结束时,会出现类似如下行: Installing shared extensions: /usr/lib64/php/modules/
2、编辑php.ini,整合php和xcache:
首先将xcache提供的样例配置导入php.ini # mkdir /etc/php.d # cp xcache-3.2.0/xcache.ini /etc/php.d
说明:xcache.ini文件在xcache的源码目录中。
接下来编辑/etc/php.d/php.ini [xcache] zend_extension = /usr/lib64/php/modules/xcache.so
3、查看浏览器并测试
phpMyAdmin
1、安装配置phpMyAdmin
下载方式:https://www.phpmyadmin.net/downloads/
安装mbstring支持中文# yum install php-mbstring -y# 解压程序包,创建软连接(此处也可以直接移动改名)# lltotal 9836-rw-r--r-- 1 root root 148 Apr 19 19:56 index.phpdrwxr-xr-x 10 root root 4096 Sep 8 2015 phpMyAdmin-4.4.14.1-all-languages-rw-r--r-- 1 root root 10057503 Sep 18 2015 phpMyAdmin-4.4.14.1-all-languages.zip# unzip phpMyAdmin-4.4.14.1-all-languages.zip# ln -sv phpMyAdmin-4.4.14.1-all-languages pma‘pma’ -> ‘phpMyAdmin-4.4.14.1-all-languages’# lltotal 9836-rw-r--r-- 1 root root 148 Apr 19 19:56 index.phpdrwxr-xr-x 10 root root 4096 Sep 8 2015 phpMyAdmin-4.4.14.1-all-languages-rw-r--r-- 1 root root 10057503 Sep 18 2015 phpMyAdmin-4.4.14.1-all-languages.ziplrwxrwxrwx 1 root root 33 Apr 19 21:28 pma -> phpMyAdmin-4.4.14.1-all-languages
生成配置文件,修改配置文件
# cd /var/www/html/pma/# cp config.sample.inc.php config.inc.php# vim config.inc.php # openssl rand -base64 20 #通过openssl生成一串随机数PRme5hzVVWLMcmr3U2mPtklqcUU= # vim config.inc.php $cfg[‘blowfish_secret‘] = ‘PRme5hzVVWLMcmr3U2mPtklqcUU‘;$cfg[‘Servers‘][$i][‘host‘] = ‘172.18.4.71‘;# 注意:此处的host是mariadb服务器地址
2、配置虚拟主机
# vim /etc/httpd/conf.d/phpmyadmin.conf<VirtualHost 172.18.4.70:80> DocumentRoot "/var/www/html/pma/" ServerName www.magedu.com <Directory "/var/www/html/pma"> Options FollowSymLinks AllowOverride None Require all granted </Directory></VirtualHost>重启httpd服务# systemctl restart httpd.service
3、访问测试是否可以连接数据库
在第一台mariadb主机上已经创建,并且授权
测试用户:pma
测试密码:pmapasswd
wordpress
1、安装配置wordpress
下载地址:https://wordpress.org/download/
安装程序:
cd /var/www/html# unzip wordpress-4.3.1-zh_CN.zip# cd wordpress/# cp wp-config-sample.php wp-config.php # vim wp-config.php
修改配置:
2、添加虚拟主机
# vim /etc/httpd/conf.d/wordpress.conf<VirtualHost 172.18.4.70:8080> DocumentRoot "/var/www/html/wordpress/" ServerName www.zhaoxin.com <Directory "/var/www/html/wordpress"> Options FollowSymLinks AllowOverride None Require all granted </Directory></VirtualHost>重启httpd服务# systemctl restart httpd.service
3、测试
https的phpMyAdmin
A、构建私有CA服务器
- 生成私钥:
# (umask 077; openssl genrsa -out /etc/pki/CA/private/cakey.pem 4096)Generating RSA private key, 4096 bit long modulus...........................................................................++.....................................................................................................................................................................................++e is 65537 (0x10001)
- 生成自签证书:
# openssl req -new -x509 -key /etc/pki/CA/private/cakey.pem -out /etc/pki/CA/cacert.pem -days 3655
具体方式如下图:
- 提供所需目录及文件
# mkdir -pv /etc/pki/CA/{certs,crl,newcerts}# touch /etc/pki/CA/{serial,index.txt}# echo 01 > /etc/pki/CA/serial
2、httpd服务器申请证书
- 生成私钥
#mkdir /etc/httpd/ssl# cd /etc/httpd/ssl# (umask 077; openssl genrsa -out /etc/httpd/ssl/httpd.key 2048)Generating RSA private key, 2048 bit long modulus................................+++.............+++e is 65537 (0x10001)
- 生成证书签署请求
# openssl req -new -key /etc/httpd/ssl/httpd.key -out /etc/httpd/ssl/httpd.csr -days 365
具体方式如下图:
- 将证书复制到CA服务器
注意:本文用scp命令复制,在生产环境中不应在网络中传输。建议使用U盘传输。
# scp /etc/httpd/ssl/httpd.csr 172.18.4.71:/opt/ssl/[email protected]172.18.4.71‘s password: httpd.csr 100% 1090 1.1KB/s 00:00
3、CA服务器签署请求
- 签署请求
# openssl ca -in /opt/ssl/httpd.csr -out /etc/pki/CA/certs/httpd.crt -days 365
- 复制证书到httpd服务器
# scp /etc/pki/CA/certs/httpd.crt 172.18.4.70:/etc/httpd/ssl/[email protected]172.18.4.70‘s password: httpd.crt 100% 5852 5.7KB/s 00:00
B、配置httpd服务器
1、安装mod_ssl以支持https
# yum install mod_ssl -y
2、修改虚拟主机,支持ssl
配置文件:/etc/httpd/conf.d/phpmyadmin.conf
DirectoryIndex index.php<VirtualHost 172.18.4.70:443> DocumentRoot "/var/www/html/pma/" ServerName www.zhaoxin.com SSLEngine on SSLCertificateFile /etc/httpd/ssl/httpd.crt SSLCertificateKeyFile /etc/httpd/ssl/httpd.key <Directory "/var/www/html/pma"> Options FollowSymLinks AllowOverride None Require all granted </Directory></VirtualHost># 重启服务,并查看443端口# systemctl reload httpd# netstat -tnlp|grep httpdtcp6 0 0 :::80 :::* LISTEN 3362/httpd tcp6 0 0 :::443 :::* LISTEN 3362/httpd
3、客户端浏览器导入证书
注意:证书为CA服务器的自签证书
4、测试https访问
注意:因为证书颁发时写的是域名,所以访问时必须是域名。
三、Centos 7 分布式lamp平台,php-fpm(rpm包)方式
注意事项
将php作为一台独立主机时,需要注意以下几点:
- 应用程序安装:应用程序必须在web所在的服务器和php所在的服务器同时存在,且所处的路径必须完全相同。
- php-fpm pool的配置:
- listen = 172.18.4.72:9000
表示监听地址,应为本机ip中可以与web服务器和mariadb通信其中的一个 - listen.allowed_clients = 172.18.4.70,172.18.4.71
设置允许连接到 FastCGI 的服务器 IPV4 地址。等同于 PHP FastCGI (5.2.2+) 中的 FCGI_WEB_SERVER_ADDRS 环境变量。仅对 TCP 监听起作用。每个地址是用逗号分隔,如果没有设置或者为空,则允许任何服务器请求连接。默认值:any。
- listen = 172.18.4.72:9000
- web服务器配置:
- 主配置文件:/etc/httpd/conf/httpd.conf
AddType application/x-httpd-php .php - 虚拟主机及其他配置文件
- 主配置文件:/etc/httpd/conf/httpd.conf
ProxyRequests OffProxyPassMatch ^/(.*\.php)$ fcgi://172.18.4.72:9000/var/www/html/wordpress/$1
环境规划
IP | software | 平台 |
---|---|---|
172.18.4.70 | httpd | CentOS 7 |
172.18.4.71 | mariadb | CentOS 7 |
172.18.4.72 | php-fpm | CentOS 7 |
主机3配置mariadb
# 安装mariadb# yum install mariadb-server mariadb -y
# 创建wordpress数据库,及授权用户MariaDB [(none)]> CREATE DATABASE wpdb2;Query OK, 1 row affected (0.07 sec)
MariaDB [(none)]> GRANT ALL ON wpdb2.* TO wpuser2@‘172.18.%.%‘ IDENTIFIED BY ‘wpuser2‘;Query OK, 0 rows affected (0.10 sec)
MariaDB [(none)]> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.09 sec)
#创建phpmyadmin测试用户
MariaDB [(none)]> GRANT ALL ON *.* TO pmatest@‘172.18.%.%‘ IDENTIFIED BY ‘pmatest‘;Query OK, 0 rows affected (0.00 sec)
#创建测试用户,用于测试php是否能连接mariadb
MariaDB [(none)]> GRANT SELECT ON *.* TO testphpuser@‘172.18.%.%‘ IDENTIFIED BY ‘testphpuser‘;Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> SELECT user,host,password FROM mysql.user;+-------------+-----------------------+-------------------------------------------+| user | host | password |+-------------+-----------------------+-------------------------------------------+| wpuser2 | 172.18.%.% | *3537DDA14FC1BECB01AE33B985D168A8FF03EAD5 || pmatest | 172.18.%.% | *A94DDD6EAFEF229762011FBE87CB765C6BF3A28F || testphpuser | 172.18.%.% | *BF4562DD1A67EE803547146247D8BDD0C1D0933F |+-------------+-----------------------+-------------------------------------------+
主机2配置php-fpm
安装配置php-fpm
# yum install php-fpm php-mysql -y
修改pool配置文件:/etc/php-fpm.d/www.conf
重新载入php-fpm服务
# systemctl reload php-fpm# ss -tnlState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 172.18.4.72:9000 *:* LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6010 *:* LISTEN 0 128 127.0.0.1:6011 *:* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 ::1:6010 :::* LISTEN 0 128 ::1:6011 :::*
主机1配置httpd
安装和配置httpd
# yum install httpd -y
修改主配置文件,添加一行
vim /etc/httpd/conf/httpd.conf AddType application/x-httpd-php .php
配置转发动态页面到php-fpm服务器
# vim /etc/httpd/conf.d/vhosts.confProxyRequests OffProxyPassMatch ^/(.*\.php)$ fcgi://172.18.4.72:9000/var/www/html/$1# systemctl start httpd
在php-fpm的主机上创建与web主机相同的DocumentRoot及添加测试页面。
# mkdir -pv /var/www/html# vim /var/www/html/index.phpmysql:<?php $conn = mysql_connect(‘172.18.4.71‘,‘testphpuser‘,‘testphpuser‘); if ($conn) echo "OK"; else echo "Failure";?><?php phpinfo();?>
注意:上面的index.php需要放在php-fpm所在的主机上面
测试
xcache
在php-fpm的服务器上:
# yum install php-xcache -y# systemctl reload php-fpm
重新访问php测试页面
phpMyAdmin
下载方式:https://www.phpmyadmin.net/downloads/
安装mbstring支持中文# yum install php-mbstring -y# 解压程序包,创建软连接(此处也可以直接移动改名)# cd /var/www/html# lltotal 9836-rw-r--r-- 1 root root 148 Apr 19 19:56 index.phpdrwxr-xr-x 10 root root 4096 Sep 8 2015 phpMyAdmin-4.4.14.1-all-languages-rw-r--r-- 1 root root 10057503 Sep 18 2015 phpMyAdmin-4.4.14.1-all-languages.zip# unzip phpMyAdmin-4.4.14.1-all-languages.zip# ln -sv phpMyAdmin-4.4.14.1-all-languages pma‘pma’ -> ‘phpMyAdmin-4.4.14.1-all-languages’# lltotal 9836-rw-r--r-- 1 root root 148 Apr 19 19:56 index.phpdrwxr-xr-x 10 root root 4096 Sep 8 2015 phpMyAdmin-4.4.14.1-all-languages-rw-r--r-- 1 root root 10057503 Sep 18 2015 phpMyAdmin-4.4.14.1-all-languages.ziplrwxrwxrwx 1 root root 33 Apr 19 21:28 pma -> phpMyAdmin-4.4.14.1-all-languages
生成配置文件,修改配置文件
# cd /var/www/html/pma/# cp config.sample.inc.php config.inc.php# vim config.inc.php # openssl rand -base64 20 #通过openssl生成一串随机数cYYZhYcj3eGTnyP8F+9kcJBEUO4= # vim config.inc.php $cfg[‘blowfish_secret‘] = ‘cYYZhYcj3eGTnyP8F+9kcJBEUO4‘;$cfg[‘Servers‘][$i][‘host‘] = ‘172.18.4.71‘;# 注意:此处的host是mariadb服务器地址
注意:以上操作需要在php-fpm服务中同样操作
此处我用scp命令拷贝:
# scp -r phpMyAdmin-4.4.14.1-all-languages 172.18.4.72:/var/www/html/pma# ifconfig |grep -e ‘inet[[:space:]].*255$‘ inet 172.18.4.72 netmask 255.255.0.0 broadcast 172.18.255.255 # ll /var/www/html/total 12-rw-r--r-- 1 root root 156 Apr 20 09:41 index.phpdrwxr-xr-x 10 root root 4096 Apr 20 10:54 pma
配置虚拟主机:
/etc/httpd/conf.d/pma.conf 配置文件路径
DirectoryIndex index.php<VirtualHost *:80> ServerName www.pma.com DocumentRoot /var/www/html ProxyRequests Off ProxyPassMath ^/(.*\.php)$ fcgi://172.18.4.72:9000/var/www/html/$1 <Directory "/var/www/html"> Options FollowSymLinks AllowOverride None Require all granted </Directory></VirtualHost>
创建session目录:
- 注意:此处如果不创建可能会报错。
# mkdir /var/lib/php/session# chown apache.apache /var/lib/php/session
测试:
wordpress
下载地址:https://wordpress.org/download/
解压程序包:
# cd /var/www/html/# unzip wordpress-4.3.1-zh_CN.zip# cd wordpress# cp wp-config-sample.php wp-config.php# vim wp-config-sample
拷贝文件到php服务器:
# scp -r wordpress 172.18.4.72:/var/www/html/wordpress
添加虚拟主机:
配置文件:/etc/httpd/conf.d/wordpress.conf
DirectoryIndex index.phpListen 8080<VirtualHost 172.18.4.70:8080> ServerName www.wordpress.com DocumentRoot /var/www/html/wordpress <Directory "/var/www/html/wordpress"> Options None AllowOverride None Require all granted </Directory> ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://172.18.4.72:9000/var/www/html/wordpress/$1</VirtualHost>重启httpd服务# systemctl reload httpd# ss -tnlState Recv-Q Send-Q Local Address:Port Peer Address:Port LISTEN 0 128 *:22 *:* LISTEN 0 100 127.0.0.1:25 *:* LISTEN 0 128 127.0.0.1:6011 *:* LISTEN 0 128 :::8080 :::* LISTEN 0 128 :::80 :::* LISTEN 0 128 :::22 :::* LISTEN 0 100 ::1:25 :::* LISTEN 0 128 ::1:6011 :::*
测试:
四、Centos 7 分布式lamp平台,编译安装方式
环境规划
IP | software | 平台 |
---|---|---|
172.18.4.60 | httpd-event | CentOS 6 |
172.18.4.61 | php-fpm | CentOS 6 |
172.18.4.62 | mariadb | CentOS 6 |
主机1配置httpd
编译安装httpd:
注意:httpd-2.4需要apr-1.4以上, apr-util-1.4以上版本的支持,而CentOS 6默认为apr-1.3.9,apr-util-1.3.9,所以像在CentOS 6上面使用httpd-2.4需要编译安装apr和apr-util.
- 环境配置:安装开发工具
# yum groupinstall "Server Platform Development" "Development tools" -y# yum install pcre-devel openssl-devel -y
apr和apr-util的所有版本都可以在这里下载:https://archive.apache.org/dist/apr/
httpd所有版本:https://archive.apache.org/dist/httpd/
- 编译安装apr
# wget http://pkgs.fedoraproject.org/repo/pkgs/apr/apr-1.5.0.tar.bz2/md5/cc93bd2c12d0d037f68e21cc6385dc31/apr-1.5.0.tar.bz2# tar xf apr-1.5.0.tar.bz2 # cd apr-1.5.0apr-1.5.0]# ./configure --prefix=/usr/local/aprapr-1.5.0]# make && make install
- 编译安装apr-util
# wget https://archive.apache.org/dist/apr/apr-util-1.5.2.tar.bz2# tar xf apr-util-1.5.2.tar.bz2# cd apr-util-1.5.2apr-util-1.5.2]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprapr-util-1.5.2]# make&&make install
- 编译安装httpd
# wget https://archive.apache.org/dist/httpd/httpd-2.4.10.tar.bz2# tar xf httpd-2.4.10.tar.bz2 # cd httpd-2.4.10httpd-2.4.10]# ./configure --prefix=/usr/local/apache24 --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-modules=most --enable-mpms-shared=all --with-mpm=eventhttpd-2.4.10]# make -j 4 && make install
# vim /etc/profile.d/httpdexport PATH=/usr/local/apache24/bin:$PATH# source /etc/profile.d/httpd# cp apachectl /etc/init.d/httpd# vim /etc/init.d/httpd 添加 # chkconfig: 35 66 99 # description: APACHE24加入系统服务:# chkconfig --add httpd# chkconfig httpd on# service httpd start# ss -tnl|grep 80LISTEN 0 128 :::80 :::*
- 查看验证是否为event模型
# httpd -M|grep mpmmpm_event_module (shared)
- 切换MPM模型
- 测试httpd服务
# service httpd restart# httpd -M|grep mpm mpm_prefork_module (shared)
主机2配置php-fpm
php源码包下载地址:http://mirrors.sohu.com/php/
- 环境配置:安装开发工具
# yum groupinstall "Server Platform Development" "Development tools" -y# yum install bzip2-devel libmcrypt-devel libxml2-devel mhash mhash-devel libmcrypt-devel libmcrypt -y-y
- 1、编译php
# tar xf php-5.4.40.tar.bz2
php-5.4.40]# ./configure --prefix=/usr/local/php5 --with-openssl --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-ztsphp-5.4.40]# make && make install
- 2、配置php
为php提供配置文件:
# cp php.ini-production /etc/php.ini
- 3、配置php-fpm
为php-fpm提供SysV init脚本,并将其添加至服务列表:
# cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm# chmod +x /etc/rc.d/init.d/php-fpm# chkconfig --add php-fpm# chkconfig php-fpm on
为php-fpm提供配置文件:
# cp /usr/local/php5/etc/php-fpm.conf.default /usr/local/php5/etc/php-fpm.conf
编辑php-fpm的配置文件:
# vim /usr/local/php5/etc/php-fpm.conf配置fpm的相关选项为你所需要的值,并启用pid文件(如下最后一行):pm.max_children = 50pm.start_servers = 5pm.min_spare_servers = 2pm.max_spare_servers = 8pid = /usr/local/php5/var/run/php-fpm.pid
启动php-fpm
# service php-fpm start
验正
# ss -tnlp|grep 9000LISTEN 0 128 127.0.0.1:9000 *:* users:(("php-fpm",37291,7),("php-fpm",37292,0),("php-fpm",37293,0),("php-fpm",37294,0),("php-fpm",37295,0),("php-fpm",37296,0))
- 4、配置xcache
下载地址:https://xcache.lighttpd.net/pub/Releases/3.2.0/
#tar xf xcache-3.2.0.tar.bz2# cd xcache-3.2.0xcache-3.2.0]# /usr/local/php5/bin/phpize Configuring for:PHP Api Version: 20100412Zend Module Api No: 20100525Zend Extension Api No: 220100525# ./configure --enable-xcache --with-php-config=/usr/local/php/bin/php-config# make && make install
安装后出现类似行:
Installing shared extensions: /usr/local/php5/lib/php/extensions/no-debug-zts-20100525/
- 5、整合php和xcache:
首先将xcache提供的样例配置导入php.ini
# mkdir /etc/php.d# cp xcache-3.2.0/xcache.ini /etc/php.d
编辑php.ini整合php和xcachevim /etc/php.d/xcache.iniextension = /usr/local/php5/lib/php/extensions/no-debug-zts-20100525/xcache.so
说明:xcache.ini文件在xcache的源码目录中。
- 6、测试xcache
A、httpd服务器端配置
开启模块和开启加载虚拟主机配置文件
# vim /etc/httpd24/httpd.confLoadModule proxy_fcgi_module modules/mod_proxy_fcgi.soLoadModule proxy_module modules/mod_proxy.soInclude /etc/httpd24/extra/httpd-vhosts.conf
增加虚拟主机并重载配置
# vim /etc/httpd24/extra/httpd-vhosts.confDirectoryIndex index.php<VirtualHost 172.18.4.60:80> ServerName www.test.com DocumentRoot "/usr/local/apache24/htdocs/" ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://172.18.4.61:9000/var/www/html/$1</VirtualHost>service httpd reload
B、php服务器端配置
修改php-fpm配置文件
修改其监听IP地址为本机,允许访问客户端ip为webservervim /usr/local/php5/etc/php-fpm.conflisten = 172.18.4.61:9000listen.allowed_clients = 172.18.4.60service php-fpm reload
在/var/www/html/下添加测试页面文件
# vim /var/ww/html/index.php<?php phpinfo();?>
C、访问测试
主机3配置mariadb
- 下载mysql通用二进制格式包
下载地址:https://downloads.mariadb.com/archives/mysql-5.6/ - 准备数据存放的文件系统
这里以/mydata/data为数据存放目录 - 创建myql系统用户
# useradd -r mysql# chown -R mysql:mysql /mydata/data
- 安装并初始化数据库
# tar xf mariadb-5.5.46-linux-x86_64.tar.gz -C /usr/local//# cd /usr/local/# ln -sv mariadb-5.5.46-linux-x86_64/ mysqll# cd mysql # chown -R root.mysql ./*# scripts/mysql_install_db --user=mysql --datadir=/mydata/data
- 配置文件及服务脚本
# mkdir /etc/mysql/# cp support-files/my-large.cnf /etc/mysql/my.cnf# cp support-files/mysql.server /etc/init.d/mysqld# chkconfig --add mysqld修改配置文件,在[mysqld]选项下添加# vim /etc/mysql/my.cnf datadir = /mydata/datainnodb_file_per_table = ONskip_name_resolve = ON启动服务service mysqld start
配置应用
phpMyAdmin
- mariadb服务器端配置
授权phpmyadmin可访问用户
mysql> GRANT ALL ON *.* TO [email protected]‘172.18.%.%‘ IDENTIFIED BY ‘pmauser‘;Query OK, 0 rows affected (0.06 sec)
mysql> FLUSH PRIVILEGES;Query OK, 0 rows affected (0.01 sec)
mysql> SELECT user,host,password FROM mysql.user WHERE user=‘pmauser‘;+---------+------------+-------------------------------------------+| user | host | password |+---------+------------+-------------------------------------------+| pmauser | 172.18.%.% | *6EA40CEE11598F7A411447B959594D78211DF9BB |+---------+------------+-------------------------------------------+1 row in set (0.00 sec)
- httpd服务器端配置
下载方式:https://www.phpmyadmin.net/downloads/
安装mbstring支持中文# yum install php-mbstring -y# 解压程序包,创建软连接(此处也可以直接移动改名)# cd /usr/local/apache24/htdocs/# unzip phpMyAdmin-4.4.14.1-all-languages.zip# ln -sv phpMyAdmin-4.4.14.1-all-languages pma‘pma’ -> ‘phpMyAdmin-4.4.14.1-all-languages’# lltotal 12-rw-r--r-- 1 root root 45 Jun 12 2007 index.html-rw-r--r-- 1 root root 21 Apr 21 02:13 index.phpdrwxr-xr-x 10 root root 4096 Sep 8 2015 phpMyAdmin-4.4.14.1-all-languageslrwxrwxrwx 1 root root 34 Apr 21 04:07 pma -> phpMyAdmin-4.4.14.1-all-languages/
生成配置文件,修改配置文件
# cd /usr/local/apache24/htdocs/pma/# cp config.sample.inc.php config.inc.php# vim config.inc.php # openssl rand -base64 20 #通过openssl生成一串随机数c1g/q0xtSyk6FKwlnME1ao4bg54=# vim config.inc.php $cfg[‘blowfish_secret‘] = ‘c1g/q0xtSyk6FKwlnME1ao4bg54‘;$cfg[‘Servers‘][$i][‘host‘] = ‘172.18.4.62‘;# 注意:此处的host是mariadb服务器地址
2、配置虚拟主机
因为本地没有dns服务器,所以做的基于端口的虚拟主机,不过不影响# vim /etc/httpd24/extra/httpd-vhosts.confListen 81<VirtualHost 172.18.4.60:81> ServerName www.pma.com DocumentRoot "/usr/local/apache24/htdocs/pma" ProxyRequests Off ProxyPassMatch ^/(.*\.php)$ fcgi://172.18.4.61:9000/var/www/html/pma/$1</VirtualHost>
重载httpd服务# service httpd reload
- php服务器端配置
注意:此处的内容需与httpd服务器保持一直,其配置方法与httpd服务器方法相同,只是路径不相同。
安装mbstring支持中文
# yum install php-mbstring -y
# 解压程序包,创建软连接(此处也可以直接移动改名)# cd /var/www/html/# unzip phpMyAdmin-4.4.14.1-all-languages.zip# ln -sv phpMyAdmin-4.4.14.1-all-languages pma‘pma’ -> ‘phpMyAdmin-4.4.14.1-all-languages’
生成配置文件,修改配置文件配置文件中的随机数也应与httpd服务器中的随机数相同# cd /var/www/html/pma# cp config.sample.inc.php config.inc.php# vim config.inc.php # openssl rand -base64 20 #通过openssl生成一串随机数c1g/q0xtSyk6FKwlnME1ao4bg54=# vim config.inc.php $cfg[‘blowfish_secret‘] = ‘c1g/q0xtSyk6FKwlnME1ao4bg54‘;$cfg[‘Servers‘][$i][‘host‘] = ‘172.18.4.62‘;# 注意:此处的host是mariadb服务器地址
- 访问测试
在第一台mariadb主机上已经创建,并且授权
测试用户:pmauser
测试密码:pmauser
对于lamp就写到这里了,感觉写的不错可以给点个赞。
Centos 7&6分布式lamp平台