脚本示例:
#!/bin/bash ### BEGIN INIT INFO # Provides: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start realserver # Description: Start realserver ### END INIT INFO # change the VIP to proper value VIP=10.65.32.28 case "$1" in start) # Start of LVS-DR real server echo "Start Real Server" /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up 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) # Stop of LVS-DR real server /sbin/ifconfig lo:0 down echo "Stop Real Server" 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) # Status of LVS-DR real server islothere=`/sbin/ifconfig lo:0 | grep $VIP` isrothere=`netstat -rn | grep "lo:0" | grep $VIP` # Either the route or the lo:0 device if [ ! "$islothere" -o ! "isrothere" ];then echo "LVS-DR real server Stopped." else echo "LVS-DR real server Running." fi ;; restart) # Restart of LVS-DR real server echo "Restart Real Server" $0 stop $0 start ;; *) echo "Usage: $0 {start|stop|restart|status}" exit 1 ;; esac exit 0