httpd, php, mariadb分离式的部署在三台主机上测试性能
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了httpd, php, mariadb分离式的部署在三台主机上测试性能相关的知识,希望对你有一定的参考价值。
CentOS7, amp + xcache,编译安装,php-fpm;
a) 分别深度:httpd, php, mariadb分别部署在一个单独的主机上,以及都在同一主机;
b) 一个虚拟主机提供phpMyAdmin,另一个虚拟主机提供wordpress;
c) 为phpMyAdmim提供https服务;
对以上所有部署做压力测试,并对比测试结果,写出测试报告;
环境:
此处用三台主机分别分离提供不同服务:
172.16.1.4------->提供httpd服务
172.16.1.3------->提供mariadb-server服务
172.16.1.2------->提供php-fpm php-mysql xcache服务
一、172.16.1.2服务器部署httpd服务:
1、安装httpd服务程序
[[email protected]~]# yum -y install httpd
[[email protected]~]# vim /etc/httpd/conf/httpd.conf
2、建立虚拟主机
3、建立网页及相关路径
[[email protected]~]# mkdir -p /var/www/html/www1
[[email protected]~]# mkdir -p /var/www/html/www2
[[email protected]~]# echo "www1.link.com" > /var/www/html/www1/index.html
[[email protected]~]# echo "www2.link.com" > /var/www/html/www2/index.html
4、启动下服务我们测试下虚拟主机是否正常
[[email protected]~]# curl www1.link.com
www1.link.com
[[email protected]~]# curl www2.link.com
www2.link.com
二、在172.16.1.2服务器上部署安装php-fpm
1、安装php-fpm php-mysql php-mbstring程序
[[email protected]~]# yum -y install php-fpm php-mysql php-mbstring
2、编辑/etc/php-fpm.d/www.conf
[[email protected]~]# vim /etc/php-fpm.d/www.conf
修改以下内容:
listen= 172.16.1.2:9000 #设置php服务器监听地址即监听本地能够与外部通信的地址
listen.allowed_clients= 172.16.1.4 #监听具有httpd服务的IP地址
3、建立以下文件并且启动php-fpm服务,查看下是否已经监听
[[email protected]~]# mkdir /var/lib/php/session
[[email protected]~]# chown apache.apache /var/lib/php/session/
[[email protected]~]# ls -ld /var/lib/php/session/
drwxrwx---.3 apache apache 21 9月 10 20:31 /var/lib/php/session/
[[email protected]~]# systemctl start php-fpm.service
[[email protected]~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 172.16.1.2:9000 *:*
以上已经显示监听在php地址
4、在php服务器上建立与http服务器上网页DocumentRoot路径,并且编写php测试也,看看是否能够与http连接
[[email protected]~]# mkdir -p /var/www/html/www{1,2}
[[email protected]~]# vim /var/www/html/www1/index.php #虚拟主机1的php和httpd连接测试
Thisis ge de vhost1
<?php
phpinfo();
?>
[[email protected]~]# vim /var/www/html/www1/index.php #虚拟主机2的php和httpd连接测试
Thisis ge de vhost2
<?php
phpinfo();
?>
5、加载服务访问站点测试php和httpd连接是否正常
正常连接,所有我的PHP和httpd服务器连接成功。
三、在172.16.1.3服务器上部署mariadb服务
1.安装数据库,开启服务
[[email protected]~]# yum -y install mariadb-server
[[email protected]~]# systemctl start mariadb.service
2、创建数据库和授权等相关操作
MariaDB[(none)]> create database wpsdb; #创建WordPress所用数据库
MariaDB[(none)]> grant all on wpsdb.* TO ‘wpuser‘@‘172.16.%.%‘IDENTIFIED BY‘123456‘; #授权WordPress用户
MariaDB[(none)]> create database pma; #授权phpmyadmin所用数据库
MariaDB[(none)]> grant all on pma.* TO ‘pmauser‘@‘172.16.%.%‘IDENTIFIED BY‘123456‘; #授权phpmyadmin的用户
3、在php服务器上建立php测试页,测试php是否可以正常连接数据
[[email protected]~]# vim /var/www/html/www1/index.php
Thisis ge de vhost1
<?php
$conn = mysql_connect(‘172.16.1.3‘,‘wpuser‘,‘123456‘);
if ($conn)
echo "ok";
else
echo "NO";
phpinfo();
?>
[[email protected]~]# vim /var/www/html/www2/index.php
Thisis ge de vhost2
<?php
$conn =mysql_connect(‘172.16.1.3‘,‘wpuser‘,‘123456‘);
if ($conn)
echo "ok";
else
echo "NO";
phpinfo();
?>
4、测试
显示OK,所以mariadb数据可以同php连接了,而且到现在分离式的LAMP平台就构建完成了!
四、部署下WordPress和phpMyadmin
部署WordPress:
1、将下载好的WordPress压缩包传到php主机上,解压缩,配置连接用户和密码,数据库地址
[[email protected]~]# unzip wordpress-3.9-zh_CN.zip
[[email protected]~]# mv wordpress /var/www/html/www1/
[[email protected]~]# cd /var/www/html/www1/wordpress/
[[email protected]]# mv wp-config-sample.php wp-config.php
[[email protected]]# vim wp-config.php
修改如下:
define(‘DB_NAME‘,‘wpsdb‘);
/**MySQL数据库用户名 */
define(‘DB_USER‘,‘wpuser‘);
/**MySQL数据库密码 */
define(‘DB_PASSWORD‘,‘123456‘);
/**MySQL主机 */
define(‘DB_HOST‘,‘172.16.1.3‘);
2、把WordPress这个目录个传到http服务器主页访问的路径下
[[email protected]]# scp -r wordpress/ [email protected]:/var/www/html/www1/
这里需要根据提示输入“yes”和root密码
部署phpMyadmin:
1、将下载好的phpMyadmin压缩包传到php主机上,解压缩,配置连接用户和密码,数据库地址
[[email protected]~]# tar -zxvf phpMyAdmin-4.0.10.20.tar.gz
[[email protected]~]# mv phpMyAdmin-4.0.10.20 /var/www/html/www2/
[[email protected]]# mv phpMyAdmin-4.0.10.20/ phpmyadmin
2、进入phpmyadmin目录下的libraries目录,编辑这个文件:
[[email protected]]# vim config.default.php
$cfg[‘blowfish_secret‘]= ‘V40VdxxM0rPrx8k2KYE‘; #添加随机字符
$cfg[‘Servers‘][$i][‘host‘]= ‘172.16.1.3‘; #数据库服务器地址
$cfg[‘Servers‘][$i][‘user‘]= ‘pmauser‘;
$cfg[‘Servers‘][$i][‘password‘]= ‘123456‘;
3、将配置好了的phpmyadmin目录传一份给httpd服务器虚拟主机对应的访问路径下
[[email protected]]# scp -r phpmyadmin/ [email protected]:/var/www/html/www2/
测试:
成功!下面进行压力测试:
[[email protected]~]# ab -c 1000 -n 10000 http://www1.link.com/wordpress
Thisis ApacheBench, Version 2.3 <$Revision:1430300 $>
Copyright1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensedto The Apache Software Foundation, http://www.apache.org/
Benchmarkingwp.linuxidc.com (be patient)
Completed1000 requests
Completed2000 requests
Completed3000 requests
Completed4000 requests
Completed5000 requests
Completed6000 requests
Completed7000 requests
Completed8000 requests
Completed9000 requests
Completed10000 requests
Finished10000 requests
ServerSoftware: Apache/2.4.6
ServerHostname: www1.link.com
ServerPort: 80
DocumentPath: /wordpress
DocumentLength: 239 bytes
ConcurrencyLevel: 1000
Timetaken for tests: 3.081 seconds
Completerequests: 10000
Failedrequests: 0
Writeerrors: 0
Non-2xxresponses: 10002
Totaltransferred: 4690938 bytes
HTMLtransferred: 2390478 bytes
Requestsper second: 3245.20 [#/sec] (mean)
Timeper request: 308.147 [ms] (mean)
Timeper request: 0.308 [ms] (mean,across all concurrent requests)
Transferrate: 1486.63 [Kbytes/sec] received
从这段测试可以看出,没用加速比我们之前的测试的都要快!
五、在php服务器172.16.1.2上安装xcache进行缓存加速
1、安装php-xache
[[email protected]~]# yum -y install php-xcache
[[email protected]~]# systemctl restart php-fpm.service
2、编辑配置文件,把缓存大小调大测试效果
[[email protected]~]# vim /etc/php.d/xcache.ini
xcache.size = 300M
3、压力测试:
[[email protected]~]# ab -c 1000 -n 10000 http://www1.link.com/wordpress
Thisis ApacheBench, Version 2.3 <$Revision:1430300 $>
Copyright1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensedto The Apache Software Foundation, http://www.apache.org/
Benchmarkingwp.linuxidc.com (be patient)
Completed1000 requests
Completed2000 requests
Completed3000 requests
Completed4000 requests
Completed5000 requests
Completed6000 requests
Completed7000 requests
Completed8000 requests
Completed9000 requests
Completed10000 requests
Finished10000 requests
ServerSoftware: Apache/2.4.6
ServerHostname: www1.link.com
ServerPort: 80
DocumentPath: /wordpress
DocumentLength: 239 bytes
ConcurrencyLevel: 1000
Timetaken for tests: 3.076 seconds
Completerequests: 10000
Failedrequests: 0
Writeerrors: 0
Non-2xxresponses: 10012
Totaltransferred: 4695628 bytes
HTMLtransferred: 2392868 bytes
Requestsper second: 3250.70 [#/sec] (mean)
Timeper request: 307.626 [ms] (mean)
Timeper request: 0.308 [ms] (mean,across all concurrent requests)
Transferrate: 1490.63 [Kbytes/sec]received
ConnectionTimes (ms)
min mean[+/-sd] median max
Connect: 0 46 208.7 2 3011
Processing: 0 69191.8 31 1575
Waiting: 0 68 191.7 31 1574
Total: 21 115 337.5 34 3040
通过测试对比,可以看到apache请求该页面的吞吐率,发现启用xcache后Requests per second有所提高,所以性能更好!
本文出自 “12657170” 博客,请务必保留此出处http://12667170.blog.51cto.com/12657170/1965820
以上是关于httpd, php, mariadb分离式的部署在三台主机上测试性能的主要内容,如果未能解决你的问题,请参考以下文章