天天看點

在win7實體機,使用vmware,3台centos7系統,分别部署httpd,php-fpm,mariadb

實驗環境,實體機為win7系統,使用vmare建立3台centos7系統,每台分别部署httpd,php-fpm,mariadb

要求:

(1)一個虛拟主機用于提供phpMyAdmin;另一個虛拟主機用于提供wordpress。

(2)xcache為php加速。

web伺服器安裝httpd程式,主機ip為:172.18.11.111

php伺服器安裝php-fpm程式,主機ip為:172.18.11.112

mysql資料庫伺服器安裝mariadb-server程式,主機ip為:172.18.11.113

在web伺服器上操作:

]# yum -y install httpd

]# systemctl start httpd.service

主配置檔案修改相關資訊:

]# vim /etc/httpd/conf/httpd.conf

<a href="http://s5.51cto.com/wyfs02/M01/7F/6E/wKiom1ceJw6AM34tAAAGu9NYDAQ426.png" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M00/7F/6E/wKiom1ceME-gn-c-AAASB_HdexM447.png" target="_blank"></a>

<a href="http://s4.51cto.com/wyfs02/M00/7F/6C/wKioL1ceMTqDBCSAAAAS0ShNeX4346.png" target="_blank"></a>

建立網頁路徑

]# mkdir /web/vhost/{www1,www2} -pv

建立虛拟主機配置檔案

]# vim /etc/httpd/conf.d/vhost.conf

<a href="http://s3.51cto.com/wyfs02/M02/7F/6E/wKiom1ceLBvQ1w7oAACa8mbNVD4578.png" target="_blank"></a>

在php主機操作:

]# yum -y install php-fpm

]# systemctl start php-fpm.service

修改本機監聽ip位址172.18.11.112,允許前端web伺服器為用戶端監聽的ip位址172.18.11.111

<a href="http://s2.51cto.com/wyfs02/M00/7F/6C/wKioL1ceKveTEPjoAAB0tRu7SSA385.png" target="_blank"></a>

]# vim /web/vhost/www1/index.php

<a href="http://s5.51cto.com/wyfs02/M02/7F/6E/wKiom1ceMPOwCM59AAAYb6agFQk503.png" target="_blank"></a>

]# vim /web/vhost/www2/index.php

<a href="http://s2.51cto.com/wyfs02/M01/7F/6E/wKiom1ceMSrA8mVlAAAYfaOY8ME225.png" target="_blank"></a>

在win7實體機浏覽器測試,web伺服器是否能把php檔案轉發給php伺服器加載

<a href="http://s2.51cto.com/wyfs02/M00/7F/6D/wKioL1ceMnWzOGZZAACmpGaaLGM386.png" target="_blank"></a>

<a href="http://s3.51cto.com/wyfs02/M00/7F/6D/wKioL1ceMnegjwSyAACY24dwEwI969.png" target="_blank"></a>

成功web伺服器轉發php檔案給php伺服器。

在mysql主機操作:

]# yum -y install mariadb-server

]# systemctl start mariadb.service

]# vim /etc/my.cnf

<a href="http://s1.51cto.com/wyfs02/M00/7F/6F/wKiom1ceMzDAehrzAAAvS4DjMYU818.png" target="_blank"></a>

加強資料庫

]# mysql_secure_installation

根據提示可自行設定(過程略)

登入資料庫并授權遠端使用者通路資料庫

]# mysql -uroot -proot

&gt; GRANT ALL ON wpdb.* TO wpuser@'172.18.%.%' IDENTIFIED BY 'wppass';

&gt; GRANT ALL ON pmadb.* TO pmauser@'172.18.%.%' IDENTIFIED BY 'pmapass';

安裝連接配接資料庫的用戶端

]# yum -y install php-mysql

建立測試頁

<a href="http://s4.51cto.com/wyfs02/M00/7F/6D/wKioL1ceOAXhAyXpAAAnRMJAo4s321.png" target="_blank"></a>

<a href="http://s5.51cto.com/wyfs02/M02/7F/6D/wKioL1ceOCPC4NdeAAAlM1F_tO4424.png" target="_blank"></a>

在win7實體機浏覽器測試,通路web伺服器是否能把php檔案中請求的資料庫資訊轉發到mysql伺服器加載

<a href="http://s4.51cto.com/wyfs02/M01/7F/6F/wKiom1ceN9riJXNpAABSmMo2xXU539.png" target="_blank"></a>

<a href="http://s4.51cto.com/wyfs02/M00/7F/6F/wKiom1ceN9uxmLJaAABErateusk713.png" target="_blank"></a>

測試成功,此時3台伺服器已經能互通了。

在php伺服器上操作:

把phpMyAdmin解壓在/web/vhost/www1目錄下并重命名

]# mv phpMyAdmin-4.4.14.1-all-languages pma

]# cd pma

]# cp config.sample.inc.php config.inc.php

生成随機數填入下面配置檔案中

]# openssl rand -base64 15

iFlj9CCD16fhODVyMhcX

]# vim config.inc.php

填入随機數,及資料庫ip位址

<a href="http://s5.51cto.com/wyfs02/M00/7F/70/wKiom1cexlayU9SoAABBWzm9hGM745.png" target="_blank"></a>

在win7中浏覽器測試pma

<a href="http://s1.51cto.com/wyfs02/M02/7F/70/wKiom1cexpqiyIysAABUBuztykc027.png" target="_blank"></a>

安裝pma所需的字元集

]#yum -y install php-mbstring

<a href="http://s4.51cto.com/wyfs02/M02/7F/6D/wKioL1cex8GAEmx4AAC5hkdyM_8058.png" target="_blank"></a>

輸入資料庫的使用者名、密碼成功登入;

<a href="http://s3.51cto.com/wyfs02/M01/7F/70/wKiom1cexyzhH-fWAAGK5JWMvOc549.png" target="_blank"></a>

]# chown -R apache:apache /var/lib/php

]# mkdir /var/lib/php/session

]# chown apache.apache /var/lib/php/session

安裝wordpress解壓在/web/vhost/www2目錄下

]# cd wordpress/

]# cp wp-config-sample.php wp-config.php

]# vim wp-config.php

<a href="http://s3.51cto.com/wyfs02/M01/7F/70/wKiom1cex5_ihyFzAAA1SGoHZLc309.png" target="_blank"></a>

在win7實體機浏覽器上測試wordpress

<a href="http://s4.51cto.com/wyfs02/M01/7F/6D/wKioL1ceyK-gYyfLAACdtqYVaIQ445.png" target="_blank"></a>

輸入個人資訊,點選安裝wordpress

<a href="http://s3.51cto.com/wyfs02/M02/7F/70/wKiom1cex-jzwHrRAACZC6liL2Y552.png" target="_blank"></a>

點選登入,填入剛才輸入的使用者名、密碼

<a href="http://s5.51cto.com/wyfs02/M02/7F/6D/wKioL1ceyLGQCRCVAABgzgFR0i0332.png" target="_blank"></a>

<a href="http://s5.51cto.com/wyfs02/M01/7F/6D/wKioL1ceyLKBLIWnAABwq7tr_HQ832.png" target="_blank"></a>

登入成功

<a href="http://s4.51cto.com/wyfs02/M00/7F/70/wKiom1cex-rT0xOnAAEDV9Gvd6s451.png" target="_blank"></a>

安裝xcache為php加速

在httpd主機操作:

未安裝xcache加速時使用ab測試

測試三次

<a href="http://s4.51cto.com/wyfs02/M02/7F/70/wKiom1cezGOwk8ufAABaE3A0Nr8558.png" target="_blank"></a>

<a href="http://s5.51cto.com/wyfs02/M01/7F/6E/wKioL1cezS3RtVTLAABXqb-S9pM254.png" target="_blank"></a>

<a href="http://s5.51cto.com/wyfs02/M02/7F/6E/wKioL1cezS2BQD32AABY47ikWc0434.png" target="_blank"></a>

檢視Requests per second,三次平均為54左右;

]# yum -y install php-xcache

編寫php測試頁

<a href="http://s1.51cto.com/wyfs02/M01/7F/6E/wKioL1ceze_gdIA-AAAYb6agFQk208.png" target="_blank"></a>

在win7系統上打開浏覽器

<a href="http://s1.51cto.com/wyfs02/M00/7F/70/wKiom1cezdegAIMcAACh6WKSscU510.png" target="_blank"></a>

成功加載xcache

可自行在httpd主機上,使用ab指令測試,步驟同上。

本文轉自 crystaleone 51CTO部落格,原文連結:http://blog.51cto.com/linsj/1767737,如需轉載請自行聯系原作者