LVS achieve --LVS / Tun pattern implementation

LVS / Tun principles and characteristics: https://blog.csdn.net/qq_35887546/article/details/104425264

The experiment requires three virtual machines and physical machines:

Virtual machine name effect IP
server1 DS 172.25.63.1
server2 RS1 172.25.63.2
server3 RS2 172.25.63.3

VIP is: 172.25.63.100
Testing Services: Http ports: 80
physical machines to clients

server2 and server3 install apache, publish written documents released under the directory / var / www / html by default

Experiments using rules before emptying server1 ago:

[root@server1 ~]# ipvsadm -C
[root@server1 ~]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn

1. Turn on the tunnel model
in server1:

[root@server1 ~]# modprobe ipip
[root@server1 ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:1b:f6:56 brd ff:ff:ff:ff:ff:ff
    inet 172.25.63.1/24 brd 172.25.63.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet 172.25.63.100/32 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe1b:f656/64 scope link 
       valid_lft forever preferred_lft forever
3: tunl0@NONE: <NOARP> mtu 1480 qdisc noop state DOWN qlen 1					#多了隧道的模型
    link/ipip 0.0.0.0 brd 0.0.0.0

2. Add to VIP ip tunnel

In server1:

[root@server1 ~]# ip addr del 172.25.63.100/32 dev eth0					#先将VIP从eth0上删除
[root@server1 ~]# ip addr add 172.25.63.100/32 dev tunl0

3. Add ipvs rule
in server1:

[root@server1 ~]# ipvsadm -A -t 172.25.63.100:80 -s rr
[root@server1 ~]# ipvsadm -a -t 172.25.63.100:80 -r 172.25.63.2:80 -i			# -i表示隧道模式
[root@server1 ~]# ipvsadm -a -t 172.25.63.100:80 -r 172.25.63.3:80 -i
[root@server1 ~]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  server1:http rr
  -> server2:http                 Tunnel  1      0          0         
  -> server3:http                 Tunnel  1      0          0         
[root@server1 ~]# ip link set up tunl0				#激活隧道模式

Configuring RS

The same operation as in server2 and server3:

modprobe ipip
ip addr del 172.25.63.100/32 dev eth0
ip addr add 172.25.63.100/32 dev tunl0
ip link set up tunl0

Close inverse filtering rule on server2 and server3 core (in server2 example):

[root@server2 html]# sysctl -a | grep rp_filter			#,查看反向过滤规则,将选项为 1 的全部改为 0
net.ipv4.conf.all.arp_filter = 0
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.arp_filter = 0
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.eth0.arp_filter = 0
net.ipv4.conf.eth0.rp_filter = 1
net.ipv4.conf.lo.arp_filter = 0
net.ipv4.conf.lo.rp_filter = 0
net.ipv4.conf.tunl0.arp_filter = 0
net.ipv4.conf.tunl0.rp_filter = 1
[root@server2 html]# sysctl -w net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.all.rp_filter = 0
[root@server2 html]# sysctl -w net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.rp_filter = 0
[root@server2 html]# sysctl -w net.ipv4.conf.eth0.rp_filter=0
net.ipv4.conf.eth0.rp_filter = 0
[root@server2 html]# sysctl -w net.ipv4.conf.tunl0.rp_filter=0
net.ipv4.conf.tunl0.rp_filter = 0
[root@server2 html]# sysctl -a | grep rp_filter				#选项全部为0,设置成功
net.ipv4.conf.all.arp_filter = 0
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.arp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.eth0.arp_filter = 0
net.ipv4.conf.eth0.rp_filter = 0
net.ipv4.conf.lo.arp_filter = 0
net.ipv4.conf.lo.rp_filter = 0
net.ipv4.conf.tunl0.arp_filter = 0
net.ipv4.conf.tunl0.rp_filter = 0

[root@server2 html]# sysctl -p				#使所有选项生效

Attention must also be the same as the above operation on server3

5. Test

Client:

[kiosk@foundation63 ~]$ curl 172.25.63.100
server3
[kiosk@foundation63 ~]$ curl 172.25.63.100
server2
[kiosk@foundation63 ~]$ curl 172.25.63.100
server3
[kiosk@foundation63 ~]$ curl 172.25.63.100
server2

Tun model represents the successful realization

Published 101 original articles · won praise 65 · views 3131

Guess you like

Origin blog.csdn.net/qq_35887546/article/details/104429831
LVS
LVS
lvs
LVS
LVS