#!/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 -t $VIP:$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
shell脚本-LVS节点健康检查
未经允许不得转载:极客进化岛 » shell脚本-LVS节点健康检查