发布时间:2014-09-05 16:53:19作者:知识屋
#!/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
NUM=`echo $[$NUM+1]`
done
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 "$TYPE RealServer Stop [ OK ]"
elif [ $TYPE == tunl ]
then
/sbin/ifconfig tunl0 down
echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_filter
echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
else
echo $USAGE
exit 2
fi
;;
status)
if /sbin/ifconfig |grep -q 'lo:'
then
TYPE=dr
elif /sbin/ifconfig |grep -q 'tunl'
then
TYPE=tunl
else
exit 2
fi
for vip in `echo $VIP_LIST`;do
if [ ! `/sbin/ifconfig |grep -q $vip` -o ! `netstat -rn |grep $vip` ];
then
echo "LVS-$TYPE real server stopped,vip = $vip"
else
echo "LVS-$TYPE Running,vip = $vip"
fi
done
;;
*)
echo "$USAGE"
exit 1
;;
esac
作者“If one day”
linux一键安装web环境全攻略 在linux系统中怎么一键安装web环境方法
Linux网络基本网络配置方法介绍 如何配置Linux系统的网络方法
Linux下DNS服务器搭建详解 Linux下搭建DNS服务器和配置文件
对Linux进行详细的性能监控的方法 Linux 系统性能监控命令详解
linux系统root密码忘了怎么办 linux忘记root密码后找回密码的方法
Linux基本命令有哪些 Linux系统常用操作命令有哪些
Linux必学的网络操作命令 linux网络操作相关命令汇总
linux系统从入侵到提权的详细过程 linux入侵提权服务器方法技巧
linux系统怎么用命令切换用户登录 Linux切换用户的命令是什么
在linux中添加普通新用户登录 如何在Linux中添加一个新的用户
2012-07-10
CentOS 6.3安装(详细图解教程)
Linux怎么查看网卡驱动?Linux下查看网卡的驱动程序
centos修改主机名命令
Ubuntu或UbuntuKyKin14.04Unity桌面风格与Gnome桌面风格的切换
FEDORA 17中设置TIGERVNC远程访问
StartOS 5.0相关介绍,新型的Linux系统!
解决vSphere Client登录linux版vCenter失败
LINUX最新提权 Exploits Linux Kernel <= 2.6.37
nginx在网站中的7层转发功能