实验共计5台机器 ( 重要提示,网关很重要,很重要,很重要)
1.测试机 192.168.10.6,gw 192.168.10.50
2.路由器 eth0 10.0.0.19 , eth1 192.168.10.50, 开启ip_forward
3. LVS主机 vip:10.0.0.100/32, eth0 10.0.0.16, gw 10.0.0.19
[23:19:56 root@centos8 ~]#ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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 inet 10.0.0.100/0 scope global lo:1 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 fq_codel state UP group default qlen 1000 link/ether 00:0c:29:eb:1f:a3 brd ff:ff:ff:ff:ff:ff inet 10.0.0.16/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:feeb:1fa3/64 scope link valid_lft forever preferred_lft forever
4.RS1主机 vip:10.0.0.100, eth0 10.0.0.17, gw 10.0.0.19
#限制响应级别:arp_ignore
#限制通告级别:arp_announce
[23:26:29 root@centos8 ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore [23:26:39 root@centos8 ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce [23:26:43 root@centos8 ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore [23:26:46 root@centos8 ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce [23:26:50 root@centos8 ~]#ifconfig lo:1 10.0.0.100/32 [23:27:26 root@centos8 ~]#ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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 inet 10.0.0.100/0 scope global lo:1 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 fq_codel state UP group default qlen 1000 link/ether 00:0c:29:e7:af:e9 brd ff:ff:ff:ff:ff:ff inet 10.0.0.17/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fee7:afe9/64 scope link valid_lft forever preferred_lft forever
4.RS2主机 vip:10.0.0.100, eth0 10.0.0.18, gw 10.0.0.19
#限制响应级别:arp_ignore
#限制通告级别:arp_announce
[23:25:31 root@centos8 ~]#echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore [23:25:37 root@centos8 ~]#echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce [23:25:39 root@centos8 ~]#echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore [23:25:45 root@centos8 ~]#echo 2 > /proc/sys/net/ipv4/conf/lo/arp_announce
[23:26:23 root@centos8 ~]#ifconfig lo:1 10.0.0.100/32 [23:27:35 root@centos8 ~]#ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 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 inet 10.0.0.100/0 scope global lo:1 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 fq_codel state UP group default qlen 1000 link/ether 00:0c:29:8b:5c:39 brd ff:ff:ff:ff:ff:ff inet 10.0.0.18/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe8b:5c39/64 scope link valid_lft forever preferred_lft forever
LVS设置DR模式及算法
[23:16:03 root@centos8 ~]#ipvsadm -A -t 10.0.0.100:80 -s rr(rr代表轮询算法) [23:16:32 root@centos8 ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.17:80 -g(g代表DR模式,且不支持端口映射) [23:16:52 root@centos8 ~]#ipvsadm -a -t 10.0.0.100:80 -r 10.0.0.18:80 -g [23:16:57 root@centos8 ~]#ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.0.0.100:80 rr -> 10.0.0.17:80 Route 1 0 0 -> 10.0.0.18:80 Route 1 0 0
运用测试机器测试
[23:45:11 root@centos8 ~]#while :;do curl 10.0.0.100;sleep 1; done 17.noise.org 10.0.0.17 18.noise.org 10.0.0.18 17.noise.org 10.0.0.17 18.noise.org 10.0.0.18 17.noise.org 10.0.0.17 18.noise.org 10.0.0.18 17.noise.org 10.0.0.17