一步一步搭建LVS-DR模型LB集群(三)

在lvs服务器上运行的脚本lvs.sh,绑定VIP地址到LVS-MASTER上,并设定LVS工作模式等

#!/bin/bash
SNS_VIP=192.168.1.108
SNS_RIP1=192.168.1.106
SNS_RIP2=192.168.1.107
./etc/rc.d/init.d/functions
logger $0 called with $1
case "$1" in
     start)
     # set squid vip
     /sbin/ipvsadm-set 30 5 60  
     #表示tcp空闲等待时间为30秒客户端关闭链接等待时间为5秒udp空闲等待为60秒
     /sbin/ifconfig eth0:0 $SNS_VIP broadcast $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP up
     /sbin/route add -host $SNS_VIP dev eth0:0
     /sbin/ipvsadm -A -t $SNS_VIP:80 -s wlc -p 120
     /sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP1:80 -g -w 1
     /sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP2:80 -g -w 1
     touch /var/lock/subsys/ipvsadm >/dev/null 2>&1
    ;;
stop)
     /sbin/ipvsadm -C
     /sbin/ipvsadm -Z
     ifconfig eth0:0 down
     route del $SNS_VIP
     rm -rf /var/lock/subsys/ipvsadm >/dev/null 2>&1
     echo "ipvsadm stoped"
    ;;
status)
     if [ !-e /var/lock/subsys/ipvsadm ];then
         echo "ipvsadm stoped"
         exit 1
     else
         echo "ipvsadm OK"
     fi
    ;;
*)
     echo "Usage: $0 {start|stop|status}"
     exit 1
esac
exit 0

后端Web服务器上执行的realserver.sh,主要作用为:绑定VIP地址,并设定arp抑制

#!/bin/bash
SNS_VIP=192.168.1.108
./etc/rc.d/init.d/functions
case "$1" in
start)
ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
/sbin/route add -host $SNS_VIP dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arpvannounce
sysctl -p >/dev/null 2>&1
echo "RealServer Start OK"
;;
stop)
ifconfig lo:0 down
route del $SNS_VIP >/dev/null 2>&1
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
echo "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0


你可能感兴趣的:(集群,LVS)