LVS-IP TUN集群

LVS-IP TUN集群概述

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

异地机房的好处: 容灾

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

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

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

[root@zh75 ~]# ifconfig ens32:1 192.168.1.66
[root@zh75 ~]# 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 模式

[root@zh75 ~]# ipvsadm -C
[root@zh75 ~]# ipvsadm -A -t 192.168.1.66:80 -s rr
[root@zh75 ~]# ipvsadm -a -t 192.168.1.66:80 -r 192.168.1.133 -i
[root@zh75 ~]# ipvsadm -a -t 192.168.1.66:80 -r 192.168.1.128 -i

-i 隧道模式

[root@zh75 ~]# 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

[root@zh74 ~]# modprobe ipip # 加载好ipip模块后,会有默认的tunl0隧道
[root@zh74 ~]# 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

[root@zh74 ~]# lsmod | grep ipip
ipip 13465 0
tunnel4 13252 1 ipip
ip_tunnel 25163 1 ipip
配置 VIP

[root@zh74 ~]# ifconfig tunl0 192.168.1.66 netmask 255.255.255.255 up
[root@zh74 ~]# systemctl restart network
[root@zh74 ~]# 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 转发

[root@zh74 ~]# 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

[root@zh74 ~]# 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收到数据包后,返回的请求再次转给分发器。

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

[root@zh76 ~]# modprobe ipip # 加载好ipip模块后,会有默认的tunl0隧道
[root@zh76 ~]# 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

[root@zh76 ~]# lsmod | grep ipip
ipip 13465 0
tunnel4 13252 1 ipip
ip_tunnel 25163 1 ipip
配置 VIP

[root@zh76 ~]# ifconfig tunl0 192.168.1.66 netmask 255.255.255.255 up
[root@zh76 ~]# systemctl restart network
[root@zh76 ~]# 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 转发

[root@zh76 ~]# 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

[root@zh76 ~]# 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收到数据包后,返回的请求再次转给分发器。

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值