director机器上
cat ipv-director.sh
#!/bin/bash
#set -x
vip=192.168.222.250
rip1=192.168.222.129
rip2=192.168.222.130
port=80
/sbin/ifconfig | grep eth0:1 > /dev/null
if [ $? -eq 0 ]
then
/sbin/route del $vip
/sbin/ifconfig eth0:1 down
fi
start() {
/sbin/ifconfig eth0:1 $vip broadcast $vip netmask 255.255.255.255 up
/sbin/route add -host $vip dev eth0:1
/bin/echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -F
/sbin/ipvsadm -C
/sbin/ipvsadm -A -t ${vip}:${port} -s wrr
/sbin/ipvsadm -a -t ${vip}:${port} -r $rip1 -g -w 1
/sbin/ipvsadm -a -t ${vip}:${port} -r $rip2 -g -w 2
/sbin/ipvsadm
}
stop () {
/bin/echo 0 > /proc/sys/net/ipv4/ip_forward
/sbin/ipvsadm -C
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo "usage:$0 {start|stop|status}"
;;
esac
realserver机器上
cat lvs-realserver.sh
#!/bin/bash
#set -x
vip=192.168.222.250
/sbin/ifconfig | grep lo:0 > /dev/null
if [ $? -eq 0 ]
then
/sbin/route del $vip
/sbin/ifconfig lo:0 down
fi
start() {
/bin/echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
/bin/echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
/bin/echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
/bin/echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
/sbin/ifconfig lo:0 $vip broadcast $vip netmask 255.255.255.255 up
/sbin/route add -host $vip dev lo:0
}
stop() {
/bin/echo 0 > /proc/sys/net/ipv4/conf/lo/arp_ignore
/bin/echo 0 > /proc/sys/net/ipv4/conf/lo/arp_announce
/bin/echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
/bin/echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
}
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo "usage:$0 {start|stop|status}"
;;
esac
阅读(1895) | 评论(0) | 转发(0) |