需求:
CentOS 7 lamp(php-fpm)
(1)三者分离于三台主机
(2)一个虚拟主机用于提供phpMyAdmin;另一个虚拟主机用于提供wordpress;
(3)xcache
实验准备:
# setenforce 0 # systemctl stop iptables # systemctl stop firwalld 修改文件: Linux: /etc/hosts windows:\Windows\System32\drivers\etc\hosts 添加内容: 10.0.0.61 www.phpadmin.com 10.0.0.61 www.wordpress.com
实验环境
三者分离于三台主机
host1: 10.0.0.61 httpd host2: 10.0.0.62 php-fpm host3: 10.0.0.63 mariadb
Host1
# yum install httpd -y
Host2
# yum install php-fpm php-mysql php-mbstring -y
编辑配置文件:
# vim /etc/php-fpm.d/www.conf listen = 127.0.0.1:9000 listen.allowed_clients = 127.0.0.1 修改为 listen = 10.0.0.62:9000 //本地的ip地址,监听在哪个端口 listen.allowed_clients = 10.0.0.61 //允许哪个地址的访问
systemctl start php-fpm
Host3
# yum install mariadb-server -y # systemctl start mariadb mysql> create user root@'10.0.0.%'; mysql> grant all on *.* to root@'10.0.0.%' identified by '123456' mysql> create user 'wordpress'@'10.0.0.62'; mysql> create database wordpress; mysql> grant all on wordpress.* to 'wordpress'@'10.0.0.62' identified by 'wordpress'
web服务器配置和测试
确保httpd服务中已经装载fcgi模块
# httpd -M | grep fcgi
确保httpd配置文件加载fcgi模块选项
其中有LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so则配置可以加载模块
# cat /etc/httpd/conf.modules.d/00-proxy.conf
创建虚拟主机
(1)删除测试页面:
# mv /etc/httpd/conf,d/welcome.conf /opt/
(2)注释主配置文件中心主机段:
# Document "/var/www/html"
(3)创建站点根目录位置:
# mkdir -pv /www/host1/
(4)创建虚拟主机位置:
# vim /etc/httpd/conf.d/vhosts.conf [object Object]
(5)检测httpd配置文件语法
# httpd -t
编辑转发配置文件:
# vim /etc/httpd/conf.d/fcgi.conf [object Object]
# systemctl start httpd
获取源码
phpadmin
# cd /www/host1/phpadmin # wget https://files.phpmyadmin.net/phpMyAdmin/4.6.0/phpMyAdmin-4.6.0-all-languages.zip # unzip phpMyAdmin-4.6.0-all-languages.zip # mv phpMyAdmin-4.6.0-all-languages phpmyadmin # cd phpmyadmin # cp config.sample.inc.php config.inc.php 生成随机数 # openssl rand -base64 20 6rR4Nxjl7YEdSBXNQlxIMZ8TeVw 将生成的随机数添加到config.inc.php: $cfg['blowfish_secret'] = 'Js/yatgOt2UBJMkKqkeJfFX9RKA'; 指定数据库的IP地址 $cfg['Servers'][$i]['host'] = '10.0.0.62';
wordpress
官网:https://cn.wordpress.org
# cd /www/host1/wordpress # wget https://cn.wordpress.org/wordpress-4.5-zh_CN.tar.gz # unzip wordpress-4.5-zh_CN.tar.gz
压力测试
ab
-n:总请求数
-c:模拟并行数
# ab -n 100 -c 100 http://www.phpadmin.com/index.php Requests per second: 6664.53 [#/sec] (mean) // 每秒处理请求数 6664
编译安装xcache
官网:http://xcache.lighttpd.net/
# yum install php-devel -y //xcache依赖php-devel # wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.bz2 # tar xf xcache-3.2.0.tar.bz2 # cd xcache-3.2.0 # phpize # ./configure --enable-xcache --with-php-config=`which php-config` # make && make install # cp xcache.ini /etc/php.d # systemctl reload httpd Requests per second: 7642.92 [#/sec] (mean) // 性能提升1000
注意epel源中xcache的rpm包可能有问题,性能不升反降