deci 发表于 2013-12-3 17:22:25

LVS客户端启动脚本

在设置LVS客户端时,如果我们使用手工设置的话会比较麻烦。现在我们直接使用脚本来启动lvs-client就OK了,下面是一个简单的脚本。

VIP地址:10.0.0.230,把文件放到/etc/init.d/目录下,并受于755的权限就可以使用service来启动和停止了,同时也可以使用chkconfig添加为开机启动


#!/bin/bash
#author:luodi   date:2013/11/27
#chkconfig: 2345 80 93
#description:this scriptto start lvs client for the server
#version:1.0
. /etc/init.d/functions
#setting variable
VIP=10.0.0.230
#functions
start(){
    ifconfig | grep $VIP >/dev/null 2>&1
    if [ $? -eq 0 ];then
      action "LVS client programalready start"
      exit 0
    fi
    ifconfig lo:0 $VIP/32 up
    route add -host $VIP eth0
    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
}
stop(){
    ifconfig | grep $VIP >/dev/null 2>&1
    if [ $? -gt 0 ];then
      action "LVS client program already stop"
      exit 1
    fi
    ifconfig lo:0 $VIP/32 down
    route del -host $VIP eth0
    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

}
#loop setting
case $1 in
start)
    start
    if [ $? -eq 0 ];then
      action "LVS client program starting successful" /bin/true
    else
      action "LVS client program starting successful" /bin/false
    fi
;;
stop)
    stop
    if [ $? -eq 0 ];then
      action "LVS client program stoping successful" /bin/true
    else
      action "LVS client program stoping successful" /bin/false
    fi
;;
status)
    ifconfig | grep $VIP >/dev/null 2>&1
    if [ $? -eq 0 ];then
      echo "LVS client program is startd"
    else
      echo "LVS client program is stopd"
    fi
;;
restart)
    stop && { action "LVS client program stoping successful" /bin/true ||
          action "LVS client program stoping failed" /bin/false
      }
    start&& { action "LVS client program starting successful" /bin/true ||
          action "LVS client program starting failed" /bin/false
      }
;;
*)
    echo "Usage:$0 {start|stop|restart|status}"
;;
esac




dryu999 发表于 2013-12-15 22:53:22

过来看看的

yxixi 发表于 2013-12-24 19:40:37

就算没有王子,公主也要依然骄傲的活着。

上海isp 发表于 2013-12-30 14:02:09

不要被所谓的甜言蜜语所迷惑。这世界,很虚伪。
页: [1]
查看完整版本: LVS客户端启动脚本