Linux:LVS/TUN模式

一·LVS/YUN模式

1.LVS/TUN模式原理和特点

这里写图片描述
在原有的IP报文外再次封装多一层IP首部,内部IP首部(源地址为CIP,目标IIP为VIP),外层IP首部(源地址为DIP,目标IP为RIP)

(a) 当用户请求到达Director Server,此时请求的数据报文会先到内核空间的PREROUTING链。此时报文的源IP为CIP,目标IP为VIP 。
(b) PREROUTING检查发现数据包的目标IP是本机,将数据包送至INPUT链
(c) IPVS比对数据包请求的服务是否为集群服务,若是,在请求报文的首部再次封装一层IP报文,封装源IP为为DIP,目标IP为RIP。然后发至POSTROUTING链。
此时源IP为DIP,目标IP为RIP
(d) POSTROUTING链根据最新封装的IP报文,将数据包发至RS(因为在外层封装多了一层IP首部,所以可以理解为此时通过隧道传输)。
此时源IP为DIP,目标IP为RIP
(e)RS接收到报文后发现是自己的IP地址,就将报文接收下来,拆除掉最外层的IP后,会发现里面还有一层IP首部,而且目标是自己的lo接口VIP,那么此
时RS开始处理此请求,处理完成之后,通过lo接口送给eth0网卡,然后向外传递。 此时的源IP地址为VIP,目标IP为CIP
(f)响应报文最终送达至客户端

2.LVS-Tun模型特性

RIP、VIP、DIP全是公网地址 RS的网关不会也不可能指向DIP 所有的请求报文经由Director
Server,但响应报文必须不能进过Director Server 不支持端口映射 RS的系统必须支持隧道 其实企业中最常用的是 DR
实现方式,而 NAT 配置上比较简单和方便,后边实践中会总结 DR 和 NAT 具体使用配置过程。

二·TUM模式

在server1中:

[root@server1 html]# modprobe ipip   ##导入模块
[root@server1 html]# ip addr
[root@server1 html]# ip link set up tunl0    
[root@server1 html]# ip addr add 172.25.71.100/24 dev tunl0   
[root@server1 html]# ip addr
[root@server1 html]# ipvsadm -C   
[root@server1 html]# ipvsadm -A -t 172.25.71.100:80 -s rr    
[root@server1 html]# ipvsadm -a -t 172.25.71.100:80 -r 172.25.71.3:80 -i    
[root@server1 html]# ipvsadm -a -t 172.25.71.100:80 -r 172.25.71.2:80 -i
[root@server1 html]# ipvsadm -l

在server2中:

[root@server2 html]# modprobe ipip
[root@server2 html]# ip addr
[root@server2 html]# ip link set up tunl0
[root@server2 html]# ip addr add 172.25.71.100/24 dev tunl0 
[root@server2 html]# /etc/init.d/arptables_jf start
[root@server2 html]# sysctl -w net.ipv4.conf.tunl0.rp_filter=0
net.ipv4.conf.tunl0.rp_filter = 0
[root@server2 html]# arptables -A IN -d 172.25.71.100 -j DROP   

这里写图片描述

在server3中:

[root@server3 html]# modprobe ipip
[root@server3 html]# ip addr
[root@server3 html]# ip link set up tunl0
[root@server3 html]# ip addr add 172.25.71.100/24 dev tunl0 
[root@server3 html]# /etc/init.d/arptables_jf start
[root@server3 html]# sysctl -w net.ipv4.conf.tunl0.rp_filter=0
net.ipv4.conf.tunl0.rp_filter = 0
[root@server3 html]# arptables -A IN -d 172.25.71.100 -j DROP

在物理机测试:

[root@foundation71 html]# curl 172.25.71.100
www.westos.org---server2
[root@foundation71 html]# curl 172.25.71.100
bbs.westos.org
[root@foundation71 html]# curl 172.25.71.100
www.westos.org---server2

这里写图片描述

猜你喜欢

转载自blog.csdn.net/Le_Anny/article/details/81321608