keepalived 实现服务器级别的接管,比如nginx 宕机了 不会接管,可以写shell 脚本实现,当nginx 挂了,把keepalived 停掉
while true
do
if [ 'ps -ef|grep nginx|grep -v grep|wc -l' -lt 2 ]
then
/etc/init.d/keepalived stop
fi
sleep 5
done

sh check_web.sh &
测试 ,pkill nginx

高可用裂脑问题解决
写脚本判断是否裂脑
vim check_split_brain.sh
while true
do
ping -c 2 -W 3 10.0.0.7 &>/dev/null (ping 两次,超时3秒,ping主节点)
if [ $? -e 0 -a 'ip addr|grep 10.0.0.17|wc -l' -eq 1 ] (ping 通,并且备节点有 vip 等于1,裂脑了)
then
echo "ha is split brain.warning."
else
echo "ha is ok."
fi
sleep 5
done

0.7
/app/nginx/sbin/nginx
/etc/init.d/keepalived start
ip add|grep 10.0.0.17
/etc/init.d/iptables start
0.8
/etc/init.d/iptables start
ip add|grep 10.0.0.17
sh check_split_brain.sh 裂脑了(有两个主机上,有vip 说明裂脑了)

两台防火墙都关掉,就正常了