細節要求:(1) 三者分離于三臺主機,Httpd與PHP以FastCGI模式通訊;
(2) 一個虛擬主機用于提供phpMyAdmin;另一個虛擬主機用于提供wordpress;
(3) 部署PHP加速器:xcache;
一、準備CentOS 7主機環境以及Repo倉庫提供基于rpm安裝包方式的程序包安裝源
安裝主機程序包規劃:
主機1:web-server(192.168.1.132) –安裝httpd(2.4.6)
主機2:php-server(192.168.1.200) –安裝php-fpm(5.4.16),php-mysql,xcache,第三方軟件wordpress.phpMyAdmin
主機3:db-server(192.168.1.201) –安裝mariadb-server(5.5.52)
3臺主機均關閉selinux進程
二、web-server主機服務包與程序安裝過程
#yum install httpd -y –安裝httpd服務
#systemctl enable httpd.service –設置httpd服務開機自動運行
#systemctl start httpd.service –啟動httpd服務進程
#systemctl status httpd.serice –查看httpd服務進程狀態
#firewall-cmd –permanent –add-service=http –設置防火墻允許http服務策略
#firewall-cmd –reload –加載防火墻策略
#ss -tnl | grep 80 –查看httpd服務監聽狀態
#httpd -M | grep fcgi –查看httpd服務是否運行fastCGI調用模塊
三、php-server主機安裝過程
#yum install php-fpm php-mysql php-xcache -y –安裝php-fpm服務
#yum install wordpress phpMyAdmin -y –安裝第三方軟件
#vim /etc/php-fpm.d/www/conf –配置php-fpm服務參數
listen = 192.168.1.200:9000 –設置本機的socket監聽服務
listen.allowed_clients = 192.168.1.132 –設置允許訪問php-fpm服務的客戶端地址
#systemctl enable php-fpm.service –啟用php-fpm開機自動運行
#systemctl start php-fpm.service –啟動php-fpm服務進程
#systemctl status php-fpm.service –查看服務進程狀態
#firewall-cmd –permanent –add-port=9000/tcp –設置防火墻允許php-fpm端口策略
#firewall-cmd –reload –加載防火墻策略
#ss -tnl | grep 9000 –查看php-fpm服務的9000端口是否已啟動并監聽
#mkdir -pv /var/www/http/www –創建測試web-server與php-server代理轉發
#vim /var/www/http/www/index.php –創建測試頁面
This is php-server
<?php
phpinfo();
?>
測試結果
針對wordpress第三方軟件的配置
#vim /etc/httpd/conf.d/wordpress.conf
<Directory /usr/share/wordpress>
AllowOverride Options
<IfModule mod_authz_core.c>
# Apache 2.4
Require all granted ##允許遠程網絡瀏覽訪問資源
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
#vim /etc/wordpress/wp-config.php –定義訪問遠程mariadb數據的信息
// ** MySQL settings – You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'test');
/** MySQL database username */
define('DB_USER', 'wordpress');
/** MySQL database password */
define('DB_PASSWORD', 'redhat');
/** MySQL hostname */
define('DB_HOST', '192.168.1.201');
/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');
針對phpMyAdmin第三方軟件的配置
#vim /etc/httpd/conf.d/phpMyAdmin.conf
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
<RequireAny>
Require all granted ##允許遠程網絡瀏覽訪問資源
Require ip ::1
</RequireAny>
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
#vim /etc/phpMyAdmin/config.inc.php –僅指定遠程mariadb數據庫IP地址即可,其他保留默認
// The $cfg['Servers'] array starts with $cfg['Servers'][1]. Do not use
// $cfg['Servers'][0]. You can disable a server config entry by setting host
// to ''. If you want more than one server, just copy following section
// (including $i incrementation) serveral times. There is no need to define
// full server array, just define values you need to change.
$i++;
$cfg['Servers'][$i]['host'] = '192.168.1.201'; // MySQL hostname or IP address
$cfg['Servers'][$i]['port'] = ''; // MySQL port – leave blank for default port
$cfg['Servers'][$i]['socket'] = ''; // Path to the socket – leave blank for default socket
$cfg['Servers'][$i]['connect_type'] = 'tcp'; // How to connect to MySQL server ('tcp' or 'socket')
$cfg['Servers'][$i]['extension'] = 'mysqli'; // The php MySQL extension to use ('mysql' or 'mysqli')
$cfg['Servers'][$i]['compress'] = FALSE; // Use compressed protocol for the MySQL connection
// (requires PHP >= 4.3.0)
$cfg['Servers'][$i]['controluser'] = ''; // MySQL control user settings
// (this user must have read-only
$cfg['Servers'][$i]['controlpass'] = ''; // access to the "mysql/user"
// and "mysql/db" tables).
// The controluser is also
四、db-server主機安裝過程
#yum install mariadb-server -y –安裝mariadb數據庫服務
#firewall-cmd –permanent –add-service=mysql –設置防火墻允許mysql服務端口3306
#firewall-cmd –reload –加載防火墻策略
#vim /etc/my.cnf –修改mariadb配置文件
skip_name_resolve = ON –禁用數據庫主機名解析
#systemctl enable mariadb.service –啟用mariadb服務開機自動運行
#systemctl start mariadb.service –啟動mariadb服務
#systemctl status mariadb.service –查看服務進程狀態
#ss -tnl | grep 3306 –查看mysql端口監聽狀態
#/usr/bin/mysql_secure_install –進行數據庫初始化安裝,設置root密碼,是否允許遠程訪問管理等
#mysql -uroot -hlocalhost -p –設置第三方程序訪問數據庫的賬戶權限
Mariadb[(none)]>grant all privileges on test.* to 'wordpress'@'192.168.1.%' identified by 'redhat'; –授予wordpress遠程訪問test數據庫的權限
Mariadb[(none)]>grant all privileges on *.* to 'pmauser'@'192.168.1.%' identified by 'redhat'; –授予pmauser遠程管理mariadb所有數據庫的權限
五、web-server主機上創建虛擬主機,并設置php轉發過程
#mkdir -pv /var/www/http/{www,wordpress,pma} –創建不同虛擬主機的主目錄
#touch /var/www/http/{www,wordpress,pma}/index.php –創建空的.php文件,提供FastCGI轉發
#vim /etc/httpd/conf.d/virtualhost.conf –創建并編輯針對虛擬主機的配置文件
<VirtualHost *:80> ##測試FastCGI連通性
ServerName www.test.com
DocumentRoot /var/www/http/www
DirectoryIndex index.php
ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.1.200:9000/var/www/html/$1"
</VirtualHost>
<VirtualHost *:80> ##測試phpMyAdmin
ServerName pma.test.com
DocumentRoot /var/www/http/pma
DirectoryIndex index.php
ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.1.200:9000/usr/share/phpMyAdmin/$1"
</VirtualHost>
<VirtualHost *:80> ##測試wordpress
ServerName wordpress.test.com
DocumentRoot /var/www/http/wordpress
DirectoryIndex index.php
ProxyPassMatch "^/(.*\.php)$" "fcgi://192.168.1.200:9000/usr/share/wordpress/$1"
</VirtualHost>
六、驗證虛擬主機訪問
訪問http://pma.test.com/phpmyadmin 虛擬主機
輸入運行數據庫遠程訪問的賬戶信息,打開圖形化管理數據庫的頁面
訪問http://wordpress.test.com 虛擬主機
原創文章,作者:N24_shishen,如若轉載,請注明出處:http://www.www58058.com/69017
對于分開部署,后期學到nginx的時候,也可以多采用這種方式,但是要注意如果是多臺機器如何做負載均衡,負載均衡的策略是怎樣的?
@luoweiro:
好的。有待后期繼續學習新的知識點以后,在來更新。