lvs dr tunl真实机脚本

来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 12:24 点击:

#!/bin/bash
#create lvs dr or tunl realservr scripts.
#chenjian 2011-09-23
 
VIP_LIST="192.168.116.20 192.168.116.21"
USAGE="Usage: $0 {start|stop|status} {dr|tunl}"
NAME=tunl
NUM=0
 
 
if [ -z $1 ]
then
    echo $USAGE 
    exit 2
fi
 
ACTION=`echo $1|tr A-Z a-z`
 
if ! [ $1 == status ]
then
    if [ -z $2 ]
    then
        echo $USAGE
        exit 2
    fi
fi
 
TYPE=`echo $2|tr A-Z a-z`
 
case "$1" in
start)
 
if [ $TYPE == dr ]
then
    if /sbin/ifconfig |grep lo: > /dev/null
    then
        /sbin/ifdown lo
        /sbin/ifup lo
    fi
    for vip in `echo $VIP_LIST`;do
        /sbin/ifconfig lo:$NUM  $vip netmask 255.255.255.255 broadcast $vip
        /sbin/route add -host $vip dev lo:$NUM
        NUM=`echo $[$NUM+1]`
    done
 
    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 "$TYPE RealServer Start [ OK ]"
elif  [ $TYPE == tunl ]
then
    for vip in `echo $VIP_LIST`;do
        if [ $NAME == tunl ]
        then
            NAME=tunl0
            /sbin/ifconfig "$NAME" $vip netmask 255.255.255.255
            /sbin/route add -host $vip dev $NAME
        else
            /sbin/ifconfig "$NAME":"$NUM" $vip netmask 255.255.255.255
            /sbin/route add -host $vip dev $NAME
        fi
        NUM=`echo $[$NUM+1]`
    done
    echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
    echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
    echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_filter
    echo 1 > /proc/sys/net/ipv4/conf/tunl0/forwarding
    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 "$TYPE RealServer Start [ OK ]"
else
    echo $USAGE
    exit 2
fi
;;
stop)
if [ $TYPE == dr ]
then
    for vip in `echo $VIP_LIST`;do
        /sbin/ifconfig lo:$NUM down
        /sbin/route del $vip
&nb

    发表评论
    请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
    用户名: 验证码:点击我更换图片
    最新评论 更多>>

    推荐热点

    • /etc/fstab 详解
    • nginx主主集群
    •  LVS-NAT和LVS-DR模式的实现详解
    •  RHCE考试之磁盘配额
    • 学习笔记:ACL详解
    •  LVM逻辑卷管理器
    • suse linux双网卡双网关配置
    •  Nginx主主负载均衡架构
    • ubuntu学习Mysql

    快速直达

    操作系统导航

    LinuxWindows虚拟机
    网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
    Copyright © 2008-2015 计算机技术学习交流网. 版权所有

    豫ICP备11007008号-1