实验拓扑
164230334.png

IP分配
client            192.168.30.1
Router          e0/0             10.0.0.123
                    e0/1             192.168.30.200 (网关)
Director        eth0    192.168.30.105/24
                     eth0:1  192.168.30.254/32 (VIP)
Real 1            eth0    192.168.30.113/24
                     tunl0   192.168.30.254/32 (VIP)
Real 2            eth0    192.168.30.114/24
                     tunl0   192.168.30.254/32 (VIP)

TUN 模式的拓扑结构与DR的一样,只需要将原先的lo网卡换成tunl网卡

一、配置Real 服务器
1、主页配置
前面的实验中以配置好,这里不再重复

2、配置IP地址
[root@node1 ~]# ifconfig eth0 192.168.30.113/24
[root@node1 ~]# ip addr add dev tunl0 192.168.30.254/32 brd 192.168.30.254
[root@node1 ~]# ip link set dev tunl0 up
[root@node1 ~]#  route add default gw 192.168.30.200
[root@node1 ~]# route add -host 192.168.30.254 dev tunl0

[root@node2 ~]# ifconfig eth0 192.168.30.114/24
[root@node2 ~]# ip addr add dev tunl0 192.168.30.254/32 brd 192.168.30.254
[root@node2 ~]# ip link set dev tunl0 up
[root@node2 ~]#  route add default gw 192.168.30.200
[root@node2 ~]# route add -host 192.168.30.254 dev tunl0

3、关闭ARP响应
[root@node1 ~]# echo "1" >/proc/sys/net/ipv4/conf/tunl0/arp_ignore
[root@node1 ~]# echo "2" >/proc/sys/net/ipv4/conf/tunl0/arp_announce
[root@node1 ~]# echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
[root@node1 ~]# echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

[root@node2 ~]# echo "1" >/proc/sys/net/ipv4/conf/tunl0/arp_ignore
[root@node2 ~]# echo "2" >/proc/sys/net/ipv4/conf/tunl0/arp_announce
[root@node2 ~]# echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
[root@node2 ~]# echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce

二、配置Director 服务器
1、配置IP
[root@server ~]# ifconfig eth0 192.168.30.105/24
[root@server ~]# ifconfig eth0:1 192.168.30.254 netmask 255.255.255.255 broadcast 192.168.30.254
[root@server ~]# route del default gw 10.0.0.2
[root@server ~]# route add default gw 192.168.30.200

[root@server ~]# route add -host 192.168.30.254 dev tunl0


[root@server ~]# echo "0" > /proc/sys/net/ipv4/ip_forward

[root@server ~]# echo "1" > /proc/sys/net/ipv4/conf/all/send_redirects

[root@server ~]# echo "1" > /proc/sys/net/ipv4/conf/default/send_redirects

[root@server ~]# echo "1" > /proc/sys/net/ipv4/conf/eth1/send_redirects




[root@server ~]# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.0.0                 *               255.255.255.0   U     0      0        0 eth1
192.168.30.0         *               255.255.255.0   U     0      0        0 eth0
link-local              *               255.255.0.0     U     1002   0        0 eth0
link-local              *               255.255.0.0     U     1003   0        0 eth1
default         192.168.30.200     0.0.0.0         UG    0      0        0 eth0

2、配置lvs
[root@server ~]# ipvsadm -A -t 192.168.30.254:80 -s rr
[root@server ~]# ipvsadm -a -t 192.168.30.254:80 -r 192.168.30.113 -i
[root@server ~]# ipvsadm -a -t 192.168.30.254:80 -r 192.168.30.114 -i

3、测试
[root@server ~]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
 -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  192.168.30.254:80 rr
 -> 192.168.30.113:80                Tunnel        1              0          0        
 -> 192.168.30.114:80                Tunnel        1              0          0    

配置脚本:
============Director===========
#!/bin/bash
VIP=192.168.30.254
RIP1=192.168.30.113
RIP2=192.168.30.114

. /etc/rc.d/init.d/functions
case "$1" in
start)
       echo "start LVS of Director Server Tun"
       /sbin/ifconfig tunl0 $VIP broadcast $VIP netmask 255.255.255.255
       /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
       /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -i

       /sbin/ipvsadm

       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

       ;;
stop)
       echo "stop LVS of Director Server Tun "
       /sbin/ifconfig tunl0 down
       /sbin/ipvsadm -C
       ;;
*)
       echo "Usage: $0 {start|stop}"
       exit 1
esac
exit 0

============Real Server===========
#!/bin/bash
VIP=192.168.30.254
RIP1=192.168.30.113
RIP2=192.168.30.114

case $1 in
start)
       echo "Start LVS of TUN"
       /sbin/ifdown eth1
       /sbin/ifconfig tunl0 $VIP netmask 255.255.255.255 broadcast $VIP
       /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 "Stop LVS of 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