[root@LVS scripts]# cat lvs_start.sh #!/bin/sh #-------------------------------------------- #Author: Created by zhangyiling 2016-06 #Mail: #Function: This scripts function is lvs start|stop #Version:4.1.2 #--------------------------------------------- . /etc/init.d/functions VIP=192.168.21.11 PORT=80 RIP=( 192.168.21.128 192.168.21.135 ) function start(){ ifconfig eth0:0 $VIP/32 up >/dev/null 2>&1 route add -host $VIP dev eth0 >/dev/null 2>&1 ipvsadm -C ipvsadm --set 30 5 60 ipvsadm -A -t $VIP:80 -s rr -p 20 for ((i=0;i<${#RIP[*]};i++)) do ipvsadm -a -t $VIP:$PORT -r ${RIP[$i]} -g -w 1 done if [ $? -eq 0 ];then action "startting lvs server..." /bin/true else action "lvs server running..." /bin/false fi } function stop(){ ipvsadm -C ifconfig eth0:0 down route del -host $VIP dev eth0 >/dev/null 2>&1 if [ $? -eq 0 ];then action "stopping lvs server..." /bin/true else action "lvs server stoped" /bin/false fi } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 1 >/dev/null 2>&1 echo "]" start ;; *) echo "Usuge: $0 {start|stop|restart}" esac
转载于:https://blog.51cto.com/zhagyilig/1855974