본문 바로가기
Programing/shell programing

lvs자동 설정 쉘스크립트

lvs자동 설정 쉘스크립트

#!/bin/sh
####################################
#
# File name  : lvs.sh
# Date       : 2013/03/27 16:44:57
# Written by : ycy (ycy@j2.co.kr)
#
#####################################

stty erase "^H"
echo -n "Insert lvs server ip : "
read S_IP

echo -n "Insert lvs server port : "
read S_PORT

echo -n "Insert lvs scheduler  [ rr | lc | wrr | wlc ] : "
read S_SC

if [ $S_SC = "rr" ]; then

          S_SC2="Robin Robin"

          elif [ $S_SC = "wrr" ]; then

                   S_SC2="Weighted Round Robin"

          elif [ $S_SC = "lc" ]; then

                   S_SC2="Least-Connection"

          elif [ $S_SC = "wlc" ]; then

                   S_SC2="Weighted Least-Connection"

          else

          echo "bad scheduler"
          exit 1;

fi

echo ""
echo "==========================================="
echo ""
echo " lvs server ip   : " $S_IP
echo " lvs server port : " $S_PORT
echo " lvs scheduler   : " $S_SC2
echo ""
echo "==========================================="


echo -n "Add virtual service? [y|n] : "
read ADD

if [ $ADD == "y" ]; then
          ipvsadm -A -t $S_IP:$S_PORT -s $S_SC
                   elif [ $ADD == "n" ]; then
                             exit 1;
fi


echo ""
echo ""
while true
do
          echo -n "Add host ? [y|n] :"
          read ADDH
                   if [ $ADDH == "y" ]; then
                             echo -n "Insert host ip : "
                             read HIP

                             echo -n "Insert host port : "
                             read HPORT
                   
                             if [ $S_SC = wrr -o $S_SC = wlc ];then
                                      echo -n "Insert weigh : "
                                      read HWEIGH
                                      
                                      echo ""
                                      echo "==========================================="
                                      echo ""
                                      echo " host ip      : " $HIP
                                      echo " host port    : " $HPORT
                                      echo " host weigh   : " $HWEIGH
                                      echo ""
                                      echo "==========================================="                         
                                      
                                      echo -n "Add virtual service? [y|n] : "
                                      read ADD

                                      if [ $ADD == "y" ];then
                                                ipvsadm -a -w $HWEIGH -t $S_IP:$S_PORT -r $HIP:$HPORT -m
                                      else
                                                continue
                                      fi
                                      
                                      else
                             
                                echo ""
                                echo "==========================================="
                                echo ""
                                echo " host ip      : " $HIP
                                echo " host port    : " $HPORT
                                echo ""
                                echo "==========================================="                     

                                echo -n "Add virtual service? [y|n] : "
                                read ADD

                                if [ $ADD == "y" ];then
                                        ipvsadm -a -t $S_IP:$S_PORT -r $HIP:$HPORT -m
                                else
                                        continue
                                fi 

                             fi
                                      
                   elif [ $ADDH == "n" ]; then
                             ipvsadm -L
                             exit 1;
                   fi        
done
  


반응형

'Programing > shell programing' 카테고리의 다른 글

TC를 이용한 인터페이스 QOS  (0) 2016.02.10
pptp vpn connection kill  (0) 2016.02.10
배너 스크립트  (0) 2016.02.10
unknown ip 확인 스크립트  (0) 2016.02.10
1. 쉘프로그래밍 파일의 실행과 생성  (0) 2013.06.12