實(shí)驗(yàn)環(huán)境:
1、centos7.3 centos6.8
2、兩臺(tái)VS提供nginx代理和keepalived
3、兩臺(tái)RS提供httpd服務(wù)并部署wordpress
4、另外一臺(tái)提供Mysql數(shù)據(jù)庫(kù)服務(wù)
實(shí)驗(yàn)拓?fù)鋱D:

實(shí)驗(yàn)步驟
1、在vs1(172.18.251.4)上配置,用yum安裝keepalived和nginx
yum install -y keepalived nginx
2、配置vs1中keepalived配置文件
vim /etc/keepalived/keepalived.com
配置keepalived.com 實(shí)現(xiàn)vs1為主服務(wù)提供VIP:172.18.10.82,vs2為備用的,這里提供vs1主備的配置,vs2上只需要修改:
state BACKUP
priority 98
通過(guò)嵌入腳本獲取nginx的進(jìn)程狀況來(lái)調(diào)整主備的工作模式。
具體配置如下:

通過(guò)寫(xiě)通知腳本發(fā)送郵件給root,具體腳本如下:

3、配置nginx
編輯nginx的配置文件,實(shí)現(xiàn)nginx反向代理功能
vim /etc/nginx/conf/nginx.conf
修改nginx.conf文件

修改nginx下的server配置文件:
vim /etc/nginx/conf.d/defualt.conf
修改配置如下:

修改完畢后,可以檢測(cè)nginx修改是否正確:
nginx -t
nginx
ss -tnl | grep 80
為了防止rs1和rs2訪問(wèn)錯(cuò)誤,可以在vs上安裝httpd服務(wù)操作如下:
yum install -y httpd
vim /var/www/html/index.html
-------index.html--------------
Sorry !
-----------end----------------------
vim /etc/httpd/conf/httpd.conf
---------httpd.conf----------
listen 8080
----------------end-------------------
systemctl start httpd
ss -tnl | grep 8080
vs2(172.18.251.40)和vs1(172.18.251.4)的配置差不多,需要注意的地方以上已經(jīng)說(shuō)明這里就不再?gòu)?fù)述。
4、部署rs中web服務(wù)
在rs1(172.18.250.237)通過(guò)yum安裝httpd等
yum -y httpd php php-mysql
下載wordpress并解壓!
cd /var/www/html
lftp 172.18.0.1
>mget pub/Sources/sources/httpd/wordpress.zip
unzip wordpress.zip
修改httpd的配置文件:
vim /etc/httpd/conf/httpd.conf
----------------httpd.conf----------------------
DocmentRoot /var/www/html/wordpress
<Dirctory /var/www/html/wordpress
----------------------end---------------------------
啟動(dòng)httpd服務(wù):
systemctl start httpd
ss -tnl | grep 80
rs2(172.18.253.233)配置和rs1相同。
5、部署mysql服務(wù)器
通過(guò)yum安裝mysql
yum install mysql -y
service mysql start
注意確保iptables和selinux不影響,以上也是一樣:
iptables -F
setenforce 0
getenforce
進(jìn)入mysql數(shù)據(jù)庫(kù),新建數(shù)據(jù)庫(kù)wpdb,并授權(quán)用戶
mysql
>>CRTEATE DATABASE wpdb;
>> GRANT ALL ON wpdb.* TO 'wpuser'@'172.18.%.%' IDENTIFIED BY 'wppasswd'
6、啟動(dòng)vs服務(wù)器上的keepalived
在vs1和vs2上啟動(dòng)keepalived服務(wù)
systemctl start keepalived
ip a l
此處為了測(cè)試效果,在rs1和rs2新建測(cè)試頁(yè)如下:


7、測(cè)試高可用效果
通過(guò)停止服務(wù)檢測(cè)高可用的效果。
vs1:
systemctl stop nginx
ss -tnl


可以通過(guò)tcpdump命令查看檢測(cè)過(guò)程如下

經(jīng)過(guò)試驗(yàn)可以看出keepalived和nginx調(diào)度后,可實(shí)現(xiàn)高可用
8、通過(guò)網(wǎng)頁(yè)訪問(wèn),配置wordpress