標籤:centos lamp
1.A主機的IP 是172.16.25182.,B主機的IP是172.16.251.154,C主機的IP是eth1 172.16.254.35。1. 在A、B、C三台主機上分別安裝httpd、php-fpm、MariaDB。
(1)在A主機上安裝httpd
~]# yum install -y httpd
(2)在B主機上安裝php-fpm
~]# yum install -y php-fpm php-mysql
(3)在C主機上安裝MariaDB
~]# yum install -y mariadb-server
2.編輯B主機的設定檔/etc/php-fpm.d/www.conf並重啟php-fpm服務:
listen = 172.16.251.154:9000
listen.backlog = -1
listen.allowed_clients = 172.16.251.82
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
php_value[session.save_handler] = files
php_value[session.save_path] =/var/lib/php/session
同時需要手動建立目錄/var/lib/php/session,並修改其屬主和屬組為apache
chown apache.apache /var/lib/php/session
3.啟動php-fpm
~]# systemctl start php-fpm.service
4.在A主機上將/etc/httpd/conf.d/welcome.conf改名,然後建立兩個基於FQDN的虛擬機器主機www1.magedu.com和www2.magedu.com.
(1)~]# mv/etc/httpd/conf.d/welcome.conf{,.bak}
(2)編輯www1主機的設定檔/etc/httpd/conf.d/www1.conf並重載httpd服務:
<VirtualHost 172.16.251.82:80>
ServerName www1.magedu.com
DocumentRoot /data/www1
ProxyRequests Off
DirectoryIndex index.php
ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.251.154:9000/data/www1/$1
<Directory "/data/www1">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
(3)編輯www2主機的設定檔/etc/httpd/conf.d/www2.conf並重載httpd服務:
<VirtualHost 172.16.251.82:80>
ServerName www2.magedu.com
DocumentRoot /data/www2
ProxyRequests Off
DirectoryIndex index.php
ProxyPassMatch ^/(.*\.php)$ fcgi://172.16.251.154:9000/data/www2/$1
<Directory "/data/www1">
Options None
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
5.測試
650) this.width=650;" src="http://s5.51cto.com/wyfs02/M00/84/68/wKiom1eQH-CRycLnAAB1agBPPko137.png-wh_500x0-wm_3-wmp_4-s_3783501945.png" title="1.png" alt="wKiom1eQH-CRycLnAAB1agBPPko137.png-wh_50" />
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/84/68/wKioL1eQH-zz5vwjAAB4twFu_XA704.png-wh_500x0-wm_3-wmp_4-s_2533944472.png" title="2.png" alt="wKioL1eQH-zz5vwjAAB4twFu_XA704.png-wh_50" />
6.測試php-fpm與MariaDB的串連。
(1)在MariaDB中建立資料庫testdb,使用者testuser,密碼testpasswd.
~]# mysql
MariaDB[(none)]>CREATEDATABASE testdb;
MariaDB[(none)]>CREATEUSER ‘testuser’@’172.16.%.%’ IDENTIFIED BY ‘testpasswd’;
MariaDB[(none)]>GRANTALL ON testdb.* TO ‘testuser’@’172.16.%.%’;
MariaDB[(none)]>FLUSHPRIVILEGES;
(2)在B主機上分別編輯/data/www1和/data/www2裡面的index.php檔案測試與MariaDB的串連是否正常,內容如下:
<?php
$conn= mysql_connect(‘172.16.254.35’,’testuesr’,’testpasswd’);
If($conn)
echo“OK”;
else
echo“Falure”;
?>
(3)在IE瀏覽器上測試如下:
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M01/84/68/wKioL1eQID-iAf3TAAAzg8cuD6I036.png" title="3.png" alt="wKioL1eQID-iAf3TAAAzg8cuD6I036.png" />
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/84/68/wKiom1eQIEyzjxk7AAAxB0eFrEI673.png" title="4.png" alt="wKiom1eQIEyzjxk7AAAxB0eFrEI673.png" />
7.在B主機上為虛擬機器主機www1上安裝wordpress。
(1)將wordpress解壓後放在/data/www1/目錄下
~]# unzipwordpress_4.3.1_zh_CN.zip
(2)將該目錄下wp-config-sample.php改名為wp-config.php並編輯以下內容:
~]# mv/data/www1/wp-config-sample.php /data/www1/wp-config.php
650) this.width=650;" src="http://s5.51cto.com/wyfs02/M00/84/68/wKiom1eQIGrQpGduAAAuWbFJ_ZA727.png" title="5.png" alt="wKiom1eQIGrQpGduAAAuWbFJ_ZA727.png" />
(3)在瀏覽器上開啟www1.magedu.com測試。
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/84/68/wKioL1eQIIvApztEAACXszedwPU411.png" title="6.png" alt="wKioL1eQIIvApztEAACXszedwPU411.png" />
8.在B主機上為虛擬機器主機www2安裝phpMyAdmin.
(1)將phpMyAdmin解壓並複製到/data/www2/目錄下。
~]# cp -rphpMyAdmin-4.4.15.7-all-languages/* /data/www2/
(2)將config.sample.inc.php改名為config.inc.php
~]# mv config.sample.inc.phpconfig.inc.php
(3)編輯config.inc.php檔案,用openssl產生的隨機碼填充blowfish_secret欄位。
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/84/68/wKiom1eQILaSWByeAAAL-rls1yU177.png" title="7.png" alt="wKiom1eQILaSWByeAAAL-rls1yU177.png" />
(4)編輯config.inc.php檔案,修改[‘Servers‘][$i][‘host‘]欄位的IP地址為172.16.254.35。
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/84/68/wKiom1eQINSwc0IXAAAKZuWAp50025.png" title="8.png" alt="wKiom1eQINSwc0IXAAAKZuWAp50025.png" />
(5)在瀏覽器裡開啟www2.magedu.com測試。
650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/84/68/wKiom1eQIPbjILfUAADodSgmkPE757.png" title="9.png" alt="wKiom1eQIPbjILfUAADodSgmkPE757.png" />
在三台主機上分別安裝httpd、php-fpm、MariaDB