keepadlived配置
global_defs {
router_id keep_254
}
vrrp_script check_nginx {
script "/etc/keepalived/scripts/check_nginx.sh"
interval 2
weight 10
}
vrrp_sync_group VG1 {
group {
vip_inter
vip_outer
}
}
vrrp_instance vip_outer {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
check_nginx
}
virtual_ipaddress {
192.168.66.254
}
}
vrrp_instance vip_inter {
state MASTER
interface eth1
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
check_nginx
}
virtual_ipaddress {
200.198.66.254
}
}
nginx检测脚本
#!/bin/bash
A=`ps -C nginx --no-header|wc -l`
if [ $A -eq 0 ];then
/usr/sbin/nginx
sleep 3
if [ `ps -C nginx --no-header|wc -l` -eq 0 ];then
killall keepalived
fi
fi