在Director 上判断Realserver是否还存在的脚本。
以VIP=172.16.10.1
P0RT=80
RIP1=172.16.10.2
RIP2=172.16.10.3
RW1=100
RW2=200 为例。
#!/bin/bash
VIP=172.16.10.1
P0RT=80
RIP1=172.16.10.2
RIP2=172.16.10.3
RW1=100
RW2=200
ADD () {
if [ "$1" = "$RIP1" ];then
ipvsadm -Ln | grep "$RIP1:80"
[ ! $? -eq 0 ] && ipvsadm -a -t $VIP:$PORT -r $RIP1 -g -w RW1
elif [ "$1" = "$RIP2" ];then
ipvsadm -Ln | grep "$RIP2:80"
[ ! $? -eq 0 ] && ipvsadm -a -t $VIP:$PORT -r $RIP2 -g -w RW2
else
exit
fi
}
DELETE () {
if [ "$1" = "$RIP1" ];then
ipvsadm -Ln | grep "$RIP1:80"
[ $? -eq 0 ] && ipvsadm -d -t $VIP:$PORT -r $RIP1
elif [ "$1" = "$RIP2" ]; then
ipvsadm -Ln | grep "$RIP2:80"
[ $? -eq 0 ] && ipvsadm -d -t $VIP:$PORT -r $RIP2
else
exit
}
ipvsadm -Ln | grep "$VIP:$PORT"
RESULAT=$?
until [ $RESULAT -eq 0 ]; do
for IP in {$RIP1,$RIP2}; do
T=`elinks -dump http://$IP/.test.html | grep "OK"`
if [ "$T" = "OK" ]; then
ADD () $IP
else
DELETE () $IP
fi
done
sleep 5
done
呵呵 ,