LAMP- CentOS 7平台三机FastCGI模型
需求:CentOS 7 lamp(php-fpm)
(1)三者分离于三台主机
(2)一个虚拟主机用于提供phpMyAdmin;另一个虚拟主机用于提供wordpress;
(3)xcache
实验准备:
1
2
3
4
5
6
7
8
9
10
# 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.61www.wordpress.com
实验环境
三者分离于三台主机
1
2
3
host1: 10.0.0.61 httpd
host2: 10.0.0.62 php-fpm
host3: 10.0.0.63 mariadb
Host1
1
# yum install httpd -y
Host2
1
# yum install php-fpm php-mysql php-mbstring -y
编辑配置文件:
1
2
3
4
5
6
# 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//允许哪个地址的访问
1
systemctl start php-fpm
Host3
1
2
3
4
5
6
7
8
# 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模块
1
# httpd -M | grep fcgi
确保httpd配置文件加载fcgi模块选项
其中有LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so则配置可以加载模块
1
# cat /etc/httpd/conf.modules.d/00-proxy.conf
创建虚拟主机
(1)删除测试页面:
1
# mv /etc/httpd/conf,d/welcome.conf /opt/
(2)注释主配置文件中心主机段:
1
# Document "/var/www/html"
(3)创建站点根目录位置:
1
# mkdir -pv /www/host1/
(4)创建虚拟主机位置:
1
2
# vim /etc/httpd/conf.d/vhosts.conf
(5)检测httpd配置文件语法
1
# httpd -t
编辑转发配置文件:
1
2
# vim /etc/httpd/conf.d/fcgi.conf
# systemctl start httpd
获取源码phpadmin官网:http://www.phpmyadmin.net
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# cd /www/host1/phpadmin
# wget https://files.phpmyadmin.net/phpMyAdmin/4.6.0/phpMyAdmin-4.6.0-all-languages.zip
# unzipphpMyAdmin-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
1
2
3
# 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:模拟并行数
1
2
# ab -n 100 -c 100 http://www.phpadmin.com/index.php
Requests per second: 6664.53 [#/sec] (mean) // 每秒处理请求数 6664
编译安装xcache官网:http://xcache.lighttpd.net/
1
2
3
4
5
6
7
8
9
10
11
# 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包可能有问题,性能不升反降
页:
[1]