LVS两种工作格局测量检验脚本,tunl真实机脚本

作者: 操作系统  发布:2019-09-06

#!/bin/bash
#create lvs dr or tunl realservr scripts.
#chenjian 2011-09-23
 
VIP_LIST="192.168.116.20 192.168.116.21"
USAGE="Usage: $0 {start|stop|status} {dr|tunl}"
NAME=tunl
NUM=0
 
 
if [ -z $1 ]
then
    echo $USAGE 
    exit 2
fi
 
ACTION=`echo $1|tr A-Z a-z`
 
if ! [ $1 == status ]
then
    if [ -z $2 ]
    then
        echo $USAGE
        exit 2
    fi
fi
 
TYPE=`echo $2|tr A-Z a-z`
 
case "$1" in
start)
 
if [ $TYPE == dr ]
then
    if /sbin/ifconfig |grep lo: > /dev/null
    then
        /sbin/ifdown lo
        /sbin/ifup lo
    fi
    for vip in `echo $VIP_LIST`;do
        /sbin/ifconfig lo:$NUM  $vip netmask 255.255.255.255 broadcast $vip
        /sbin/route add -host $vip dev lo:$NUM
        NUM=`echo $[$NUM+1]`
    done
 
    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 
    sysctl -p >/dev/null 2>&1 
    echo "$TYPE RealServer Start [ OK ]"
elif  [ $TYPE == tunl ]
then
    for vip in `echo $VIP_LIST`;do
        if [ $NAME == tunl ]
        then
            NAME=tunl0
            /sbin/ifconfig "$NAME" $vip netmask 255.255.255.255
            /sbin/route add -host $vip dev $NAME
        else
            /sbin/ifconfig "$NAME":"$NUM" $vip netmask 255.255.255.255
            /sbin/route add -host $vip dev $NAME
        fi
        NUM=`echo $[$NUM+1]`
    done
    echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
    echo 2 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
    echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_filter
    echo 1 > /proc/sys/net/ipv4/conf/tunl0/forwarding
    echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
    echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
 
    sysctl -p >/dev/null 2>&1 
    echo "$TYPE RealServer Start [ OK ]"
else
    echo $USAGE
    exit 2
fi
;;
stop)
if [ $TYPE == dr ]
then
    for vip in `echo $VIP_LIST`;do
        /sbin/ifconfig lo:$NUM down
        /sbin/route del $vip
        NUM=`echo $[$NUM+1]`
    done
    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 
 
    sysctl -p >/dev/null 2>&1 
    echo "$TYPE RealServer Stop [ OK ]"
elif  [ $TYPE == tunl ]
then
        /sbin/ifconfig tunl0 down
 
        echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_ignore
        echo 0 > /proc/sys/net/ipv4/conf/tunl0/arp_announce
        echo 1 > /proc/sys/net/ipv4/conf/tunl0/arp_filter
        echo 0 > /proc/sys/net/ipv4/conf/all/arp_ignore
        echo 0 > /proc/sys/net/ipv4/conf/all/arp_announce
 
else
    echo $USAGE
    exit 2
fi
;;
status)
if /sbin/ifconfig |grep -q 'lo:'
then
    TYPE=dr
elif /sbin/ifconfig |grep -q 'tunl'
then
    TYPE=tunl
else
    exit 2
fi
    
for vip in `echo $VIP_LIST`;do
 
    if [ ! `/sbin/ifconfig |grep -q $vip` -o ! `netstat -rn |grep $vip` ];
    then
        echo "LVS-$TYPE real server stopped,vip = $vip"
    else 
        echo "LVS-$TYPE Running,vip = $vip"
    fi
done
 
;;
*)
echo "$USAGE"
exit 1
;;
esac 
 
作者“If one day”

LVS二种工作形式测量检验脚本

#create lvs dr or tunl realservr scripts. #chenjian 2011-09-23 VIP_LIST=192.168.116.20 192.168.116.21 USAGE=Usage: $0 {start|stop|status} {dr|tunl} NAME=tunl NUM=0 if [...

 

001

  1. NAT:

002

#!/bin/bash

003

VIP=192.168.0.111

004

RIP1=10.0.0.10

005

RIP2=10.0.0.20

006

case "$1" in

007

start)

008

           echo "start LVS of DirectorServer NAT"

009

           echo "1" >/proc/sys/net/ipv4/ip_forward

010

           /sbin/ipvsadm -C

011

           /sbin/ifconfig eth0:0 $VIP netmask 255.255.255.0 up

012

           /sbin/ipvsadm -A -t $VIP:80 -s rr

013

           /sbin/ipvsadm -a -t $VIP:80 -r $RIP1 -m

014

           /sbin/ipvsadm -a -t $VIP:80 -r $RIP2 -m

015

           /sbin/ipvsadm

016

       ;;

017

stop)

018

           echo "stop LVS of DirectorServer NAT"

019

           echo "0" >/proc/sys/net/ipv4/ip_forward

020

           /sbin/ipvsadm -C

021

           /sbin/ifconfig eth0:0 down

022

           ;;

023

*)

024

          echo "Usage: $0 {start|stop}"

025

          exit 1

026

esac

027

 

028

 

029

2.DR

030

  server:

031

#!/bin/bash

032

VIP=10.0.0.111

033

RIP1=10.0.0.20

034

RIP2=10.0.0.10

035

. /etc/rc.d/init.d/functions

036

 

037

case "$1" in

038

    start)

039

         echo "start LVS of DirectorServer DR"

040

         /sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up

041

         /sbin/route add -host $VIP dev eth0:0

042

         echo "1">/proc/sys/net/ipv4/ip_forward

043

         /sbin/ipvsadm -C

044

         /sbin/ipvsadm -A -t $VIP:80 -s rr

045

         /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g

046

         /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g

047

         /sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -g

048

         /sbin/ipvsadm

049

         ;;

050

 

051

     stop)

052

         echo "stop LVS of DierctorServer DR"

053

         echo "0">/proc/sys/net/ipv4/ip_forward

054

         /sbin/ipvsadm -C

055

         /sbin/ifconfig eth0:0 down

056

         ;;

057

 

058

       *)

059

         echo "Usage:$0{start|stop}"

060

         exit 1

061

esac

062

 

063

 

064

 

065

   real server:

066

#!/bin/bash

067

VIP=10.0.0.111

068

. /etc/rc.d/init.d/functions

069

 

070

case "$1" in

071

   start)

072

     echo "start LVS of RealServer DR"

073

     /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up

074

     /sbin/route add -host $VIP dev lo:0

075

     echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore

076

     echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce

077

     echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore

078

     echo "2">/proc/sys/net/ipv4/conf/all/arp_announce

079

     ;;

080

     

081

   stop)

082

     /sbin/ifconfig lo:0 down

083

     echo "close LVS of RealServer DR"

084

     echo "0">/proc/sys/net/ipv4/conf/lo/arp_ignore

085

     echo "0">/proc/sys/net/ipv4/conf/lo/arp_announce

086

     echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore

087

     echo "0">/proc/sys/net/ipv4/conf/all/arp_announce

088

     ;;

089

 

090

    *)

091

      echo "Usage:$0{start|stop}"

092

             exit 1

093

esac    

094

 

095

 

096

3.TUN

097

  server:

098

#!/bin/bash

099

VIP=192.168.0.111

100

RIP1=192.168.0.13

101

RIP2=192.168.0.17

102

. /etc/init.d/functions

103

case "$1" in

104

start)

105

           echo "start LVS of DirectorServer Tun"

106

           /sbin/ifconfig tunl0 $VIP  netmask 255.255.255.255 up

107

           /sbin/route add -host $VIP dev tunl0

108

         #  echo "0" >/proc/sys/net/ipv4/ip_forward

109

         #  echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects  

110

         #  echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects

111

         #  echo "1" >/proc/sys/net/ipv4/conf/eth1/send_redirects

112

           /sbin/ipvsadm -C

113

           /sbin/ipvsadm -A -t $VIP:80 -s rr

114

           /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -i

115

           /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i

116

           /sbin/ipvsadm

117

       ;;

118

stop)

119

           echo "stop LVS of DirectorServer Tun"

120

           /sbin/ifconfig tunl0 down

121

           /sbin/ipvsadm -C

122

           ;;

123

*)

124

          echo "Usage: $0 {start|stop}"

125

          exit 1

126

esac

127

 

128

   real server:

129

#!/bin/bash

130

VIP=192.168.0.111

131

. /etc/init.d/functions

132

case "$1" in

133

start)

134

           echo "start LVS of RealServer Tun"

135

           /sbin/ifconfig tunl0 $VIP  netmask 255.255.255.255 up

136

           /sbin/route add -host $VIP dev tunl0

137

           echo "1" >/proc/sys/net/ipv4/conf/tunl0/arp_ignore

138

           echo "2" >/proc/sys/net/ipv4/conf/tunl0/arp_announce

139

           echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore

140

           echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

141

           echo 0 > /proc/sys/net/ipv4/ip_forward

142

           echo 0 > /proc/sys/net/ipv4/conf/tunl0/rp_filter

143

           echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter

144

       ;;

145

stop)

146

           echo "close LVS of RealServer Tun"

147

           /sbin/ifconfig tunl0 down

148

           echo "0" >/proc/sys/net/ipv4/conf/tunl0/arp_ignore

149

           echo "0" >/proc/sys/net/ipv4/conf/tunl0/arp_announce

150

           echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore

151

           echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce

152

           ;;

153

*)

154

          echo "Usage: $0 {start|stop}"

155

          exit 1

156

esac

157

exit 0

 

001 1. NAT: 002 #!/bin/bash 003 VIP=192.168.0.111 004 RIP1=10.0.0.10 005 RIP2=10.0.0.20 006 case $1 in 007 start) 008 echo start LVS of DirectorSe...

本文由今晚买四不像发布于操作系统,转载请注明出处:LVS两种工作格局测量检验脚本,tunl真实机脚本

关键词: