lvs arp抑制指令碼

wang_0720發表於2013-11-06
在用lvs做負載均衡時,後端真實伺服器要進行arp抑制,將一些命令寫在多個不同的地方往往不方便管理,本文將所有的命令集中在一個指令碼,開機後自啟動,即可完成arp抑制,vip繫結等工作
#!/bin/bash
#chkconfig:345 20 80
#description: lvs real server
VIP=192.168.2.173
host=`/bin/hostname`
case "$1" in
                start)
                        #start lvs
                        /sbin/ifconfig lo down
                        /sbin/ifconfig lo up
                        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/arp_announce
                        sysctl -p > /dev/null 2>&1
                        /sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 up
                        /sbin/route add -host $VIP dev lo:0
                        ;;
                stop)
                        #stop lvs
                        /sbin/ifconfig lo:0 down
                        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
                        sysctl -p > /dev/null 2>&1
                        ;;
                status)
                        #status of lvs
                        islothere=`/sbin/ifconfig lo:0 |grep $VIP`
                        isrothere=`/netstat -rn |grep "lo" |grep "$VIP"`
                        if [ ! "islothere" -o ! "isrothere" ];then
                                        echo "the realserver is stopped"
                                else
                                        echo "realserver is running"
                        fi
                        ;;
                *)
                        echo "Usage:$0{start|stop|status}"
                exit 1
esac

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-775882/,如需轉載,請註明出處,否則將追究法律責任。

相關文章