RealServer脚本

#!/bin/bash  
#   
# 描述: LVS DR模型真实服务器配置
#
.  /etc/rc.d/init.d/functions
VIP=192.168.168.100
case "$1" in  
start)        /sbin/ifconfig lo:3 $VIP netmask 255.255.255.255
        echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore   
        echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore   
        echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce   
        echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
        
;;  
stop)     /sbin/ifconfig lo:3 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
;;  
status)
        islothere=`/sbin/ifconfig lo:3 | grep $VIP`   
        isrothere=`netstat -rn | grep "lo:3" | grep $VIP`   
        if [ ! "$islothere" -o ! "isrothere" ];then 
            echo "LVS-DR real server Stopped."   
        else   
            echo "LVS-DR real server Running."   
        fi   
;;   
*)   
            echo "$0: Usage: $0 {start|status|stop}"   
            exit 1   
;;   
esac

注:脚本如果是在window上编辑过后上传至linux的,需要做如下操作:

vim打开该sh文件,输入:
:set ff 
回车,显示fileformat=dos,重新设置下文件格式:
:set ff=unix 

保存退出: 
:wq

否则会出现No such file or directory问题

相关推荐