LVS DR模式配置脚本

配置LVS Server

#!/bin/sh
VIP=192.168.20.200
RIP1=192.168.20.92
RIP2=192.168.20.93
netname="ens33"
. /etc/rc.d/init.d/functions
         case "$1" in
         start)
         echo "start LVS of DirectorServer"
         #Set the Virtual IP Address
         /sbin/ip addr add  $VIP/32 dev ${netname}:1 label ${netname}:1
         /sbin/route add -host $VIP dev ${netname}:1
         #Clear IPVS Table
         /sbin/ipvsadm -C
         #Set Lvs
         /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
         #Run Lvs
         /sbin/ipvsadm
         ;;
         stop)
         echo "close LVS Directorserver"
         /sbin/ipvsadm -C
         /sbin/ip addr del  $VIP/32 dev ${netname}:1 label ${netname}:1
         ;;
         *)
         echo "Usage: $0 {start|stop}"
         exit 1
         esac

配置RIP Server

#!/bin/bash
VIP=192.168.20.200
. /etc/rc.d/init.d/functions
case "$1" in
     start)
      echo "reparing for Real Server"
        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
        /sbin/ip addr add  $VIP/32 dev lo:0 label lo:0
        /sbin/route add -host $VIP dev lo:0
         ;;
     stop)
        /sbin/ip addr del  $VIP/32 dev lo:0 label lo:0
        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: lvs_dr_rip {start|stop}"
         exit 1
esac

LVS官网:http://www.linuxvirtualserver.org/

你可能感兴趣的:(WEB)