ITPub博客

首页 > Linux操作系统 > Linux操作系统 > lvs arp抑制脚本

lvs arp抑制脚本

原创 Linux操作系统 作者:wang_0720 时间:2013-11-06 15:39:49 0 删除 编辑
在用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/,如需转载,请注明出处,否则将追究法律责任。

下一篇: Oracle 体系结构图
请登录后发表评论 登录
全部评论

注册时间:2013-11-05

  • 博文量
    111
  • 访问量
    907706