LVS三种工作模式测试脚本

1. NAT:
#!/bin/bash
VIP=192.168.0.111
RIP1=10.0.0.10
RIP2=10.0.0.20
case "$1" in
start)
           echo "start LVS of DirectorServer NAT"
           echo "1" >/proc/sys/net/ipv4/ip_forward
           /sbin/ipvsadm -C
           /sbin/ifconfig eth0:0 $VIP netmask 255.255.255.0 up
           /sbin/ipvsadm -A -t $VIP:80 -s rr 
           /sbin/ipvsadm -a -t $VIP:80 -r $RIP1 -m 
           /sbin/ipvsadm -a -t $VIP:80 -r $RIP2 -m
           /sbin/ipvsadm
       ;;
stop)
           echo "stop LVS of DirectorServer NAT"
           echo "0" >/proc/sys/net/ipv4/ip_forward
           /sbin/ipvsadm -C
           /sbin/ifconfig eth0:0 down
           ;;
*)
          echo "Usage: $0 {start|stop}"
          exit 1
esac


2.DR
  server:
#!/bin/bash
VIP=10.0.0.111
RIP1=10.0.0.20
RIP2=10.0.0.10
. /etc/rc.d/init.d/functions

case "$1" in
    start)
         echo "start LVS of DirectorServer DR"
         /sbin/ifconfig eth0:0 $VIP broadcast $VIP netmask 255.255.255.255 up
         /sbin/route add -host $VIP dev eth0:0
         echo "1">/proc/sys/net/ipv4/ip_forward
         /sbin/ipvsadm -C
         /sbin/ipvsadm -A -t $VIP:80 -s rr
         /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g
         /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g
         /sbin/ipvsadm -a -t $VIP:80 -r $RIP3:80 -g
         /sbin/ipvsadm
         ;;

     stop)
         echo "stop LVS of DierctorServer DR"
         echo "0">/proc/sys/net/ipv4/ip_forward
         /sbin/ipvsadm -C
         /sbin/ifconfig eth0:0 down
         ;;

       *)
         echo "Usage:$0{start|stop}"
         exit 1
esac 



   real server:
#!/bin/bash
VIP=10.0.0.111
. /etc/rc.d/init.d/functions

case "$1" in
   start)
     echo "start LVS of RealServer DR"
     /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
     /sbin/route add -host $VIP dev lo:0
     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
     ;;
    
   stop)
     /sbin/ifconfig lo:0 down
     echo "close LVS of RealServer DR"
     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 
     ;;

    *)
      echo "Usage:$0{start|stop}"
             exit 1
esac    


3.TUN
  server:
#!/bin/bash
VIP=192.168.0.111
RIP1=192.168.0.13
RIP2=192.168.0.17
. /etc/init.d/functions
case "$1" in
start)
           echo "start LVS of DirectorServer Tun"
           /sbin/ifconfig tunl0 $VIP  netmask 255.255.255.255 up
           /sbin/route add -host $VIP dev tunl0
         #  echo "0" >/proc/sys/net/ipv4/ip_forward
         #  echo "1" >/proc/sys/net/ipv4/conf/all/send_redirects  
         #  echo "1" >/proc/sys/net/ipv4/conf/default/send_redirects
         #  echo "1" >/proc/sys/net/ipv4/conf/eth1/send_redirects
           /sbin/ipvsadm -C
           /sbin/ipvsadm -A -t $VIP:80 -s rr
           /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -i
           /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i
           /sbin/ipvsadm
       ;;
stop)
           echo "stop LVS of DirectorServer Tun"
           /sbin/ifconfig tunl0 down
           /sbin/ipvsadm -C
           ;;
*)
          echo "Usage: $0 {start|stop}"
          exit 1
esac

   real server:
#!/bin/bash
VIP=192.168.0.111
. /etc/init.d/functions
case "$1" in
start)
           echo "start LVS of RealServer Tun"
           /sbin/ifconfig tunl0 $VIP  netmask 255.255.255.255 up
           /sbin/route add -host $VIP dev tunl0
           echo "1" >/proc/sys/net/ipv4/conf/tunl0/arp_ignore
           echo "2" >/proc/sys/net/ipv4/conf/tunl0/arp_announce
           echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
           echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce 
           echo 0 > /proc/sys/net/ipv4/ip_forward
           echo 0 > /proc/sys/net/ipv4/conf/tunl0/rp_filter
           echo 0 > /proc/sys/net/ipv4/conf/all/rp_filter
       ;;
stop)
           echo "close LVS of RealServer Tun"
           /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 "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
           echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
           ;;
*)
          echo "Usage: $0 {start|stop}"
          exit 1
esac
exit 0

你可能感兴趣的:(LVS三种工作模式测试脚本)