您好,登錄后才能下訂單哦!
CentOS 7, amp + xcache, rpm包,php-fpm;
a) httpd, php, mariadb分別部署在一個單獨的主機上;
b) 一個虛擬主機提供phpMyAdmin,另一個虛擬主機提供wordpress;
c) 為phpMyAdmim提供https服務;
分別三臺centos 7主機分別部署 httpd , php-fpm , mariadb
第一臺 172.16.100.31 -->httpd
第二臺 172.16.100.32 -->php-fpm 分別在2臺虛擬主機上部署wordpress和phpmyadmin
第三臺 172.16.100.33 -->mariadb
開始之前 首先把iptables 和SElinux給關閉了 方便測試
#iptables -F
#setenforce 0
那么我們先從第一臺開始:
#安裝htppd
yum -y instal httpd
#以FQDN配置2個虛擬主機的文件:
[root@localhost ~]# vim /etc/httpd/conf.d/vhost1.conf
<VirtualHost 172.16.100.31:80>
ServerName www1.wufeng.com
DocumentRoot "/data/vhost/www1"
ProxyRequests on
DirectoryIndex index.php
ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.100.32:9000/data/vhost/www1/$1 動態資源代理轉發給第2臺主機
<Directory "/data/vhost/www1">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
[root@localhost ~]# vim /etc/httpd/conf.d/vhost2.conf
<VirtualHost 172.16.100.31:80>
ServerName www2wufeng.com
DocumentRoot "/data/vhost/www2"
ProxyRequests on
DirectoryIndex index.php
ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.100.32:9000/data/vhost/www2/$1 動態資源代理轉發給第2臺主機
<Directory "/data/vhost/www2">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
#修改etc下的2個配置文件指定NDS以及域名解析
[root@localhost ~]# vim /etc/resolv.conf
# Generated by NetworkManager
DNS=172.16.100.31
nameserver 172.16.0.1
#本地域名解析
[root@localhost ~]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.100.31 www1.wufeng.com www2.wufeng.com
#創建靜態默認文件:
[root@localhost ~]# mkdir -pv /data/vhost/www{1,2}
[root@localhost ~]# vim /data/vhost/www1/index.html
<h2>峰哥1第1臺物理機靜態數據 172.16.100.31</h2>
[root@localhost ~]# vim /data/vhost/www2/index.html
<h2>峰哥2第1臺物理機靜態數據 172.16.100.31</h2>
#然后測試本機靜態數據是否可以正常訪問
================================================================
第二臺主機:
#向要安裝php-fpm
yum -y install php-fpm
#修改配置文件
[root@localhost ~]# vim /etc/php-fpm.d/www.conf
listen = 172.16.100.32:9000 監聽本機地址端口
listen.allowed_clients = 172.16.100.31 允許第一臺主機連接
#創建資源映射目錄及文件
mkdir -pv /data/vhost/www{1,2}
#寫入測試php的文件
[root@localhost ~]# vim /data/vhost/www1/index.php
<h2>第2臺物理機a</h2>
<?php
$conn = mysql_connect('172.16.100.33','testuser','testpass');
if($conn)
echo "OK";
else
echo "Failure";
phpinfo();
?>
#然后安裝加速器php-xcache
yum -y install php-xcache
#然后安裝wordpress以及php-myadmin
#我們要把這2個程序分別部署在第2臺主機上的2個分別的資源映射路徑下
#我是直接在ftp服務器上下載的所以直接就解壓了
#首先我們先搞定wordpress
[root@localhost ~]# unzip wordpress-4.3.1-zh_CN.zip
#并移動至第一個虛擬主機的資源映射路徑下
[root@localhost ~]# mv wordpress /data/vhost/www1
#cd進入該目錄下并且修改配置文件
#注意這個配置文件里面添加的是第3臺主機上的數據庫信息我們當前還沒有創建數據庫可以先修改,之后在以這個配置創建數據庫;
#修改配置文件名并修改之;
[root@localhost ~]# cd /data/vhost/www1/wordpress/
[root@localhost wordpress]# ln -s wp-config-sample.php wp-config.php
[root@localhost wordpress]# vim wp-config.php
// ** MySQL 設置 - 具體信息來自您正在使用的主機 ** //
/** WordPress數據庫的名稱 */
define('DB_NAME', 'wpdb');
/** MySQL數據庫用戶名 */
define('DB_USER', 'wpuser');
/** MySQL數據庫密碼 */
define('DB_PASSWORD', 'wppass');
/** MySQL主機 */
define('DB_HOST', '172.16.100.33'); 這里的地址是指向第3臺主機的數據庫地址
/** 創建數據表時默認的文字編碼 */
define('DB_CHARSET', 'utf8');
/** 數據庫整理類型。如不確定請勿更改 */
define('DB_COLLATE', '');
那么wordpress基本上已經配置好了 不急于測試 下面把php-myadmin也一起安裝了
#php-myadmin也是在ftp服務器上下載的所以直接解壓了
[root@localhost ~]# unzip phpMyAdmin-4.4.14.1-all-languages.zip
#并且放在第2臺主機上的第2個虛擬主機資源映射路徑下;
[root@localhost ~]# mv phpMyAdmin-4.4.14.1-all-languages /data/vhost/www2/
#cd進該目錄下并且修改文件名修改配置
[root@localhost ~]# cd /data/vhost/www2/ 進入目錄
[root@localhost www2]# ln -s phpMyAdmin-4.4.14.1-all-languages myadmin 創建一個鏈接
[root@localhost www2]# cd myadmin/ 進入目標目錄
[root@localhost myadmin]# ln -s config.sample.inc.php config.inc.php 創建配置文件連接
[root@localhost myadmin]# vim config.inc.php
$cfg['blowfish_secret'] = '4pfPnJU4R8pA4WMWaQxD'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */
上面這2個單引號中間加上隨機碼 用openssl rand -base64 15 生成 用于通信加密
/*
* Servers configuration
*/
$i = 0;
/*
* First server
*/
$i++;
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '172.16.100.33'; 這里這指向mysql數據庫主機的地址
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = false;
那么現在我們第2臺主機的配置基本完成
=====================================================================================
下面再去第3臺主機創建mysql數據庫
第三臺物理機: 唯一作用就是作為數據庫
#那么首先安裝數據庫
yum -y install mariadb-server
#啟動起來
systemctl start mariadb.service
#然后授權創建用戶
先進mysql 然后如下
mysql> GRANT ALL ON wpdb.* TO 'wpuser'@'172.16.%.%' IDENTIFIED BY 'wppass';
mysql> FLUSH PRIVILEGES;
mysql> CREATE DATABASE wpdb;
=====================================================================================
那么現在可以測試php是否可以連接數據庫了
http://www1.wufeng.com/ 測試第一臺主機的靜態數據
http://www2.wufeng.com/ 第1臺主機的靜態數據連接成功
http://www1.wufeng.com/index.php 第2臺物理機的第一個虛擬主機的動態數據訪問成功
http://www2.wufeng.com/index.php 第2臺物理機的第二個虛擬主機的動態數據訪問成功
http://www1.wufeng.com/wordpress/index.php 測試轉發第2臺主機第一個虛擬主機
http://www2.wufeng.com/myadmin/index.php 測試轉發第2臺主機第二個虛擬主機
#下面我們要給第2臺物理主機的第2個虛擬主機上的php-myadmin提供https服務;
#簽署CA證書并為phpmyadmin提供https服務;
#在第一臺主機上安裝mod_ssl模塊 因為需要http來加載模塊并啟動443端口
[root@localhost CA]# yum install mod_ssl.x86_64
#然后在第2臺主機上生成CA自簽名證書;
1、生成密鑰
#首先進入CA目錄下
[root@1 wordpress]# cd /etc/pki/CA/
#在CA目錄下生成密鑰
[root@1 CA]# (umask 077; openssl genrsa -out private/cakey.pem 2048)
Generating RSA private key, 2048 bit long modulus
............................................................................+++
...............+++
e is 65537 (0x10001)
2、生成自簽證書
[root@1 CA]# openssl req -new -x509 -key private/cakey.pem -out cacert.pem
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:wufeng
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:ca.wufeng.com
Email Address []:admin@wufeng.com
補充文件
[root@1 CA]# touch index.txt
[root@1 CA]# echo 01 > serial
、
#然后在去第1臺主機上生成請求簽署文件以及密鑰
在/etc/httpd/目錄下創建一個目錄
~]# mkdir ssl
~]# cd ssl
生成密鑰
[root@1 ssl]# (umask 077; openssl genrsa -out httpd.key 1024)
Generating RSA private key, 1024 bit long modulus
.++++++
........................................++++++
e is 65537 (0x10001)
生成簽署請求文件:
[root@1 ssl]# openssl req -new -key httpd.key -out httpd.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:beijing
Locality Name (eg, city) [Default City]:beijing
Organization Name (eg, company) [Default Company Ltd]:wufeng
Organizational Unit Name (eg, section) []:ops
Common Name (eg, your name or your server's hostname) []:www2.wufeng.com 這個要和客戶訪問要加密的主機名一樣
Email Address []:www1admin@wufeng.com
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
復制給CA主機簽署證書
[root@1 ssl]# scp httpd.csr 172.16.100.32:/tmp
然后到centos7主機上簽署文件
[root@2 CA]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt
連續2個yes 簡寫y
簽署完成后 復制給請求主機
[root@2 CA]# scp certs/httpd.crt 172.16.100.31:/etc/httpd/ssl/
在請求主機上也就是第2臺centos7上
編輯這個文件
[root@2 ~]# vim /etc/httpd/conf.d/ssl.conf
DocumentRoot "/data/vhost/www2/myadmin" 這2個啟用起來 把前面的#號去掉 改成自己的資源映射路徑
ServerName www2.wufeng.com:443 主機名也改成自己的
SSLCertificateFile /etc/httpd/ssl/httpd.crt 指明簽署的證書文件路徑
SSLCertificateKeyFile /etc/httpd/ssl/httpd.key 指明私鑰文件的路徑
#最重要的一條是需要做轉發
#需要在這里面定義<VirtualHost _default_:443>
ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.100.32:9000/data/vhost/www2/$1
然后reload一下
然后ss -tnl 查看一下443端口起來沒
在centos7 主CA機器上 測試基于https訪問相應的主機;
[root@localhost CA]# openssl s_client -connect 172.16.100.31:443 -CAfile /etc/pki/CA/cacert.pem
#然后打開瀏覽器輸入myadmin地址訪問看看是否提供了https服務
用winds上面的瀏覽器以ip的方式測試https
最后查看xcache服務啟動沒有
最后可以做個壓力測試
首先做httpd主機的靜態數據測試:html
[root@localhost ~]# ab -c 100 -n 1000 http://www1.wufeng.com/data/vhost/www1/index.html 靜態數據
Time per request: 21.244 [ms] (mean) 十次的測試數據穩定在這個數值
Time per request: 0.212 [ms] (mean, across all concurrent requests)
Transfer rate: 1995.00 [Kbytes/sec] received
#動態數據測試info() php
[root@localhost ~]# ab -c 100 -n 1000 http://www1.wufeng.com/data/vhost/www1/index.php
Concurrency Level: 100
Time taken for tests: 0.523 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Total transferred: 226000 bytes
HTML transferred: 16000 bytes
Requests per second: 1913.59 [#/sec] (mean)
Time per request: 52.258 [ms] (mean) 十次的測試數據穩定在這個數值
Time per request: 0.523 [ms] (mean, across all concurrent requests)
Transfer rate: 422.33 [Kbytes/sec] received
#測試wordpress動態數據
[root@localhost ~]# ab -c 100 -n 1000 http://www1.wufeng.com/data/vhost/www1/wordpress/index.php
Concurrency Level: 100
Time taken for tests: 0.517 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Total transferred: 226000 bytes
HTML transferred: 16000 bytes
Requests per second: 1934.61 [#/sec] (mean)
Time per request: 51.690 [ms] (mean) 十次的測試數據穩定在這個數值
Time per request: 0.517 [ms] (mean, across all concurrent requests)
Transfer rate: 426.97 [Kbytes/sec] received
#動態測試myadmin數據
[root@localhost ~]# ab -c 100 -n 1000 http://www2.wufeng.com/data/vhost/www2/myadmin/index.php
Document Path: /data/vhost/www2/myadmin/index.php
Document Length: 16 bytes
Concurrency Level: 100
Time taken for tests: 0.520 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Non-2xx responses: 1000
Total transferred: 226000 bytes
HTML transferred: 16000 bytes
Requests per second: 1923.43 [#/sec] (mean)
Time per request: 51.990 [ms] (mean) 十次的測試數據穩定在這個數值
Time per request: 0.520 [ms] (mean, across all concurrent requests)
Transfer rate: 424.51 [Kbytes/sec] received
#友情提示不要太奔放 比如:
[root@localhost ~]# ab -c 1000 -n 10000 http://www2.wufeng.com/data/vhost/www2/index.php
然后第2臺 php主機就掛了
比較2個架構性能的差別
單臺主機部署LAMP
三臺主機分別部署LAMP
結論很明顯 三臺主機分別部署LAMP的性能是單臺主機的2倍
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。