LVS四种模式之TUN(隧道)模式

时间:2024-03-20 17:28:05

一、配置环境:

1.清除策略,删除vip

server1:
ipvsadm -C    ##清除策略
ip addr del 172.25.38.100/24 dev eth0 

server2:
ip addr del 172.25.60.100/32 dev eth0

server3:
ip addr del 172.25.60.100/32 dev eth0

LVS四种模式之TUN(隧道)模式

2.编辑调度策略

server1:

modprobe ipip    ##添加ipip模块
ip addr add 172.25.60.100/24 dev tunl0
ip link set up tunl0

ipvsadm -A -t 172.25.60.100:80 -s rr
ipvsadm -a -t 172.25.60.100:80 -r 172.25.38.2:80 -i
ipvsadm -a -t 172.25.60.100:80 -r 172.25.38.3:80 -i  #-i 隧道模式


/etc/init.d/ipvsadm save

LVS四种模式之TUN(隧道)模式

LVS四种模式之TUN(隧道)模式

server2:

[[email protected] ~]# modprobe ipip 
[[email protected] ~]# ip addr add 172.25.60.100/32 dev tunl0
[[email protected] ~]# ip link set up tunl0

将反向过滤关闭 (linux系统反向过滤 系统在接收到一个IP包后,检查该IP是不是合乎要求,不合要求的IP包会被系统丢弃)

[[email protected] ~]# sysctl -a | grep rp_filter

[[email protected] ~]# sysctl -w net.ipv4.conf.lo.rp_filter=0
net.ipv4.conf.lo.rp_filter = 0
[[email protected] ~]# sysctl -w net.ipv4.conf.eth0.rp_filter=0
net.ipv4.conf.eth0.rp_filter = 0
[[email protected] ~]# sysctl net.ipv4.conf.tunl0.rp_filter=0
net.ipv4.conf.tunl0.rp_filter = 0

 LVS四种模式之TUN(隧道)模式

vim /etc/sysctl.conf 
net.ipv4.conf.default.rp_filter = 0

sysctl -p  ##重新加载

LVS四种模式之TUN(隧道)模式

LVS四种模式之TUN(隧道)模式

server3:与server2操作相同

二、测试

在物理机上:

[[email protected] ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[[email protected] ~]# curl 172.25.60.100
<h1>server2,example.com</h1>
[[email protected] ~]# curl 172.25.60.100
<h1>server3 - www.westos.org</h1>
[[email protected] ~]# curl 172.25.60.100
<h1>server2,example.com</h1>
[[email protected] ~]#  arp -an |grep 100
? (172.25.60.100) at 52:54:00:d1:b7:77 [ether] on br0
[[email protected] ~]# 

LVS四种模式之TUN(隧道)模式

LVS四种模式之TUN(隧道)模式

注意:lvs和后端真实服务器上都要有vip