1> 本次实验共计4台机器
A:客户机,192.168.10.6
[23:29:02 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:7a:db:89 brd ff:ff:ff:ff:ff:ff inet 192.168.10.6/24 brd 192.168.10.255 scope global noprefixroute eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe7a:db89/64 scope link valid_lft forever preferred_lft forever
B:LVS, 两张网卡,主机网卡:192.168.10.100, NAT网卡:10.0.0.16, 同时开启ip_forward路由功能
[22:15:11 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 inet6 fe80::20c:29ff:feeb:1fa3/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:eb:1f:ad brd ff:ff:ff:ff:ff:ff inet 192.168.10.100/24 brd 192.168.10.255 scope global noprefixroute eth1 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:feeb:1fad/64 scope link valid_lft forever preferred_lft forever
[22:55:50 root@centos8 ~]#sysctl -a | grep ip_forward
net.ipv4.ip_forward = 1
C: 两台客户机, C1:10.0.0.17, gw 10.0.0.16 c2:10.0.0.18,gw 10.0.0.016
[22:10:20 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 inet6 fe80::20c:29ff:fee7:afe9/64 scope link valid_lft forever preferred_lft forever [22:10:25 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 inet6 fe80::20c:29ff:fe8b:5c39/64 scope link valid_lft forever preferred_lft forever
开始设置ipvsadm
[22:15:30 root@centos8 ~]#ipvsadm -A -t 192.168.10.100:80 -s rr (rr代表运用轮询算法) [22:16:26 root@centos8 ~]#ipvsadm -a -t 192.168.10.100:80 -r 10.0.0.17:80 -m (m 是NAT) [22:16:45 root@centos8 ~]#ipvsadm -a -t 192.168.10.100:80 -r 10.0.0.18:80 -m [22:16:51 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 192.168.10.100:80 rr -> 10.0.0.17:80 Masq 1 0 0 -> 10.0.0.18:80 Masq 1 1 0
用客户机192.168.10.6测试
[22:33:47 root@centos8 ~]#while :;do curl 192.168.10.100;sleep 1; done 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 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