上善若水,不浮不沉!
分类: LINUX
2014-04-02 09:33:15
本文介绍使用LVS实现负载均衡的TUN模式实验。
TUN模式与DR模式实验步骤区别在VIP绑定设备不一样,简单修改DR脚本即可。
1,实验环境:
负载均衡器: :192.168.1.16 vip:
192.168.1.17
后端WEB1:192.168.1.19
后端WEB2:192.168.1.20
2,创建LVS TUN模式启动脚本
[root@localhost ~]# vi
/etc/init.d/lvsdstun
#!/bin/bash
VIP=192.168.1.17
RIP1=192.168.1.19
RIP2=192.168.1.20
/etc/rc.d/init.d/functions
case
"$1" in
start)
echo "start LVS of DirectorServer
Tun"
/sbin/ifconfig tunl0 $VIP broadcast $VIP netmask
255.255.255.255 up
/sbin/route add -host $VIP dev
tunl0
/sbin/ipvsadm -C
/sbin/ipvsadm -A -t $VIP:80
-s rr
/sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80
-i###-i指定工作模式为TUN
/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
[root@localhost ~]# chmod +x /etc/rc.d/init.d/lvsdsdr
[root@localhost ~]#
/etc/rc.d/init.d/lvsdsdr start
[root@localhost ~]# ifconfig
tunl0
tunl0 Link encap:IPIP Tunnel HWaddr
inet
addr:192.168.1.17 Mask:255.255.255.255
UP RUNNING NOARP MTU:1480
Metric:1
RX packets:0 errors:0 dropped:0 overruns:0
frame:0
TX packets:0 errors:0 dropped:0 overruns:0
carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0
b) TX bytes:0 (0.0 b)
3, web1,web2分别创建启动脚本
[root@localhost ~]# vi
/etc/init.d/lvsrstun
#!/bin/bash
VIP=192.168.1.17
/etc/rc.d/init.d/functions
case
"$1" in
start)
echo "start LVS of RealServer Tun"
/sbin/ifconfig tunl0 $VIP broadcast $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
;;
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
[root@localhost ~]# chmod +x /etc/rc.d/init.d/lvsrsdr
[root@localhost ~]#
/etc/rc.d/init.d/lvsrsdr start
[root@localhost ~]# ifconfig
tunl0
tunl0 Link encap:IPIP Tunnel HWaddr
inet
addr:192.168.1.17 Mask:255.255.255.255
UP RUNNING NOARP MTU:1480
Metric:1
RX packets:15 errors:0 dropped:0 overruns:0
frame:0
TX packets:0 errors:0 dropped:0 overruns:0
carrier:0
collisions:0 txqueuelen:0
RX bytes:1890 (1.8
KiB) TX bytes:0 (0.0 b)
4,web1,web2分别修改首页,启动http服务
5,终端及WEB测试
LVS-TUN模式实验
6,lvs查看访问连接