LVS-IP TUN集群

LVS-IP TUN集群概述

DR方式是通过MAC,规模是一个交换网络。而TUN方式,是通过给数据包加上新的IP头部来实现,这个可以跨整个广域网.

异地机房的好处: 容灾

是否可以保证 边界 最近访问到对应的real server呢? 不能,最大的问题

DNS view功能实现 边界最近访问, 智能DNS

实验拓扑图
在这里插入图片描述
配置 Director --> zh75​​​​​​​​​​​​​​ 网络

[[email protected] ~]# ifconfig ens32:1 192.168.1.66
[[email protected] ~]# ifconfig ens32:1
ens32:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.1.66 netmask 255.255.255.0 broadcast 192.168.1.255
ether 00:0c:29:83:2a:4d txqueuelen 1000 (Ethernet)
配置 LVS TUN 模式

[[email protected] ~]# ipvsadm -C
[[email protected] ~]# ipvsadm -A -t 192.168.1.66:80 -s rr
[[email protected] ~]# ipvsadm -a -t 192.168.1.66:80 -r 192.168.1.133 -i
[[email protected] ~]# ipvsadm -a -t 192.168.1.66:80 -r 192.168.1.128 -i

-i 隧道模式

[[email protected] ~]# 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.1.66:80 rr
-> 192.168.1.128:80 Tunnel 1 0 0
-> 192.168.1.133:80 Tunnel 1 0 0
配置 RealServer --> zh74

[[email protected] ~]# modprobe ipip # 加载好ipip模块后,会有默认的tunl0隧道
[[email protected] ~]# ifconfig tunl0
tunl0: flags=128 mtu 1480
tunnel txqueuelen 1 (IPIP Tunnel)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[[email protected] ~]# lsmod | grep ipip
ipip 13465 0
tunnel4 13252 1 ipip
ip_tunnel 25163 1 ipip
配置 VIP

[[email protected] ~]# ifconfig tunl0 192.168.1.66 netmask 255.255.255.255 up
[[email protected] ~]# systemctl restart network
[[email protected] ~]# ifconfig tunl0
tunl0: flags=193<UP,RUNNING,NOARP> mtu 1480
inet 192.168.1.66 netmask 255.255.255.255
tunnel txqueuelen 1 (IPIP Tunnel)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
关闭 ARP 转发

[[email protected] ~]# tail -7 /etc/sysctl.conf
net.ipv4.conf.tunl0.arp_ignore = 1
net.ipv4.conf.tunl0.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.tunl0.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0

[[email protected] ~]# sysctl -p

tunl0/rp_filter 默认为1 , 需要改为0,关闭此功能。
Linux的rp_filter用于实现反向过滤技术,也即uRPF,它验证反向数据包的流向,以避免伪装IP攻击 。 然而,在LVS TUN 模式中,我们的数据包是有问题的,因为从realserver ens33 出去的IP数据包的源IP地址应该为192.168.1.133,而不是VIP地址。所以必须关闭这一项功能。

DR和TUN在 网络层实际上使用了一个伪装IP数据包的功能。让client收到数据包后,返回的请求再次转给分发器。

[[email protected] ~]# cat /var/www/html/index.html
zh74 test successful !
[[email protected] ~]# systemctl start httpd
配置 RealServer --> zh76

[[email protected] ~]# modprobe ipip # 加载好ipip模块后,会有默认的tunl0隧道
[[email protected] ~]# ifconfig tunl0
tunl0: flags=128 mtu 1480
tunnel txqueuelen 1 (IPIP Tunnel)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[[email protected] ~]# lsmod | grep ipip
ipip 13465 0
tunnel4 13252 1 ipip
ip_tunnel 25163 1 ipip
配置 VIP

[[email protected] ~]# ifconfig tunl0 192.168.1.66 netmask 255.255.255.255 up
[[email protected] ~]# systemctl restart network
[[email protected] ~]# ifconfig tunl0
tunl0: flags=193<UP,RUNNING,NOARP> mtu 1480
inet 192.168.1.66 netmask 255.255.255.255
tunnel txqueuelen 1 (IPIP Tunnel)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
关闭 ARP 转发

[[email protected] ~]# tail -7 /etc/sysctl.conf
net.ipv4.conf.tunl0.arp_ignore = 1
net.ipv4.conf.tunl0.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.tunl0.rp_filter = 0
net.ipv4.conf.all.rp_filter = 0

[[email protected] ~]# sysctl -p

tunl0/rp_filter 默认为1 , 需要改为0,关闭此功能。
Linux的rp_filter用于实现反向过滤技术,也即uRPF,它验证反向数据包的流向,以避免伪装IP攻击 。 然而,在LVS TUN 模式中,我们的数据包是有问题的,因为从realserver ens33 出去的IP数据包的源IP地址应该为192.168.1.128,而不是VIP地址。所以必须关闭这一项功能。

DR和TUN在 网络层实际上使用了一个伪装IP数据包的功能。让client收到数据包后,返回的请求再次转给分发器。

[[email protected] ~]# cat /var/www/html/index.html
zh76 test successful !
[[email protected] ~]# systemctl restart httpd
测试
在这里插入图片描述
注:不能在分发器上直接测试,需要去其他机器上测试.
在这里插入图片描述