#!/bin/bash
#
VIP=192.168.0.70
PORT=80
RIP1=192.168.16.7
RIP2=192.168.16.8
RWEIGHT1=1
RWEIGHT2=2
IP_F(){
ipvsadm -Ln | grep "$VIP:$PORT" &> /dev/null
if [ $? -eq 0 ];then
elinks -dump http://$1/index.html &>/dev/null
if [ ! $? -eq 0 ];then
ipvsadm -Ln | grep "$1:$PORT" &> /dev/null
if [ $? -eq 0 ];then
D_F $1
else
return 13
fi
else
ipvsadm -Ln | grep "$1:$PORT" &> /dev/null
if [ ! $? -eq 0 ];then
A_F $1
fi
fi
fi
return 0
}
D_F(){
ipvsadm -d -t $VIP:$PORT -r $1
return 0
}
A_F(){
if [ "$1" == "$RIP1" ];then
ipvsadm -a -t $VIP:$PORT -r $1 -m -w $RWEIGHT1
elif [ "$1" == "$RIP2" ];then
ipvsadm -a -t $VIP:$PORT -r $1 -m -w $RWEIGHT2
fi
return 0
}
ipvsadm -Ln &>/dev/null
RESULAT=$?
until [ ! $RESULAT -eq 0 ]; do
for IP in {$RIP1,$RIP2};do
IP_F $IP
done
sleep 5
done
说明:此小程序仅提供简单的实时监控,缺陷很多,如有不屑者,请绕道!!!! 本文出自 “狼驰草原” 博客,请务必保留此出处http://ykllang.blog.51cto.com/3778268/753362
拥有帝国一切,皆有可能。欢迎访问phome.net |