上一节我们讲到了LVS/DR模式实例部署,这节将会讲到LVS/TUN实例部署,LVS/TUN模式比较适用于异地灾备的一种模式,它突破了LVS/NAT以及LVS/DR模式因为DIR和RIP地理环境限制,下面我们来讲讲LVS/TUN部署过程
LVS/NAT实例部署
如图所示为整体的拓扑图:
CIP:202.10.1.1/24
VIP:202.10.1.101/24
DIR: Eth1:202.10.1.100/24 Eth0:192.168.1.2/24
RS server:(这里假设后端只有两台RS server)
RIP3( Eth0:192.168.1.12/24 && Eth1:202.10.1.12/24(提供http服务)
RIP2( Eth0:192.168.1.11/24 && Eth1:202.10.1.11/24(提供http服务)
二.部署操作:
负载均衡器上配置操作
(1)在DIR上安装ipvsadm软件包以及相关依赖包:
# yum install popt-devel libnl-devel ipvsadm -y
(2)在DIR上新建一个shell脚本文件,如下操作所示:
# vim /etc/init.d/lvs-dr
脚本内容如下
#!/bin/sh # Startup script handle the initialisation of LVS # chkconfig: - 28 72 # description: Initialise the Linux Virtual Server for TUN # ### BEGIN INIT INFO # Provides: ipvsadm # Required-Start: $local_fs $network $named # Required-Stop: $local_fs $remote_fs $network # Short-Description: Initialise the Linux Virtual Server # Description: The Linux Virtual Server is a highly scalable and highly # available server built on a cluster of real servers, with the load # balancer running on Linux. LOCK=/var/lock/lvs-tun.lock VIP=202.10.1.101 RIP1=192.168.1.10 RIP2=192.168.1.11 . /etc/rc.d/init.d/functions start() { PID=`ipvsadm -Ln | grep ${VIP} | wc -l` if [ $PID -gt 0 ]; then echo "The LVS-TUN Server is already running !" else #Set the tun Virtual IP Address /sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $VIP dev tunl0 #Clear IPVS Table /sbin/ipvsadm -C #Set Lvs /sbin/ipvsadm -At $VIP:80 -s rr /sbin/ipvsadm -at $VIP:80 -r $RIP1:80 -i -w 1 /sbin/ipvsadm -at $VIP:80 -r $RIP2:80 -i -w 1 /bin/touch $LOCK #Run Lvs echo "starting LVS-TUN-DIR Server is ok !" fi } stop() { #stop Lvs server /sbin/ipvsadm -C /sbin/ifconfig tunl0 down >/dev/null rm -rf $LOCK echo "stopping LVS-TUN-DIR server is ok !" } status() { if [ -e $LOCK ]; then echo "The LVS-TUN Server is already running !" else echo "The LVS-TUN Server is not running !" fi } case "$1" in start) start ;; stop) stop ;; restart) stop sleep 1 start ;; status) status ;; *) echo "Usage: $1 {start|stop|restart|status}" exit 1 esac exit 0
授权并启动该脚本
# chmod 777 /etc/init.d/lvs-dr
# service lvd-dr start
RS server 上配置操作
(1)分别在每个RIP(RIP1,RIP2,RIP3)上新建一个shell脚本文件,如下操作所示:
# vim /etc/init.d/lvs-dr
脚本内容如下
#!/bin/sh # # Startup script handle the initialisation of LVS # chkconfig: - 28 72 # description: Initialise the Linux Virtual Server for TUN # ### BEGIN INIT INFO # Provides: ipvsadm # Required-Start: $local_fs $network $named # Required-Stop: $local_fs $remote_fs $network # Short-Description: Initialise the Linux Virtual Server # Description: The Linux Virtual Server is a highly scalable and highly # available server built on a cluster of real servers, with the load # balancer running on Linux. # description: start LVS of DR-RIP LOCK=/var/lock/ipvsadm.lock VIP=192.168.10.100 . /etc/rc.d/init.d/functions start() { PID=`ifconfig | grep tunl0 | wc -l` if [ $PID -ne 0 ]; then echo "The LVS-TUN-RIP Server is already running !" else /sbin/ifconfig tunl0 $VIP netmask 255.255.255.255 broadcast $VIP 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/eth0/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/eth0/arp_announce echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce /bin/touch $LOCK echo "starting LVS-TUN-RIP server is ok !" fi } stop() { /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/eth0/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/eth0/arp_announce echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce rm -rf $LOCK echo "stopping LVS-TUN-RIP server is ok !" } status() { if [ -e $LOCK ]; then echo "The LVS-TUN-RIP Server is already running !" else echo "The LVS-TUN-RIP Server is not running !" fi } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) status ;; *) echo "Usage: $1 {start|stop|restart|status}" exit 1 esac exit 0
注:在LVS/TUN模式中,关于arp原则:
(1)若DIR和RIP在不同lan网络中,比如不同的网段,不同的IDC机房,就不需要设置arp仰制,不同网段中,arp会被屏蔽掉,所以只需要开启ip tunnel即可;
(2)若DIR和RIP在同一广播域中,需要和LVS/DR模式一样在所有的RIP上仰制arp,防止arp响应导致arp表婚乱,
授权并启动该脚本
# chmod 777 /etc/init.d/lvs-dr
# service lvd-dr start
(2)分别在每个RIP上安装http服务,并创建测试页,如下分别为RIP上测试页面:
RIP1上的测试页:
RIP2上的测试页:
三.LVS负载测试:
在客户端上访问:http://vip,这时我们就可以看到如下的页面,此时页面为RIP1的页面
本文出自 “菜鸟的成长记” 博客,请务必保留此出处http://blief.blog.51cto.com/6170059/1747656
原文:http://blief.blog.51cto.com/6170059/1747656