#MASTER
cat > /etc/keepalived/keepalived.conf <
vrrp_script chk_http_port {
script "/opt/sh/chk_nginx.sh"
interval 5
weight 2
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
authentication {
auth_type PASS
auth_pass anniesb
}
track_script {
chk_http_port
}
virtual_ipaddress {
192.168.39.88
}
}
EOF
#SLAVER
cat > /etc/keepalived/keepalived.conf <
vrrp_script chk_http_port {
script "/opt/sh/chk_nginx.sh"
interval 5
weight 2
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 50
authentication {
auth_type PASS
auth_pass anniesb
}
track_script {
chk_http_port
}
virtual_ipaddress {
192.168.39.88
}
}
EOF
cat > /opt/sh/chk_nginx.sh <
#/bin/bash
if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
sudo /etc/init.d/nginx start
sleep 2
if [ `ps -C nginx --no-header |wc -l` -eq 0 ];then
sudo /etc/init.d/keepalived stop
fi
fi
exit 0
EOF
sudo chmod 755 /opt/sh/chk_nginx.sh
阅读(1056) | 评论(0) | 转发(1) |