LVS 3种工作模式配置脚本

LVS-DR:

#!/bin/sh

VIP=192.168.0.210

RIP1=192.168.0.175

RIP2=192.168.0.145

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

case “$1” in

start)

echo “start LVS of DirectorServer”

#Set the Virtual IP Address

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

/sbin/route add -host $VIP dev eth0: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/ifconfig eth0:1 down

;;

*)

echo “Usage: $0 {start|stop}”

exit 1

esac

配置 RIP server

 

 

#!/bin/bash

VIP=192.168.0.210

. /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

ifconfig lo:0 $VIP netmask 255.255.255.255  up

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

sysctl -p >/dev/null 2>&1

echo “RealServer Start OK”

 

;;

stop)

ifconfig lo:0 down

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 {start|stop}”

exit 1

esac

=================================================

LVS-NAT

#!/bin/sh

# description: start LVS of Nat

VIP=202.99.59.110

RIP1=10.1.1.2

RIP2=10.1.1.3

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

case “$1″ in

start)

echo ” start LVS of NAtServer”

echo “1” >/proc/sys/net/ipv4/ip_forward

echo “0” >/proc/sys/net/ipv4/conf/all/send_redirects

echo “0” >/proc/sys/net/ipv4/conf/default/send_redirects

echo “0” >/proc/sys/net/ipv4/conf/eth0/send_redirects

echo “0” >/proc/sys/net/ipv4/conf/eth1/send_redirects

#Clear IPVS table

/sbin/ipvsadm -C

#set LVS

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

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

#Run LVS

/sbin/ipvsadm

#end

;;

stop)

echo “close LVS Nat server”

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/eth0/send_redirects

echo “1” >/proc/sys/net/ipv4/conf/eth1/send_redirects

/sbin/ipvsadm -C

;;

*)

echo “Usage: $0 {start|stop}”

exit 1

esac

配置real server

 

LVS-Nat 模式的后端机器不需要配置.

 

=========================================

LVS-TUN

#!/bin/sh

# description: start LVS of TUN

VIP=192.168.25.41

RIP1=192.168.25.44

RIP2=192.168.25.45

 

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

case “$1″ in

start)

echo ” start LVS of TUN”

# set the Virtual IP Address

/sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.0 up

/sbin/route add -host $VIP dev tunl0

#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 -i

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

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

#Run LVS

/sbin/ipvsadm

#end

;;

stop)

echo “close LVS Directorserver”

ifconfig tunl0 down

/sbin/ipvsadm -C

;;

*)

echo “Usage: $0 {start|stop}”

exit 1

esac

配置real server

 

#!/bin/sh

# ghb in 20060812

# description: Config realserver tunl port and apply arp patch

VIP=192.168.25.43

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

case “$1” in

start)

echo “Tunl port starting”

ifconfig tunl0 $VIP netmask 255.255.255.0 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

sysctl -p>/dev/null 2>&1

echo “RealServer Start OK

;;

stop)

echo “Tunl port closing”

ifconfig tunl0 down

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

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

;;

*)

echo “Usage: $0 {start|stop}”

exit 1

esac

===================

发表评论

电子邮件地址不会被公开。 必填项已用*标注