32饿312 发表于 2016-9-26 10:34:35

shell lvs启动脚本


   
# catlvs_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
      routeadd -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:0down
      routedel -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



页: [1]
查看完整版本: shell lvs启动脚本