lvs健康状态检查脚本(个人原创)
自己之前搭建lvs的时候,写的脚本,直接把地址改一下就ok#!/bin/bash
#
VIP=192.168.3.3
CPORT=80
FAIL_BACK=127.0.0.1
RS=("192.168.3.7" "192.168.3.8")
RSTATUS=("1" "1")
RW=("2" "1")
RPORT=80
TYPE=g
add() {
ipvsadm -a -t $VIP:$CPORT -r $1:$RPORT -$TYPE -w $2
[ $? -eq 0 ] && return 0 || return 1
}
del() {
ipvsadm -d -t $VIP:$CPORT -r $1:$RPORT
[ $? -eq 0 ] && return 0 || return 1
}
while :; do
let COUNT=0
for I in ${RS}
do
if curl --connect-timeout 1 http://$I &> dev/null;then
if [ ${RSTATUS[$COUNT]} -eq 0 ];then
add $I ${RW[$COUNT]}
[ $? -eq 0 ] && RSTATUS[$COUNT]=1
fi
else
if [ ${RSTATUS[$COUNT]} -eq 1 ];then
del $I
[ $? -eq 0 ] && RSTATUS[$COUNT]=0
fi
fi
let COUNT++
done
sleep 5
done
页:
[1]