在上个实验的基础上,给路由,LVS,RS1,RS2 添加172.0.0.0/24网段
1> 路由器
[23:09:10 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 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:18:c0:18 brd ff:ff:ff:ff:ff:ff inet 10.0.0.19/24 brd 10.0.0.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet 172.16.0.200/24 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe18:c018/64 scope link valid_lft forever preferred_lft forever 3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 00:0c:29:18:c0:22 brd ff:ff:ff:ff:ff:ff inet 192.168.10.50/24 brd 192.168.10.255 scope global noprefixroute eth1 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe18:c022/64 scope link valid_lft forever preferred_lft forever
2> LVS主机
[23:09:27 root@centos8 ~]#ip a a 172.16.0.100/24 dev eth0 [23:10:05 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 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 inet 172.16.0.100/24 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:feeb:1fa3/64 scope link valid_lft forever preferred_lft forever
3> RS1,RS2
[23:09:35 root@centos8 ~]#ip a a 172.16.0.100/24 dev eth0 [23:10:14 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 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 inet 172.16.0.100/24 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fee7:afe9/64 scope link valid_lft forever preferred_lft forever
[23:09:37 root@centos8 ~]#ip a a 172.16.0.100/24 dev eth0 [23:10:19 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 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 inet 172.16.0.100/24 scope global eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe8b:5c39/64 scope link valid_lft forever preferred_lft forever
LVS规则
[22:58:19 root@centos8 ~]#ipvsadm -A -t 172.16.0.100:80 -s rr [23:01:59 root@centos8 ~]#ipvsadm -a -t 172.16.0.100:80 -r 10.0.0.17:80 -g [23:02:34 root@centos8 ~]#ipvsadm -a -t 172.16.0.100:80 -r 10.0.0.18:80 -g [23:02:38 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 172.16.0.100:80 rr -> 10.0.0.17:80 Route 1 0 0 -> 10.0.0.18:80 Route 1 0 0
测试
[23:10:51 root@centos8 ~]#while :;do curl 172.16.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 18.noise.org 10.0.0.18
持久保存和重新reload规则 [23:10:07 root@centos8 ~]#ipvsadm-save > /data/ipvsadm-rule1 [23:15:41 root@centos8 ~]#cat /data/ipvsadm-rule1 -A -t centos8.3:http -s rr -a -t centos8.3:http -r 10.0.0.17:http -g -w 1 -a -t centos8.3:http -r 10.0.0.18:http -g -w 1 [23:15:55 root@centos8 ~]#ipvsadm-restore < /data/ipvsadm-rule1 [23:15:59 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.16:80 rr -> 10.0.0.17:80 Route 1 0 0 -> 10.0.0.18:80 Route 1 0 0