您好,登錄后才能下訂單哦!
三臺主機分別部署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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。