Nginx-S上面也要配置跟Nginx-M上面同樣的Nginx代理服務配置node
Nginx-M和Nginx-S的keepalived服務配置:nginx
配置文件模板:bash
! Configuration File for keepalived服務器
global_defs {網絡
notification_email {ide
}代理
notification_email_from ops@wangshibo.cnrest
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id master-node
}
vrrp_script chk_http_port {
script "/opt/chk_nginx.sh"
interval 2
weight -5
fall 2
rise 1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
mcast_src_ip 192.168.115.173
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.115.100
}
track_script {
chk_http_port
}
}
此監控腳本Nginx-S服務器上面也須要:
腳本模板:
#!/bin/bash
counter=$(ps -C nginx --no-heading|wc -l)
if [ "${counter}" = "0" ]; then
service nginx restart
sleep 2
counter=$(ps -C nginx --no-heading|wc -l)
if [ "${counter}" = "0" ]; then
service keepalived stop
fi
fi
WEB服務器上面只須要搭建Apache服務便可,不須要作其餘的網絡設置
將Nginx-M和Nginx-S服務器上面的keepalived和Nginx服務開啓,再將/opt/下面的監控腳本執行,以後停掉任何一臺Nginx代理服務器查看效果驗證是否一臺Nginx代理服務器宕機的狀況下,另外一臺繼續工做