三臺(tái)主機(jī)分別部署LAMP
創(chuàng)新互聯(lián)建站是一家集網(wǎng)站建設(shè),甘肅企業(yè)網(wǎng)站建設(shè),甘肅品牌網(wǎng)站建設(shè),網(wǎng)站定制,甘肅網(wǎng)站建設(shè)報(bào)價(jià),網(wǎng)絡(luò)營(yíng)銷,網(wǎng)絡(luò)優(yōu)化,甘肅網(wǎng)站推廣為一體的創(chuàng)新建站企業(yè),幫助傳統(tǒng)企業(yè)提升企業(yè)形象加強(qiáng)企業(yè)競(jìng)爭(zhēng)力??沙浞譂M足這一群體相比中小企業(yè)更為豐富、高端、多元的互聯(lián)網(wǎng)需求。同時(shí)我們時(shí)刻保持專業(yè)、時(shí)尚、前沿,時(shí)刻以成就客戶成長(zhǎng)自我,堅(jiān)持不斷學(xué)習(xí)、思考、沉淀、凈化自己,讓我們?yōu)楦嗟钠髽I(yè)打造出實(shí)用型網(wǎng)站。
要求:httpd, php, mariadb分別部署在一個(gè)單獨(dú)的主機(jī)上,一個(gè)虛擬主機(jī)提供phpMyAdmin,另一個(gè)虛擬主機(jī)提供wordpress,為phpMyAdmim提供https服務(wù);
一. 分工三臺(tái)主機(jī)
A httpd主機(jī) 172.16.35.1
B php-fpm主機(jī) 172.16.35.2
C mariadb主機(jī) 172.16.35.3
為方便實(shí)驗(yàn)在這里關(guān)閉防火墻
#iptables-F
#setenforce0
安裝所需rpm包:
在A上yum -y install httpd,B主機(jī)yum -y install php-fpm, C上yum -y install mariade-server php-MySQL
二. httpd主機(jī)設(shè)置
1.設(shè)置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動(dòng)態(tài)資源代理轉(zhuǎn)發(fā)給第2臺(tái)主機(jī)
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動(dòng)態(tài)資源代理轉(zhuǎn)發(fā)給第2臺(tái)主機(jī)
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.創(chuàng)建靜態(tài)默認(rèn)文件:
[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.然后測(cè)試本機(jī)靜態(tài)數(shù)據(jù)是否可以正常訪問(wèn)
================================================================
三.php-fpm主機(jī):
1.修改配置文件
[root@zq~]# vim /etc/php-fpm.d/www.conf
listen = 172.16.35.2:9000監(jiān)聽(tīng)本機(jī)地址端口
listen.allowed_clients= 172.16.35.1允許A主機(jī)連接
2.創(chuàng)建資源映射目錄及文件
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設(shè)置 -具體信息來(lái)自您正在使用的主機(jī) ** //
/**WordPress數(shù)據(jù)庫(kù)的名稱 */
define('DB_NAME','qqdb');
/** MySQL數(shù)據(jù)庫(kù)用戶名 */
define('DB_USER','qquser');
/** MySQL數(shù)據(jù)庫(kù)密碼 */
define('DB_PASSWORD',qqpass');
/** MySQL主機(jī) */
define('DB_HOST','172.16.35.3');這里的地址是指向第C主機(jī)的數(shù)據(jù)庫(kù)地址
/**創(chuàng)建數(shù)據(jù)表時(shí)默認(rèn)的文字編碼 */
define('DB_CHARSET','utf8');
/**數(shù)據(jù)庫(kù)整理類型。如不確定請(qǐng)勿更改 */
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! */
隨機(jī)碼用!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主機(jī)
1.啟動(dòng)被查看數(shù)據(jù)庫(kù)且設(shè)定其為開(kāi)機(jī)啟動(dòng)
systemctlstart mariadb.service
systemctlstatus mariadb.service
systemctlenabled mariadb.service
2.授權(quán)創(chuàng)建用戶
[root@zq ~]#mysql
mysql>GRANT ALL ON qqdb.* TO 'qquser'@'172.16.%.%' IDENTIFIED BY 'qqpass';
mysql>FLUSH PRIVILEGES;
mysql>CREATE DATABASE qqdb;
=====================================================================================
五.測(cè)試php是否可以連接數(shù)據(jù)庫(kù)
http://www1.test.com/測(cè)試A主機(jī)的靜態(tài)數(shù)據(jù)
http://www2.test.com/第1臺(tái)主機(jī)的靜態(tài)數(shù)據(jù)連接成功
http://www1.test.com/index.php第2臺(tái)物理機(jī)的第一個(gè)虛擬主機(jī)的動(dòng)態(tài)數(shù)據(jù)訪問(wèn)成功
http://www2.test.com/index.php第2臺(tái)物理機(jī)的第二個(gè)虛擬主機(jī)的動(dòng)態(tài)數(shù)據(jù)訪問(wèn)成功
http://www1.test.com/wordpress/index.php測(cè)試轉(zhuǎn)發(fā)第2臺(tái)主機(jī)第一個(gè)虛擬主機(jī)
http://www2.test.com/myadmin/index.php測(cè)試轉(zhuǎn)發(fā)第2臺(tái)主機(jī)第二個(gè)虛擬主機(jī)
六.給B主機(jī)上的php-myadmin提供https服務(wù),詳情參考單主機(jī)部署LAMP
七.壓力測(cè)試
1.httpd主機(jī)的靜態(tài)數(shù)據(jù)測(cè)試html:
[root@zq~]# ab-c 100 -n 1000http://www1.test.com/data/vhost/www1/index.html靜態(tài)數(shù)據(jù)
Time perrequest: 17.254 [ms] (mean)十次的測(cè)試數(shù)據(jù)穩(wěn)定在這個(gè)數(shù)值
Time perrequest: 0.172 [ms] (mean, across all concurrent requests)
Transferrate: 2495.00 [Kbytes/sec] received
2.http主機(jī)的動(dòng)態(tài)數(shù)據(jù)測(cè)試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)十次的測(cè)試數(shù)據(jù)穩(wěn)定在這個(gè)數(shù)值
Time perrequest: 0.493 [ms] (mean, across all concurrent requests)
Transferrate: 515.33 [Kbytes/sec] received
3.測(cè)試wordpress動(dòng)態(tài)數(shù)據(jù)
[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)十次的測(cè)試數(shù)據(jù)穩(wěn)定在這個(gè)數(shù)值
Time perrequest: 0.487 [ms] (mean, across all concurrent requests)
Transferrate: 46.59 [Kbytes/sec] received
4.動(dòng)態(tài)測(cè)試myadmin數(shù)據(jù)
[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)十次的測(cè)試數(shù)據(jù)穩(wěn)定在這個(gè)數(shù)值
Time perrequest: 0.490 [ms] (mean, across all concurrent requests)
Transferrate: 486.59 [Kbytes/sec] received
注意對(duì)于bash來(lái)書(shū)單次接受的數(shù)據(jù)不能大于10024所以壓力測(cè)試時(shí)不能把數(shù)值調(diào)的過(guò)大
5.表格:
并發(fā)100請(qǐng)求1000 | 并發(fā)100請(qǐng)求1000 | 并發(fā)100請(qǐng)求1000 | |
單臺(tái)主機(jī)做LAMP | 122.684 | 119.658 | 118.152 |
三臺(tái)主機(jī)做LAMP | 48.658 | 47.685 | 48.158 |
所以用三臺(tái)主機(jī)的話動(dòng)態(tài)數(shù)據(jù)的響應(yīng)速度會(huì)大大提高