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 script to 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 program already 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