• LVS(五)LVS集群RealServer高可用健康监测


    RealServer高可用健康监测

     1 #!/bin/bash
     2 #
     3 VIP=192.168.43.200
     4 CPORT=80
     5 FAIL_BACK=127.0.0.1
     6 RS=("192.168.43.202" "192.168.43.203")
     7 declare -a RSSTATUS
     8 RW=("2" "1")
     9 RPORT=80
    10 TYPE=g
    11 CHKLOOP=3
    12 LOG=/var/log/ipvsmonitor.log
    13 
    14 addrs(){
    15  ipvsadm -a -t $VIP:$CPORT -r $1:$RPORT -$TYPE -w $2
    16  [ $? -eq 0 ] && return 0 || return 1    
    17 }
    18 delrs(){
    19  ipvsadm -d -t $VIP:$CPORT -r $1:$RPORT
    20  [ $? -eq 0 ] && return 0 || return 1
    21 }
    22 checkrs(){
    23  local I=1
    24  while [ $I -le $CHKLOOP ]; do
    25   if curl --connect-timeout 1 http://$1 &> /dev/null; then
    26    return 0
    27   fi
    28   let I++
    29  done
    30  return 1
    31 }
    32 initstatus(){
    33  local I
    34  local COUNT=0;
    35  for I in ${RS[*]}; do
    36   if checkrs $I; then
    37    RSSTATUS[$COUNT]=1
    38   else
    39    RSSTATUS[$COUNT]=0
    40   fi
    41  let COUNT++
    42  done
    43 }
    44 initstatus
    45 while :; do
    46  let COUNT=0
    47  for I in ${RS[*]}; do
    48   if checkrs $I; then
    49    if [ ${RSSTATUS[$COUNT]} -eq 0 ]; then
    50     addrs $I ${RW[$COUNT]}
    51     [ $? -eq 0 ] && RSSTATUS[$COUNT]=1 && echo " $I is back." >> $LOG
    52    fi
    53   else
    54    if [ ${RSSTATUS[$COUNT]} -eq 1 ]; then
    55     delrs $I
    56     [ $? -eq 0 ] && RSSTATUS[$COUNT]=0 && echo " $I is gone." >> $LOG
    57    fi
    58   fi
    59   let COUNT++
    60  done
    61  sleep 5
    62 done
  • 相关阅读:
    css3之box-shadow
    css3之圆角
    KOA 学习(九)koa-static
    KOA 学习(八) koa-bodyparser
    KOA 学习(七) 路由koa-router
    videojs使用的常见问题
    KOA 学习(六)superAgent
    KOA 学习(四)
    Ng第五课:Octave 教程(Octave Tutorial)
    Ng第四课:多变量线性回归(Linear Regression with Multiple Variables)
  • 原文地址:https://www.cnblogs.com/Matchman/p/9112464.html
Copyright © 2020-2023  润新知