实验目标
本次LAMP搭建在CentOS 7虚拟机上,基于 php-fpm(Fastcgi)实现httpd、php-fpm、mariadb三者分离,并且在LAMP上部署应用,用两个虚拟机一个虚拟主机用于提供phpMyAdmin;另一个虚拟主机用于提供wordpress;且提供 xcache加速。
实验环境部署如下:
httpd | 172.18.12.7 | httpd-2.4.6-40.el7.centos.x86_64 |
php-fpm | 172.18.12.8 | php-fpm-5.4.16-36.el7_1.x86_64 |
mariadb | 172.18.12.9 | mariadb-5.5.44-2.el7.centos.x86_64 |
xcache | 172.18.12.8 | xcache-3.2.0(编译安装) |
一、配置mariadb主机
1.安装mariadb服务
yum install -y mariadb-server
2 禁止mysql反解主机名
# vim /etc/my.cnf [mysqld] skip_name_resolve=on
3.给mysql管理员设置密码
# mysql_secure_installation # systemctl start mariadb.service
4.授权远程主机登陆mysql
# mysql -uroot -h127.0.0.1 -pmageedu > CREATE DATABASE testdb > GRANT ALL ON testdb.* TO test@'172.18.%.%' IDENTIFIED BY 'testpasswd'; > FLUSH PRIVILEGES;
二、配置httpd主机
1.安装httpd服务
# yum install -y httpd
2.注释中心主机
# vim /etc/httpd/conf/httpd.conf #DocumentRoot "/var/www/html"
3.创建虚拟主机的配置文件
配置wordpress应用的配置文件# vim /etc/httpd/conf.d/wordpress.conf
配置phpMyAdmin应用的配置文件# vim /etc/httpd/conf.d/phpadmin.conf
4.创建虚拟机的目录站点文档
# mkdir -pv /web/php
4.1配置phpMyAdmin的配置文件
#cd /web/php
# unzip phpMyAdmin-4.4.14.1-all-languages.zip# mv phpMyAdmin-4.4.14.1-all-languages pma
# cd pma/# cp config.sample.inc.php config.inc.php #openssl rand -base64 20 CvVbs1QfE81B7B7NV9njuNgHSAg# vim config.inc.php $cfg['blowfish_secret'] = 'CvVbs1QfE81B7B7NV9njuNgHSAg'; $cfg['Servers'][$i]['host'] = '172.18.12.9';
#systemctl restart php-fpm#systemctl restart httpd
4.2配置wordpress应用的配置文件
# unzip wordpress-4.3.1-zh_CN.zip
# cd wordpress/# cp wp-config-sample.php wp-config.php# vim wp-config.php
# httpd -t# scp -r /web/php/* root@172.18.12.8:/web/php/ #为了保证php-fpm与httpd目录站点下具有相同的文件# systemctl restart httpd
三、配置php-fpm主机
# yum install php-fpm -y# yum install php-mbstring -y#yum install php-mysql -y# vim /etc/php-fpm.d/www.conf listen = 172.18.12.8:9000 listen.allowed_clients = 172.18.12.7
四、安装xcache用于实现加速
1.压力测试
# ab -n 300 -c 10 http://dy.wordpress/index.php
2.安装xcache
yum groupinstall "Development tools" "Server Platfrom Develpment" yum install php-devel -y phpize ./configure --enable-xcache --with-php-config=/usr/bin/php-config make&&make installcp xcache.ini /etc/php.d/systemctl reload php-fpm
3.再次进行压测
]# ab -n 300 -c 10 http://dy.wordpress/index.php
从图可以看出安装了xcache后性能有着显著提升