• LVS+Keepalived DR模式(附脚本)


    LVS+Keepalived DR模式(附脚本)


    keepalived官方网站:http://www.keepalived.org/

    Keepalived stable tarball


    以keepalived-1.2.13.tar.gz为例

    说明:
    1.配置好本地yum源,编译源码包会依赖相关库文件
    2.把以下脚本和keepalived源码包放在相同目录
    3.添加脚本的可执行权限
    PS:脚本执行完毕后会直接将keepalived通过chkconifg加入开机启动,相关目录如下
    /usr/local/src/keepalived-1.2.13  #keepalived源码解压目录,
    /etc/keepalived/keepalived.conf    #keepalived的主配置文件
    /etc/sysconfig/keepalived    #keepalived附加配置文件
    /usr/sbin/keepalived  #keepalived的二进制文件
    /etc/init.d/keepalived   #keepalived的自启动脚本,下面是截取致/etc/init.d/keepalived前面的部分脚本

    #!/bin/sh
    #
    # Startup script for the Keepalived daemon
    #
    # processname: keepalived
    # pidfile: /var/run/keepalived.pid
    # config: /etc/keepalived/keepalived.conf
    # chkconfig: - 21 79
    # description: Start and stop Keepalived

    # Source function library
    . /etc/rc.d/init.d/functions

    # Source configuration file (we set KEEPALIVED_OPTIONS there)
    . /etc/sysconfig/keepalived


    上面放大标红的部分是chkconfig keepalived on时在/etc/rc.d/rc{2,3,4,5}.d/这4个级别里生成的开机启动和关机停止顺序,也就是会生成如:/etc/rc.d/rc3.d/S21keepalived这个链接以便在3运行级别时在21这个顺序启动keepalived


    我的实验环境如下:
    OS:CentOS6.5 64bit
    两台LVS调度器:
    VIP:192.168.10.100
    主(MASTER,优先级100): 192.168.10.101
    备(BACKUP,优先级80):   192.168.10.102

    查看调度结果,watch -n 1 ipvsadm -L -n

    两台http服务器:
    VIP:192.168.10.100
    RealServer1:192.168.10.11
    RealServer2:192.168.10.12

    客户端:
    CIP:192.168.10.2
    压力测试, ab -n 10000 192.168.10.100/





    下面是脚本源码定义的一些变量,有需要的可心自行修改。
    注意:脚本2,脚本4是直接生成配置文件重启仍然生效,脚本3和脚本5只是当前生效重启后需再次运行。

    #Define E-mail & Smtp_Server    #定义keepalived.conf中global_defs{ }段中的通知邮箱及邮件SMTP服务器地址,为空则保持默认

    Mail1=
    Mail2=
    Mail3=

    Smtp_Server=

    #Define keepalived "MASTER" or "BACKUP"   #定义keepalived的主备和优先级

    State_Flag=MASTER
    State_Flag_Priority=100
    #State_Flag=BACKUP
    #State_Flag_Priority=80

    #Define Virtual Server IP & Listen Port     #定义VIP和监听端口
    VIP1=192.168.10.100
    VIP1_Listen_Port=80
    VIP2=
    VIP2_Listen_Port=

    #Define Real Server IP & Listen Port        #定义RIP和监听端口
    VIP1_RIP1=192.168.10.11
    VIP1_RIP1_Listen_Port=80
    VIP1_RIP2=192.168.10.12
    VIP1_RIP2_Listen_Port=80
    VIP1_RIP3=
    VIP1_RIP3_Listen_Port=

    VIP2_RIP1=
    VIP2_RIP1_Listen_Port=
    VIP2_RIP2=
    VIP2_RIP2_Listen_Port=
    VIP2_RIP3=
    VIP2_RIP3_Listen_Port=

    #Define Weight                            #定义RIP权重
    Weight_VIP1_RIP1=1
    Weight_VIP1_RIP2=2
    Weight_VIP1_RIP3=3
          
    Weight_VIP2_RIP1=
    Weight_VIP2_RIP2=
    Weight_VIP2_RIP3=

    #Define Schedule & Model       #定义调度算法(静态算法rr, wrr, dh, sh;动态算法lc, wlc, sed, nq, lblc, lvlcr)和lvs包转发模型(NAT|DR|TUN),具体的说明请自行man ipvsadm或者man keepalived.conf 以下是man ipvsadm的简单说明:
    three  packet-forwarding methods (NAT, tunneling, and direct routing), and eight loadbalancing algorithms (round robin, weighted round robin,  least-connec-tion,   weighted   least-connection,  locality-based  least-connection, locality-based least-connection with replication,  destination-hashing,and source-hashing).


    Schedule_VIP1=wlc
    Mode_VIP1=DR

    Schedule_VIP2=
    Mode_VIP2=







    脚本1:调度器keepalived安装脚本源码:
    ############################################
    #!/bin/bash
    #To install keepalived automatically
    #Made by liujun,2014/08/15
    ############################################
    #Define system environment PATH
    export PATH=$PATH
    #Source function library
    . /etc/rc.d/init.d/functions

    #Define Keepalived Version
    Keepalived_Version=1.2.13
    Install_Directory=/usr/local/src
    #Install the build-essential
    PACKAGE="kernel-devel gcc openssl-devel popt-devel libnl-devel net-snmp-devel"
    for i in $PACKAGE
    do
        FLAG=$(rpm -qa|grep -w $i)
        if [ "$FLAG" == "" ];then
            yum -y install $i
        else
            echo -e "e[32;1m$ie[0m is installed"
        fi
    done

    echo -e " "
    echo -e "... ... "
    sleep 1
    echo -e "... ... "
    echo -e " "


    #Build and install
    tar -xvf keepalived-$Keepalived_Version.tar.gz -C /usr/local/src
    cd /usr/local/src/keepalived-$Keepalived_Version
    ./configure 
    --prefix=/usr
    --sysconf=/etc
    --with-kernel-dir=/usr/src/kernels/$(uname -r)
    --enable-snmp
    --enable-sha1
    make && make install



    echo -e " "
    echo -e "e[31;1mkeepalivede[0m is e[32;1minstallede[0m"
    echo -e " "

    #Autostart on init 3/5
    #cp $Install_Directory/keepalived-$Keepalived_Version/keepalived/etc/init.d/keepalived.init /etc/rc.d/rc3.d/S99keepalived
    #cp $Install_Directory/keepalived-$Keepalived_Version/keepalived/etc/init.d/keepalived.init /etc/rc.d/rc5.d/S99keepalived
    chkconfig keepalived on
    chkconfig --list keepalived

    ###################################################
    ##########################
    #Build keepalived.conf
    ##########################

    #Define E-mail & Smtp_Server
    Mail1=
    Mail2=
    Mail3=

    Smtp_Server=

    #Define keepalived "MASTER" or "BACKUP"
    State_Flag=MASTER
    State_Flag_Priority=100
    #State_Flag=BACKUP
    #State_Flag_Priority=80

    #Define Virtual Server IP & Listen Port
    VIP1=192.168.10.100
    VIP1_Listen_Port=80
    VIP2=
    VIP2_Listen_Port=

    #Define Real Server IP & Listen Port
    VIP1_RIP1=192.168.10.11
    VIP1_RIP1_Listen_Port=80
    VIP1_RIP2=192.168.10.12
    VIP1_RIP2_Listen_Port=80
    VIP1_RIP3=
    VIP1_RIP3_Listen_Port=

    VIP2_RIP1=
    VIP2_RIP1_Listen_Port=
    VIP2_RIP2=
    VIP2_RIP2_Listen_Port=
    VIP2_RIP3=
    VIP2_RIP3_Listen_Port=

    #Define Weight
    Weight_VIP1_RIP1=1
    Weight_VIP1_RIP2=2
    Weight_VIP1_RIP3=3
          
    Weight_VIP2_RIP1=
    Weight_VIP2_RIP2=
    Weight_VIP2_RIP3=

    #Define Schedule & Model
    Schedule_VIP1=wlc
    Mode_VIP1=DR

    Schedule_VIP2=
    Mode_VIP2=

    mv /etc/keepalived/keepalived.conf{,.bak}
    cat >/etc/keepalived/keepalived.conf <<HERE
    ! Configuration File for keepalived

    global_defs {
       notification_email {
         ${Mail1:-acassen@firewall.loc}
         ${Mail2:-failover@firewall.loc}
         ${Mail3:-sysadmin@firewall.loc}
       }
       notification_email_from Alexandre.Cassen@firewall.loc
       smtp_server ${Smtp_Server:-192.168.200.1}
       smtp_connect_timeout 30
       router_id LVS_DEVEL
    }

    vrrp_instance VI_1 {
        state $State_Flag
        interface eth0
        virtual_router_id 51
        priority $State_Flag_Priority
        advert_int 1
        authentication {
            auth_type PASS
            auth_pass 1111
        }
        virtual_ipaddress {
            $VIP1
            $VIP2
        }
    }

    virtual_server $VIP1 $VIP1_Listen_Port {
        delay_loop 6
        lb_algo $Schedule_VIP1
        lb_kind $Mode_VIP1
        nat_mask 255.255.255.0
        persistence_timeout 50
        protocol TCP

        real_server $VIP1_RIP1 $VIP1_RIP1_Listen_Port {
            weight $Weight_VIP1_RIP1
        TCP_CHECK {
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }
        real_server $VIP1_RIP2 $VIP1_RIP2_Listen_Port {
            weight $Weight_VIP1_RIP2
        TCP_CHECK {
                connect_timeout 3
                nb_get_retry 3
                delay_before_retry 3
            }
        }
       real_server $VIP1_RIP3 $VIP1_RIP3_Listen_Port {
           weight $Weight_VIP1_RIP3
       TCP_CHECK {
               connect_timeout 3
               nb_get_retry 3
               delay_before_retry 3
           }
       }

    }

    !virtual_server $VIP2 $VIP2_Listen_Port {
       delay_loop 6
       lb_algo $Schedule_VIP2
       lb_kind $Mode_VIP2
       nat_mask 255.255.255.0
       persistence_timeout 50
       protocol TCP
    !
       real_server $VIP2_RIP1 $VIP2_RIP1_Listen_Port {
           weight $Weight_VIP2_RIP1
       TCP_CHECK {
               connect_timeout 3
               nb_get_retry 3
               delay_before_retry 3
           }
       }
       real_server $VIP2_RIP2 $VIP2_RIP2_Listen_Port {
           weight $Weight_VIP2_RIP2
       TCP_CHECK {
               connect_timeout 3
               nb_get_retry 3
               delay_before_retry 3
           }
       }
       real_server $VIP2_RIP3 $VIP1_RIP3_Listen_Port {
           weight $Weight_VIP2_RIP3
       TCP_CHECK {
               connect_timeout 3
               nb_get_retry 3
               delay_before_retry 3
           }
       }
    !}

    HERE

    echo -e " "
    /etc/init.d/keepalived start
    sleep 1
    echo -e " "
    /etc/init.d/keepalived restart

    ###################################################





    脚本2:调度器子接口及路由配置脚本(永久生效)

    ############################################
    #!/bin/bash
    #To contribute to lvs_dr
    #Made by liujun,2014/08/11
    ############################################
    #Define system environment PATH
    export PATH=$PATH
    #Source function library
    . /etc/rc.d/init.d/functions

    #Define Variable
    Sysconfig_Dir=/etc/sysconfig/network-scripts
    VIP=192.168.10.100
    Eth=lo
    Eth_Child_Num=0

    #################
    #Define functions
    #################

    network_restart() {
    echo -e "e[31;1mNetworkinge[0m e[32;1mrestarte[0m "
    /etc/init.d/network restart
    }

    start_begin() {
    echo -e "e[31;1mActivinge[0m e[32;1m$Eth:$Eth_Child_Nume[0m "
    sleep 0.5
    echo -e "e[31;1mAddinge[0m route rules to e[32;1m$Eth:$Eth_Child_Nume[0m "
    sleep 0.5
    echo -e "e[31;1mChanginge[0m  e[32;1mkernel argse[0m "
    echo -e "... ..."
    sleep 0.5
    }

    start_end() {
    sleep 0.5
    echo -e " "
    echo -e "ifcfg-e[32;1m$Eth:$Eth_Child_Nume[0m is e[31;1mactived!e[0m $(ifconfig $Eth:$Eth_Child_Num)"
    echo -e "e[31;1mRoute rulese[0m is e[32;1mcreatede[0m $(route -ne|grep $VIP)"
    echo -e "e[31;1mKernel argse[0m has been e[32;1mattached!e[0m $(sysctl -p 2>/dev/null|grep arp_)"
    }

    stop_begin() {
    echo -e "e[31;1mRemovinge[0m route rules from e[32;1m$Eth:$Eth_Child_Nume[0m "
    sleep 0.5
    echo -e "e[31;1mInactivinge[0m  e[32;1m$Eth:$Eth_Child_Nume[0m "
    sleep 0.5
    echo -e "e[31;1mRestoringe[0m  e[32;1mkernel argse[0m "
    echo -e "... ..."
    }

    stop_end() {
    sleep 0.5
    echo -e " "
    echo -e "The e[31;1mroute rulese[0m is e[32;1mremovede[0m "
    echo -e "The ifcfg-e[31;1m$Eth:$Eth_Child_Nume[0m is e[32;1minactivede[0m "
    echo -e "e[31;1mKernel argse[0m has been e[32;1mrestored!e[0m $(sysctl -p >/dev/null 2>&1|grep arp_)"
    sleep 0.5
    }

    status() {
    echo -e " "
    if [ "$(grep net.ipv4.conf.lo.arp_ignore /etc/sysctl.conf)" == "" ];then
        echo -e "ifcfg-e[32;1m$Eth:$Eth_Child_Nume[0m is e[31;1minactived!e[0m "
        echo -e "e[31;1mNo route e[0m to e[32;1m$Eth:$Eth_Child_Nume[0m "
        echo -e "e[31;1mKernel argse[0m is e[32;1mrequired!e[0m "
        else
        echo -e "ifcfg-e[32;1m$Eth:$Eth_Child_Nume[0m is e[31;1mactived!e[0m $(ifconfig $Eth:$Eth_Child_Num)"
        echo -e "e[31;1mRoute rulese[0m is e[32;1mcreatede[0m $(route -ne|grep $VIP)"
        echo -e "e[31;1mKernel argse[0m has been e[32;1mattached!e[0m $(sysctl -p 2>/dev/null|grep arp_)"
    fi

    }


    start() {
    #Build /etc/sysconfig/network-scripts/ifcfg-lo:0
    start_begin

    if ! [ -f $Sysconfig_Dir/ifcfg-$Eth:$Eth_Child_Num ];then
        cat > $Sysconfig_Dir/ifcfg-$Eth:$Eth_Child_Num <<HERE
    DEVICE=$Eth:$Eth_Child_Num
    BOOTPROTO=static
    IPADDR=$VIP
    NETMASK=255.255.255.255
    BROADCAST=$VIP
    NM_CONTROLLED=no
    ONBOOT=yes
    TYPE=Ethernet
    HERE
    fi

    #Build /etc/sysconfig/network-scripts/route-lo:0
    if ! [ -f $Sysconfig_Dir/route-$Eth:$Eth_Child_Num ];then
    cat >$Sysconfig_Dir/route-$Eth:$Eth_Child_Num <<HERE
    $VIP  dev $Eth:$Eth_Child_Num
    HERE
    fi



    #Modify kernel args
    if [ "$(grep net.ipv4.conf.lo.arp_ignore /etc/sysctl.conf)" == "" ];then
    echo "
    net.ipv4.conf.lo.arp_ignore = 1
    net.ipv4.conf.all.arp_ignore = 1
    net.ipv4.conf.lo.arp_announce = 2
    net.ipv4.conf.all.arp_announce = 2">>/etc/sysctl.conf
    fi

    network_restart
    start_end

    }

    stop() {
    stop_begin

    rm -rf $Sysconfig_Dir/ifcfg-$Eth:$Eth_Child_Num >/dev/null 2>&1
    rm -rf $Sysconfig_Dir/route-$Eth:$Eth_Child_Num >/dev/null 2>&1

    sed -i '/net.ipv4.conf.lo.arp_ignore = 1/ d' /etc/sysctl.conf
    sed -i '/net.ipv4.conf.all.arp_ignore = 1/ d' /etc/sysctl.conf
    sed -i '/net.ipv4.conf.lo.arp_announce = 2/ d' /etc/sysctl.conf
    sed -i '/net.ipv4.conf.all.arp_announce = 2/ d' /etc/sysctl.conf

    stop_end
    network_restart
    }


    #How to use

    case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        sleep 1
        echo -e "########################################################"
        echo -e " "
        echo -e "########################################################"
        start
        ;;
    status)
        status
        ;;
       
    *)
        echo -e "e[32;1mUsage:e[0m e[33;1m$0e[0m e[34;1m{start|stop|restart|status}e[0m"
        exit 1
        ;;
    esac
    exit $?



    脚本3:调度器子接口及路由配置脚本(临时生效)
    ############################################
    #!/bin/bash
    #To contribute to lvs_dr
    #Made by liujun,2014/08/11
    ############################################
    #Define system environment PATH
    export PATH=$PATH
    #Source function library
    . /etc/rc.d/init.d/functions

    VIP=192.168.10.100

    #Define  function
    start() {
        ifconfig eth0:0 $VIP netmask 255.255.255.255 broadcast $VIP up
        route add -host $VIP dev eth0:0

        echo -e "Derector e[32;1mstartede[0m"
    }
    stop() {
        route del -host $VIP dev eth0:0
        ifconfig eth0:0 down

        echo -e "Derector e[31;1mstoppede[0m"
    }
    case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        start
        ;;
    *)
        echo -e "e[32;1mUsage:e[0m e[33;1m$0e[0m e[34;1m{start|stop|restart}e[0m"
        exit 1
        ;;
    esac
    exit $?





    脚本4:RealServer子接口,路由配置及内核参数修改脚本(永久生效)

    ############################################
    #!/bin/bash
    #modify kernel args to contribute to lvs_dr
    #Made by liujun,2014/08/11
    ############################################
    #Define system environment PATH
    export PATH=$PATH
    #Source function library
    . /etc/rc.d/init.d/functions

    #Define Variable
    Sysconfig_Dir=/etc/sysconfig/network-scripts
    VIP=192.168.10.100
    Eth=lo
    Eth_Child_Num=0

    #################
    #Define functions
    #################

    network_restart() {
    echo -e "e[31;1mNetworkinge[0m e[32;1mrestarte[0m "
    /etc/init.d/network restart
    }

    start_begin() {
    echo -e "e[31;1mActivinge[0m e[32;1m$Eth:$Eth_Child_Nume[0m "
    sleep 0.5
    echo -e "e[31;1mAddinge[0m route rules to e[32;1m$Eth:$Eth_Child_Nume[0m "
    sleep 0.5
    echo -e "e[31;1mChanginge[0m  e[32;1mkernel argse[0m "
    echo -e "... ..."
    sleep 0.5
    }

    start_end() {
    sleep 0.5
    echo -e " "
    echo -e "ifcfg-e[32;1m$Eth:$Eth_Child_Nume[0m is e[31;1mactived!e[0m $(ifconfig $Eth:$Eth_Child_Num)"
    echo -e "e[31;1mRoute rulese[0m is e[32;1mcreatede[0m $(route -ne|grep $VIP)"
    echo -e "e[31;1mKernel argse[0m has been e[32;1mattached!e[0m $(sysctl -p 2>/dev/null|grep arp_)"
    }

    stop_begin() {
    echo -e "e[31;1mRemovinge[0m route rules from e[32;1m$Eth:$Eth_Child_Nume[0m "
    sleep 0.5
    echo -e "e[31;1mInactivinge[0m  e[32;1m$Eth:$Eth_Child_Nume[0m "
    sleep 0.5
    echo -e "e[31;1mRestoringe[0m  e[32;1mkernel argse[0m "
    echo -e "... ..."
    }

    stop_end() {
    sleep 0.5
    echo -e " "
    echo -e "The e[31;1mroute rulese[0m is e[32;1mremovede[0m "
    echo -e "The ifcfg-e[31;1m$Eth:$Eth_Child_Nume[0m is e[32;1minactivede[0m "
    echo -e "e[31;1mKernel argse[0m has been e[32;1mrestored!e[0m $(sysctl -p >/dev/null 2>&1|grep arp_)"
    sleep 0.5
    }

    status() {
    echo -e " "
    if [ "$(grep net.ipv4.conf.lo.arp_ignore /etc/sysctl.conf)" == "" ];then
        echo -e "ifcfg-e[32;1m$Eth:$Eth_Child_Nume[0m is e[31;1minactived!e[0m "
        echo -e "e[31;1mNo route e[0m to e[32;1m$Eth:$Eth_Child_Nume[0m "
        echo -e "e[31;1mKernel argse[0m is e[32;1mrequired!e[0m "
        else
        echo -e "ifcfg-e[32;1m$Eth:$Eth_Child_Nume[0m is e[31;1mactived!e[0m $(ifconfig $Eth:$Eth_Child_Num)"
        echo -e "e[31;1mRoute rulese[0m is e[32;1mcreatede[0m $(route -ne|grep $VIP)"
        echo -e "e[31;1mKernel argse[0m has been e[32;1mattached!e[0m $(sysctl -p 2>/dev/null|grep arp_)"
    fi

    }


    start() {
    #Build /etc/sysconfig/network-scripts/ifcfg-lo:0
    start_begin

    if ! [ -f $Sysconfig_Dir/ifcfg-$Eth:$Eth_Child_Num ];then
        cat > $Sysconfig_Dir/ifcfg-$Eth:$Eth_Child_Num <<HERE
    DEVICE=$Eth:$Eth_Child_Num
    BOOTPROTO=static
    IPADDR=$VIP
    NETMASK=255.255.255.255
    BROADCAST=$VIP
    NM_CONTROLLED=no
    ONBOOT=yes
    TYPE=Ethernet
    HERE
    fi

    #Build /etc/sysconfig/network-scripts/route-lo:0
    if ! [ -f $Sysconfig_Dir/route-$Eth:$Eth_Child_Num ];then
    cat >$Sysconfig_Dir/route-$Eth:$Eth_Child_Num <<HERE
    $VIP  dev $Eth:$Eth_Child_Num
    HERE
    fi



    #Modify kernel args
    if [ "$(grep net.ipv4.conf.lo.arp_ignore /etc/sysctl.conf)" == "" ];then
    echo "
    net.ipv4.conf.lo.arp_ignore = 1
    net.ipv4.conf.all.arp_ignore = 1
    net.ipv4.conf.lo.arp_announce = 2
    net.ipv4.conf.all.arp_announce = 2">>/etc/sysctl.conf
    fi

    network_restart
    start_end

    }

    stop() {
    stop_begin

    rm -rf $Sysconfig_Dir/ifcfg-$Eth:$Eth_Child_Num >/dev/null 2>&1
    rm -rf $Sysconfig_Dir/route-$Eth:$Eth_Child_Num >/dev/null 2>&1

    sed -i '/net.ipv4.conf.lo.arp_ignore = 1/ d' /etc/sysctl.conf
    sed -i '/net.ipv4.conf.all.arp_ignore = 1/ d' /etc/sysctl.conf
    sed -i '/net.ipv4.conf.lo.arp_announce = 2/ d' /etc/sysctl.conf
    sed -i '/net.ipv4.conf.all.arp_announce = 2/ d' /etc/sysctl.conf

    stop_end
    network_restart
    }


    #How to use

    case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        sleep 1
        echo -e "########################################################"
        echo -e " "
        echo -e "########################################################"
        start
        ;;
    status)
        status
        ;;
       
    *)
        echo -e "e[32;1mUsage:e[0m e[33;1m$0e[0m e[34;1m{start|stop|restart|status}e[0m"
        exit 1
        ;;
    esac
    exit $?



    脚本5:RealServer子接口,路由配置及内核参数修改脚本(临时生效)
    ############################################
    #!/bin/bash
    #modify kernel args to contribute to lvs_dr
    #Made by liujun,2014/08/11
    ############################################
    #Define system environment PATH
    export PATH=$PATH
    #Source function library
    . /etc/rc.d/init.d/functions

    VIP=192.168.10.100

    #Define  function
    start() {
        ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $VIP up >/dev/null 2>&1
        route add -host $VIP dev lo:0 >/dev/null 2>&1
        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
        echo -e "RealServer e[32;1mstartede[0m"
    }
    stop() {
        route del -host $VIP dev lo:0 >/dev/null 2>&1
        ifconfig lo:0 down >/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

        sysctl -p >/dev/null 2>&1
        echo -e "RealServer e[31;1mstoppede[0m"
    }
    case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        stop
        sleep 1
        start
        ;;
    *)
        echo -e "e[32;1mUsage:e[0m e[33;1m$0e[0m e[34;1m{start|stop|restart}e[0m"
        exit 1
        ;;
    esac
    exit $?

  • 相关阅读:
    【数据分析师 Level 1 】17.分类分析
    【数据分析师 Level 1 】16.回归分析
    【数据分析师 Level 1 】15.因子分析
    【数据分析师 Level 1 】14.主成分分析
    2020年年终总结
    【数据分析师 Level 1 】13.数据预处理方法
    【数据分析师 Level 1 】12.数据探索和可视化
    【数据分析师 Level 1 】11.市场调研
    一些关于angular的总结
    Git
  • 原文地址:https://www.cnblogs.com/lixuebin/p/10814530.html
Copyright © 2020-2023  润新知