lvs启动脚本
LVS_DR 脚本
- #!/bin/sh
- #
- # lvs Start lvs
- #
- # chkconfig: 2345 08 92
- # description: Starts, stops and saves lvs
- #
- SNS_VIP=192.168.16.200
- SNS_RIP1=192.168.10.253
- SNS_RIP2=192.168.10.254
- . /etc/rc.d/init.d/functions
- #logger $0 called with $1
- retval=0
- start()
- {
- #set squid vip
- /sbin/ipvsadm --set 30 5 60
- /sbin/ifconfig eth0:0 $SNS_VIP broadcast $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP up
- /sbin/route add -host $SNS_VIP dev eth0:0
- /sbin/ipvsadm -A -t $SNS_VIP:80 -s wlc -p 120
- /sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP1:80 -g -w 1
- /sbin/ipvsadm -a -t $SNS_VIP:80 -r $SNS_RIP2:80 -g -w 1
- touch /var/lock/subsys/ipvsadm > /dev/null 2 >&1
- echo "ipvsadm started"
- }
- stop()
- {
- /sbin/ipvsadm -C
- /sbin/ipvsadm -Z
- ifconfig eth0:0 down
- route del $SNS_VIP
- rm -rf /var/lock/subsys/ipvsadm > /dev/null 2 >&1
- echo "ipvsadm stoped"
- }
- status()
- {
- if [ ! -e /var/lock/subsys/ipvsadm ];then
- echo "ipvsadm stoped"
- exit 1
- else
- echo "ipvsadm OK"
- fi
- }
- case "$1" in
- start)
- start
- ;;
- stop)
- stop
- ;;
-
- status)
- status
-
;;
restart) - stop
- start
- ;;
用service命令启动该脚本
-
[root@localhost]# vim /etc/rc.d/init.d/lvs 输入上面的脚本内容(具体参数需要自己更改),保存
-
[root@localhost]# chmod 755 /etc/rc.d/init.d/lvs
-
[root@localhost]# service lvs start
- ipvsadm started
- [root@localhost]# service lvs status
- ipvsadm OK
- [root@localhost]# service lvs restart
- ipvsadm stoped
- ipvsadm started
- [root@localhost]# service lvs stop
- ipvsadm stoped
使用chkconfig把lvs脚本添加到开机自启动项
- [root@localhost ]chkconfig --add lvs
- [root@localhost ]chkconfig --level 2345 lvs on
- [root@localhost ]chkconfig --list lvs
- lvs 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
在这个步骤的时候,遇到过一些麻烦,现问题已经解决,需要注意的是脚本中以下代码不能有错误,不然可能会遇到添加不上的情况,
- #!/bin/sh
- #
- # lvs Start lvs
- #
- # chkconfig: 2345 08 92
- # description: Starts, stops and saves lvs
- #
chkconfig的相关知识,附链接,有兴趣的可参考
http://shhyang.blog.51cto.com/714134/207055
http://wenku.baidu.com/view/9bbc7b6448d7c1c708a145de.html
LVS_RealServer 脚本
- #!/bin/bash
- SNS_VIP=192.168.16.200
- . /etc/rc.d/init.d/functions
- case "$1" in
- start)
- ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
- /sbin/route add -host $SNS_VIP dev lo:0
- 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
- echo "RealServer Start Ok"
- ;;
- stop)
- ifconfig lo:0 down
- route del $LVS_VIP >/dev/null 2 >&1
- 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
- echo "RealServer Stoped"
- ;;
- *)
- echo "Usage: $0 {start|stop}"
- exit 1
- esac
本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/744237,如需转载请自行联系原作者