监控LVS真实服务器的脚本

1. 脚本内容编写如下

#!/bin/bash
VIP=192.168.153.188
rs=(192.168.153.136 192.168.153.137)
while :
do
for i in ${rs[*]}
do
    exist_num=$(ipvsadm -Ln | grep -c $i)
    status_code=$(curl -sI -o /dev/null -w %{
     
     http_code} http://$i/index.html)
    if [ $status_code -ne 200 -a $exist_num -eq 1 ];then
        echo "正在将$i从调度表中删除"
        ipvsadm -d -t $VIP:80  -r $i:80
    elif [ $status_code -eq 200 -a $exist_num -eq 0 ];then
        echo "正在添加 $i 到调度表中"
        ipvsadm -a -t $VIP:80  -r $i:80 -g
    fi
    done
    sleep 1
done

2. 执行测试脚本

[root@host-135 ~]# sh check_lvs.sh 
正在将192.168.153.137从调度表中删除
正在将192.168.153.136从调度表中删除
正在添加 192.168.153.136 到调度表中
正在添加 192.168.153.137 到调度表中
^C

猜你喜欢

转载自blog.csdn.net/m0_46674735/article/details/112628601
今日推荐