實驗環(huán)境:
1、centos7.3 centos6.8
2缴守、兩臺VS提供nginx代理和keepalived
3囚衔、兩臺RS提供httpd服務并部署wordpress
4、另外一臺提供Mysql數(shù)據(jù)庫服務
實驗拓撲圖:
實驗步驟
1匙赞、在vs1(172.18.251.4)上配置佛掖,用yum安裝keepalived和nginx
yum install -y keepalived nginx
2妖碉、配置vs1中keepalived配置文件
vim /etc/keepalived/keepalived.com
配置keepalived.com 實現(xiàn)vs1為主服務提供VIP:172.18.10.82,vs2為備用的芥被,這里提供vs1主備的配置欧宜,vs2上只需要修改:
state BACKUP
priority 98
通過嵌入腳本獲取nginx的進程狀況來調(diào)整主備的工作模式。
具體配置如下:
通過寫通知腳本發(fā)送郵件給root拴魄,具體腳本如下:
3冗茸、配置nginx
編輯nginx的配置文件,實現(xiàn)nginx反向代理功能
vim /etc/nginx/conf/nginx.conf
修改nginx.conf文件
修改nginx下的server配置文件:
vim /etc/nginx/conf.d/defualt.conf
修改配置如下:
修改完畢后匹中,可以檢測nginx修改是否正確:
nginx -t
nginx
ss -tnl | grep 80
為了防止rs1和rs2訪問錯誤夏漱,可以在vs上安裝httpd服務操作如下:
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)說明這里就不再復述职员。
4麻蹋、部署rs中web服務
在rs1(172.18.250.237)通過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---------------------------
啟動httpd服務:
systemctl start httpd
ss -tnl | grep 80
rs2(172.18.253.233)配置和rs1相同焊切。
5扮授、部署mysql服務器
通過yum安裝mysql
yum install mysql -y
service mysql start
注意確保iptables和selinux不影響,以上也是一樣:
iptables -F
setenforce 0
getenforce
進入mysql數(shù)據(jù)庫专肪,新建數(shù)據(jù)庫wpdb刹勃,并授權用戶
mysql
>>CRTEATE DATABASE wpdb;
>> GRANT ALL ON wpdb.* TO 'wpuser'@'172.18.%.%' IDENTIFIED BY 'wppasswd'
6、啟動vs服務器上的keepalived
在vs1和vs2上啟動keepalived服務
systemctl start keepalived
ip a l
此處為了測試效果嚎尤,在rs1和rs2新建測試頁如下:
7荔仁、測試高可用效果
通過停止服務檢測高可用的效果。
vs1:
systemctl stop nginx
ss -tnl
可以通過tcpdump命令查看檢測過程如下
經(jīng)過試驗可以看出keepalived和nginx調(diào)度后芽死,可實現(xiàn)高可用
8乏梁、通過網(wǎng)頁訪問,配置wordpress