#!/bin/bash
VIP=202.106.195.1
PORT=80
RIP=(192.168.100.10 192.168.100.20)
while true
do
for ((i=0;i<`echo {#RIP[*]}`;i++))
do
code=`curl -I -m 10 -o /dev/null -s -w %{http_code} http://{RIP[i]}`
if [code -ne 200 -a (ipvsadm -Ln|grep{RIP[i]}|wc -l) -eq 1 ]
then ipvsadm -d -tVIP:PORT -r{RIP[i]}:PORT
elif [ code -eq 200 -a(ipvsadm -Ln|grep {RIP[i]}|wc -l) -lt 1 ]
then ipvsadm -a -t VIP:PORT -r {RIP[i]}:PORT
fi
done
sleep 5
done
keepalived 监控服务
#!/bin/bash
while true
do
if [(pidof httpd|wc -l) -eq 1 -a (pidof keepalived|wc -l) -eq 0 ]
then systemctl start keepalived
fi
pidof httpd &>/dev/null
if [? -ne 0 ]
then systemctl start httpd &>/dev/null
fi
sleep 3
pidof httpd &>/dev/null
if [ $? -ne 0 ]
then systemctl stop keepalived
fi
sleep 3
done
本文链接:http://www.geekyunwei.com/1848.html
网友评论comments