大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
三台主机分别部署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
ServerNamewww1.test.com
DocumentRoot"/data/vhost/www1"
ProxyRequestson
DirectoryIndexindex.php
ProxyPassMatch^/(.*\.php)$ fcgi://172.16.35.2:9000/data/vhost/www1/$1动态资源代理转发给第2台主机
OptionsNone
AllowOverrideNone
Requireall granted
[root@zq~]# vim /etc/httpd/conf.d/vhost2.conf
ServerNamewww2.test.com
DocumentRoot"/data/vhost/www2"
ProxyRequestson
DirectoryIndexindex.php
ProxyPassMatch^/(.*\.php)$ fcgi://172.16.35.2:9000/data/vhost/www2/$1动态资源代理转发给第2台主机
OptionsNone
AllowOverrideNone
Requireall granted
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
[root@zq~]# vim /data/vhost/www2/index.html
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
$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
$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@zqwordpress]# ln -s wp-config-sample.phpwp-config.php
[root@zqwordpress]# 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! */
随机码用!ropensslrand -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 1000http://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 1000http://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 1000http://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 1000http://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 |
所以用三台主机的话动态数据的响应速度会大大提高