Linux之lvs负载均衡【TUN模式】

######隧道TUN模式######

#在server1上
1.ipvsadm -C ##清除之前的规则

2.modprobe ipip ##添加隧道使用的模块

ip addr del 172.25.0.100/24 dev eth0
ip addr add 172.25.0.100/24 dev tunl0
ip link set up tunl0 ##删除原来网卡上的vip,添加到tunl0上,并激活

ipvsadm -A -t 172.25.0.100:80 -s rr
ipvsadm -a -t 172.25.0.100:80 -r 172.25.0.2:80 -i
ipvsadm -a -t 172.25.0.100:80 -r 172.25.0.3:80 -i ##添加隧道规则

#在server2和server3(rs)上
modprobe ipip ##添加tunl模块

ip addr del 172.25.0.100/32 dev eth0

ip addr add 172.25.0.100/32 dev tunl0 ##添加vip到tunl上

ip link set up tunl0 ##激活tunl0

sysctl -a | grep rp_filter ##查看反向过滤规则
sysctl -w net.ipv4.conf.default.rp_filter = 0
sysctl -w net.ipv4.conf.default.rp_filter=0
sysctl -w net.ipv4.conf.lo.rp_filter=0
sysctl -w net.ipv4.conf.eth0.rp_filter=0
sysctl -w net.ipv4.conf.tunl0.rp_filter=0 ##关闭反向过滤(如果开启,会对流入的数据包的反向路径进行校验,如果不符合要求,就 丢弃,设置为0则不进行校验)

sysctl -p ##使生效

猜你喜欢

转载自blog.csdn.net/qq_36016375/article/details/94915606