三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb


      CentOS 7, amp + xcache, rpm包,php-fpm;

創(chuàng)新互聯(lián)自2013年起,先為潞城等服務(wù)建站,潞城等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為潞城企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問題。

                a) httpd, php, mariadb分別部署在一個單獨(dú)的主機(jī)上;

                b) 一個虛擬主機(jī)提供phpMyAdmin,另一個虛擬主機(jī)提供wordpress;

                c) 為phpMyAdmim提供https服務(wù);


分別三臺centos 7主機(jī)分別部署 httpd , php-fpm  ,  mariadb

第一臺 172.16.100.31 -->httpd

第二臺 172.16.100.32 -->php-fpm    分別在2臺虛擬主機(jī)上部署wordpress和phpmyadmin

第三臺 172.16.100.33 -->mariadb

開始之前 首先把iptables 和SElinux給關(guān)閉了  方便測試

        #iptables -F

        #setenforce 0

那么我們先從第一臺開始:

        #安裝htppd

yum -y instal httpd

        #以FQDN配置2個虛擬主機(jī)的文件:

[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        動態(tài)資源代理轉(zhuǎn)發(fā)給第2臺主機(jī)

        <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    動態(tài)資源代理轉(zhuǎn)發(fā)給第2臺主機(jī)

        <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

        #創(chuàng)建靜態(tài)默認(rèn)文件:

[root@localhost ~]# mkdir -pv /data/vhost/www{1,2}

[root@localhost ~]# vim /data/vhost/www1/index.html

<h2>峰哥1第1臺物理機(jī)靜態(tài)數(shù)據(jù)    172.16.100.31</h2>

[root@localhost ~]# vim /data/vhost/www2/index.html

<h2>峰哥2第1臺物理機(jī)靜態(tài)數(shù)據(jù)    172.16.100.31</h2>

        #然后測試本機(jī)靜態(tài)數(shù)據(jù)是否可以正常訪問

================================================================

           

第二臺主機(jī):

        #向要安裝php-fpm

yum -y install php-fpm

        #修改配置文件

[root@localhost ~]# vim /etc/php-fpm.d/www.conf 

listen = 172.16.100.32:9000        監(jiān)聽本機(jī)地址端口

listen.allowed_clients = 172.16.100.31        允許第一臺主機(jī)連接


        #創(chuàng)建資源映射目錄及文件

mkdir -pv /data/vhost/www{1,2}


        #寫入測試php的文件

[root@localhost ~]# vim /data/vhost/www1/index.php

<h2>第2臺物理機(jī)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臺主機(jī)上的2個分別的資源映射路徑下

        #我是直接在ftp服務(wù)器上下載的所以直接就解壓了

     

       #首先我們先搞定wordpress

[root@localhost ~]# unzip wordpress-4.3.1-zh_CN.zip 


        #并移動至第一個虛擬主機(jī)的資源映射路徑下

[root@localhost ~]# mv wordpress /data/vhost/www1

        #cd進(jìn)入該目錄下并且修改配置文件

        #注意這個配置文件里面添加的是第3臺主機(jī)上的數(shù)據(jù)庫信息我們當(dāng)前還沒有創(chuàng)建數(shù)據(jù)庫可以先修改,之后在以這個配置創(chuàng)建數(shù)據(jù)庫;

        #修改配置文件名并修改之;

[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 設(shè)置 - 具體信息來自您正在使用的主機(jī) ** //

/** WordPress數(shù)據(jù)庫的名稱 */

define('DB_NAME', 'wpdb');

/** MySQL數(shù)據(jù)庫用戶名 */

define('DB_USER', 'wpuser');

/** MySQL數(shù)據(jù)庫密碼 */

define('DB_PASSWORD', 'wppass');

/** MySQL主機(jī) */

define('DB_HOST', '172.16.100.33');            這里的地址是指向第3臺主機(jī)的數(shù)據(jù)庫地址

/** 創(chuàng)建數(shù)據(jù)表時(shí)默認(rèn)的文字編碼 */

define('DB_CHARSET', 'utf8');

/** 數(shù)據(jù)庫整理類型。如不確定請勿更改 */

define('DB_COLLATE', '');

那么wordpress基本上已經(jīng)配置好了 不急于測試 下面把php-myadmin也一起安裝了

        #php-myadmin也是在ftp服務(wù)器上下載的所以直接解壓了

[root@localhost ~]# unzip phpMyAdmin-4.4.14.1-all-languages.zip 

        #并且放在第2臺主機(jī)上的第2個虛擬主機(jī)資源映射路徑下;

[root@localhost ~]# mv phpMyAdmin-4.4.14.1-all-languages /data/vhost/www2/

        #cd進(jìn)該目錄下并且修改文件名修改配置

[root@localhost ~]# cd /data/vhost/www2/            進(jìn)入目錄

[root@localhost www2]# ln -s phpMyAdmin-4.4.14.1-all-languages myadmin        創(chuàng)建一個鏈接

[root@localhost www2]# cd myadmin/        進(jìn)入目標(biāo)目錄

[root@localhost myadmin]# ln -s config.sample.inc.php config.inc.php        創(chuàng)建配置文件連接

[root@localhost myadmin]# vim config.inc.php

$cfg['blowfish_secret'] = '4pfPnJU4R8pA4WMWaQxD'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

                                                           上面這2個單引號中間加上隨機(jī)碼 用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數(shù)據(jù)庫主機(jī)的地址

$cfg['Servers'][$i]['connect_type'] = 'tcp';

$cfg['Servers'][$i]['compress'] = false;

$cfg['Servers'][$i]['AllowNoPassword'] = false;

那么現(xiàn)在我們第2臺主機(jī)的配置基本完成

=====================================================================================

下面再去第3臺主機(jī)創(chuàng)建mysql數(shù)據(jù)庫

第三臺物理機(jī):            唯一作用就是作為數(shù)據(jù)庫

        #那么首先安裝數(shù)據(jù)庫

yum -y install mariadb-server

        #啟動起來

systemctl start mariadb.service

        #然后授權(quán)創(chuàng)建用戶

先進(jìn)mysql  然后如下

mysql> GRANT ALL ON wpdb.* TO 'wpuser'@'172.16.%.%' IDENTIFIED BY 'wppass';

mysql> FLUSH PRIVILEGES;

mysql>  CREATE DATABASE wpdb;


=====================================================================================

那么現(xiàn)在可以測試php是否可以連接數(shù)據(jù)庫了

http://www1.wufeng.com/   測試第一臺主機(jī)的靜態(tài)數(shù)據(jù)三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

http://www2.wufeng.com/        第1臺主機(jī)的靜態(tài)數(shù)據(jù)連接成功

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

http://www1.wufeng.com/index.php    第2臺物理機(jī)的第一個虛擬主機(jī)的動態(tài)數(shù)據(jù)訪問成功

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

http://www2.wufeng.com/index.php    第2臺物理機(jī)的第二個虛擬主機(jī)的動態(tài)數(shù)據(jù)訪問成功

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

http://www1.wufeng.com/wordpress/index.php            測試轉(zhuǎn)發(fā)第2臺主機(jī)第一個虛擬主機(jī)

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

http://www2.wufeng.com/myadmin/index.php            測試轉(zhuǎn)發(fā)第2臺主機(jī)第二個虛擬主機(jī)

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

            #下面我們要給第2臺物理主機(jī)的第2個虛擬主機(jī)上的php-myadmin提供https服務(wù);

            #簽署CA證書并為phpmyadmin提供https服務(wù);

            #在第一臺主機(jī)上安裝mod_ssl模塊 因?yàn)樾枰猦ttp來加載模塊并啟動443端口

[root@localhost CA]# yum install mod_ssl.x86_64 

            #然后在第2臺主機(jī)上生成CA自簽名證書;

1、生成密鑰

            #首先進(jìn)入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

補(bǔ)充文件

[root@1 CA]# touch index.txt

[root@1 CA]# echo 01 > serial


、

            #然后在去第1臺主機(jī)上生成請求簽署文件以及密鑰

在/etc/httpd/目錄下創(chuàng)建一個目錄

~]# 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    這個要和客戶訪問要加密的主機(jī)名一樣

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 []:

復(fù)制給CA主機(jī)簽署證書 

[root@1 ssl]# scp httpd.csr 172.16.100.32:/tmp

然后到centos7主機(jī)上簽署文件

[root@2 CA]# openssl ca -in /tmp/httpd.csr -out /etc/pki/CA/certs/httpd.crt

連續(xù)2個yes   簡寫y


簽署完成后 復(fù)制給請求主機(jī)

[root@2 CA]# scp certs/httpd.crt 172.16.100.31:/etc/httpd/ssl/


在請求主機(jī)上也就是第2臺centos7上

編輯這個文件

[root@2 ~]# vim /etc/httpd/conf.d/ssl.conf 

DocumentRoot "/data/vhost/www2/myadmin"        這2個啟用起來 把前面的#號去掉 改成自己的資源映射路徑

ServerName www2.wufeng.com:443            主機(jī)名也改成自己的

SSLCertificateFile /etc/httpd/ssl/httpd.crt       指明簽署的證書文件路徑

SSLCertificateKeyFile /etc/httpd/ssl/httpd.key  指明私鑰文件的路徑

            #最重要的一條是需要做轉(zhuǎn)發(fā)

            #需要在這里面定義<VirtualHost _default_:443>

ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.100.32:9000/data/vhost/www2/$1

 然后reload一下

然后ss -tnl 查看一下443端口起來沒

在centos7 主CA機(jī)器上 測試基于https訪問相應(yīng)的主機(jī);

                  

[root@localhost CA]# openssl s_client -connect 172.16.100.31:443 -CAfile /etc/pki/CA/cacert.pem

            #然后打開瀏覽器輸入myadmin地址訪問看看是否提供了https服務(wù)

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

用winds上面的瀏覽器以ip的方式測試https

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

最后查看xcache服務(wù)啟動沒有

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

最后可以做個壓力測試

首先做httpd主機(jī)的靜態(tài)數(shù)據(jù)測試:html

[root@localhost ~]# ab -c 100 -n 1000 http://www1.wufeng.com/data/vhost/www1/index.html        靜態(tài)數(shù)據(jù)

Time per request:       21.244 [ms] (mean)                十次的測試數(shù)據(jù)穩(wěn)定在這個數(shù)值

Time per request:       0.212 [ms] (mean, across all concurrent requests)

Transfer rate:          1995.00 [Kbytes/sec] received

            #動態(tài)數(shù)據(jù)測試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)                十次的測試數(shù)據(jù)穩(wěn)定在這個數(shù)值

Time per request:       0.523 [ms] (mean, across all concurrent requests)

Transfer rate:          422.33 [Kbytes/sec] received

            #測試wordpress動態(tài)數(shù)據(jù)

[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)                十次的測試數(shù)據(jù)穩(wěn)定在這個數(shù)值

Time per request:       0.517 [ms] (mean, across all concurrent requests)

Transfer rate:          426.97 [Kbytes/sec] received

            #動態(tài)測試myadmin數(shù)據(jù)

[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)                十次的測試數(shù)據(jù)穩(wěn)定在這個數(shù)值

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主機(jī)就掛了

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

比較2個架構(gòu)性能的差別

單臺主機(jī)部署LAMP

三臺主機(jī)分別部署LAMP

三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb

結(jié)論很明顯 三臺主機(jī)分別部署LAMP的性能是單臺主機(jī)的2倍

新聞標(biāo)題:三臺centos7主機(jī)分別部署httpd,php-fpm,mariadb
文章起源:http://bm7419.com/article14/jdeige.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站設(shè)計(jì)、網(wǎng)站排名、企業(yè)建站微信小程序、建站公司、定制網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都網(wǎng)站建設(shè)