三台主机分别部署LAMP
要求:httpd, php, mariadb分别部署在一个单独的主机上,一个虚拟主机提供phpMyAdmin,另一个虚拟主机提供wordpress,为phpMyAdmim提供https服务;
一. 分工三台主机
A httpd主机 172.16.35.1
B php-fpm主机 172.16.35.2
C mariadb主机 172.16.35.3
为方便实验在这里关闭防火墙
#iptables-F
#setenforce0
安装所需rpm包:
在A上yum -y install httpd,B主机yum -y install php-fpm, C上yum -y install mariade-server php-mysql
二. httpd主机设置
1.设置vhost1.conf和vhost2.conf
[root@zq~]# vim /etc/httpd/conf.d/vhost1.conf
<VirtualHost172.16.35.1:80>
ServerNamewww1.test.com
DocumentRoot"/data/vhost/www1"
ProxyRequestson
DirectoryIndexindex.php
ProxyPassMatch^/(.*\.php)$ fcgi://172.16.35.2:9000/data/vhost/www1/$1 动态资源代理转发给第2台主机
<Directory"/data/vhost/www1">
OptionsNone
AllowOverrideNone
Requireall granted
</Directory>
</VirtualHost>
[root@zq~]# vim /etc/httpd/conf.d/vhost2.conf
<VirtualHost172.16.35.1:80>
ServerNamewww2.test.com
DocumentRoot"/data/vhost/www2"
ProxyRequestson
DirectoryIndexindex.php
ProxyPassMatch^/(.*\.php)$ fcgi://172.16.35.2:9000/data/vhost/www2/$1 动态资源代理转发给第2台主机
<Directory"/data/vhost/www2">
OptionsNone
AllowOverrideNone
Requireall granted
</Directory>
</VirtualHost>
2.修改配置文件指定NDS以及域名解析
[root@zq~]# vim /etc/resolv.conf
#Generated by NetworkManager
DNS=172.16.35.1
nameserver172.16.0.1
#本地域名解析
[root@zq ~]#vim /etc/hosts
127.0.0.1localhost localhost.localdomain localhost4 localhost4.localdomain4
::1localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.35.1www1.test.com www2.test.com
3.创建静态默认文件:
[root@zq~]# mkdir -p /data/vhost/www{1,2}
[root@zq~]# vim /data/vhost/www1/index.html
<h2>zq1第1台物理机静态数据 172.16.35.1</h2>
[root@zq~]# vim /data/vhost/www2/index.html
<h2>zq2第1台物理机静态数据 172.16.35.1</h2>
4.然后测试本机静态数据是否可以正常访问
================================================================
三.php-fpm主机:
1.修改配置文件
[root@zq~]# vim /etc/php-fpm.d/www.conf
listen = 172.16.35.2:9000监听本机地址端口
listen.allowed_clients= 172.16.35.1 允许A主机连接
2.创建资源映射目录及文件
mkdir -pv/data/vhost/www{1,2}
[root@zq~]# vim /data/vhost/www1/index.php
<h2>第2台物理机a</h2>
<?php
$conn =mysql_connect('172.16.35.3','testuser','testpass');
if($conn)
echo"OK";
else
echo"Failure";
phpinfo();
?>
[root@zq~]# vim /data/vhost/www2/index.php
<h2>第2台物理机b</h2>
<?php
$conn =mysql_connect('172.16.35.3','testuser','testpass');
if($conn)
echo"OK";
else
echo"Failure";
phpinfo();
?>
3.安装加速器php-xcache
yum -yinstall php-xcache
解压wordpress以及php-myadmin分别在www1和www2中
4.修改wordpress的配置文件
[root@zq~]# cd /data/vhost/www1/wordpress/
[root@zq wordpress]# ln -s wp-config-sample.phpwp-config.php
[root@zq wordpress]# vim wp-config.php
// **MySQL 设置 - 具体信息来自您正在使用的主机 ** //
/**WordPress数据库的名称 */
define('DB_NAME','qqdb');
/** MySQL数据库用户名 */
define('DB_USER','qquser');
/** MySQL数据库密码 */
define('DB_PASSWORD',qqpass');
/** MySQL主机 */
define('DB_HOST','172.16.35.3'); 这里的地址是指向第C主机的数据库地址
/** 创建数据表时默认的文字编码 */
define('DB_CHARSET','utf8');
/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE','');
5.修改phpMyAdmin的配置文件
[root@zqt ~]# ln -s /data/vhost/www2/phpMyAdmin-4.4.14.1-all-languages/data/vhost/www2/myadmin
[root@zq ~]# ln -s /data/vhost/www2/myadmin/config.sample.inc.php/data/vhost/www2/myadmin/config.inc.php
[root@zq ~]# vim /data/vhost/www2/myadmin/config.inc.php
$cfg['blowfish_secret']= '4pfPnDAJFPA4WMWaQxD'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
随机码用!r opensslrand -base64 15 生成用于通信加密
/*
* Serversconfiguration
*/
$i = 0;
/*
* Firstserver
*/
$i++;
/*Authentication type */
$cfg['Servers'][$i]['auth_type']= 'cookie';
/* Serverparameters */
$cfg['Servers'][$i]['host']= '172.16.35.3'; $cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress']= false;
$cfg['Servers'][$i]['AllowNoPassword']= false;
四.mariadb主机
1.启动被查看数据库且设定其为开机启动
systemctlstart mariadb.service
systemctlstatus mariadb.service
systemctlenabled mariadb.service
2.授权创建用户
[root@zq ~]#mysql
mysql>GRANT ALL ON qqdb.* TO 'qquser'@'172.16.%.%' IDENTIFIED BY 'qqpass';
mysql>FLUSH PRIVILEGES;
mysql>CREATE DATABASE qqdb;
=====================================================================================
五.测试php是否可以连接数据库
http://www1.test.com/测试A主机的静态数据
http://www2.test.com/第1台主机的静态数据连接成功
http://www1.test.com/index.php第2台物理机的第一个虚拟主机的动态数据访问成功
http://www2.test.com/index.php第2台物理机的第二个虚拟主机的动态数据访问成功
http://www1.test.com/wordpress/index.php测试转发第2台主机第一个虚拟主机
http://www2.test.com/myadmin/index.php测试转发第2台主机第二个虚拟主机
六.给B主机上的php-myadmin提供https服务,详情参考单主机部署LAMP
七.压力测试
1.httpd主机的静态数据测试html:
[root@zq~]# ab-c 100 -n 1000 http://www1.test.com/data/vhost/www1/index.html 静态数据
Time perrequest: 17.254 [ms] (mean) 十次的测试数据稳定在这个数值
Time perrequest: 0.172 [ms] (mean, across all concurrent requests)
Transferrate: 2495.00 [Kbytes/sec] received
2.http主机的动态数据测试info() php:
[root@zq~]# ab -c 100 -n 1000 http://www1.test.com/data/vhost/www1/index.php
ConcurrencyLevel: 100
Timetaken for tests: 0.423 seconds
Completerequests: 1000
Failedrequests: 0
Writeerrors: 0
Non-2xxresponses: 1000
Totaltransferred: 226000 bytes
HTMLtransferred: 16000 bytes
Requestsper second: 1613.49 [#/sec] (mean)
Time perrequest: 42.345 [ms] (mean) 十次的测试数据稳定在这个数值
Time perrequest: 0.493 [ms] (mean, across all concurrent requests)
Transferrate: 515.33 [Kbytes/sec] received
3.测试wordpress动态数据
[root@zq~]# ab -c 100 -n 1000 http://www1.test.com/data/vhost/www1/wordpress/index.php
ConcurrencyLevel: 100
Timetaken for tests: 0.428 seconds
Completerequests: 1000
Failedrequests: 0
Writeerrors: 0
Non-2xxresponses: 1000
Totaltransferred: 226000 bytes
HTMLtransferred: 16000 bytes
Requestsper second: 2168.61 [#/sec] (mean)
Time perrequest: 47.690 [ms] (mean) 十次的测试数据稳定在这个数值
Time perrequest: 0.487 [ms] (mean, across all concurrent requests)
Transferrate: 46.59 [Kbytes/sec] received
4.动态测试myadmin数据
[root@zq~]# ab -c 100 -n 1000 http://www2.test.com/data/vhost/www2/myadmin/index.php
DocumentPath: /data/vhost/www2/myadmin/index.php
DocumentLength: 16 bytes
ConcurrencyLevel: 100
Timetaken for tests: 0.495 seconds
Completerequests: 1000
Failedrequests: 0
Writeerrors: 0
Non-2xxresponses: 1000
Totaltransferred: 226000 bytes
HTMLtransferred: 16000 bytes
Requestsper second: 2168.43 [#/sec] (mean)
Time perrequest: 45.840 [ms] (mean) 十次的测试数据稳定在这个数值
Time perrequest: 0.490 [ms] (mean, across all concurrent requests)
Transferrate: 486.59 [Kbytes/sec] received
注意对于bash来书单次接受的数据不能大于10024所以压力测试时不能把数值调的过大
5.表格:
并发100请求1000 | 并发100请求1000 | 并发100请求1000 | |
单台主机做LAMP | 122.684 | 119.658 | 118.152 |
三台主机做LAMP | 48.658 | 47.685 | 48.158 |
所以用三台主机的话动态数据的响应速度会大大提高
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。