1.准备5台主机
(1)client:192.168.0.110(桥接),设置为静态ip,网关指向192.168.0.111
(2)路由器:192.168.0.111(桥接),192.168.147.148(nat)
修改配置文件,打开ip地址转发功能
echo 1 > /proc/sys/net/ipv4/ip_forward
(3)DS(调度器):192.168.147.222(vip)、192.168.147.149(DIP,nat)
(4)RS1:192.168.147.150(nat)
(5)RS2:192.168.147.151(nat)
2.配置RS
(1)安装httpd
(2)修改rs的index.html
echo rs1 > /var/www/html/index.html
echo rs2 > /var/www/html/index.html
(3)启动httpd
(4)修改网卡配置文件,网关指向192.168.147.148
[root@rs1 yum.repos.d]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 192.168.147.148 0.0.0.0 UG 100 0 0 ens33 192.168.147.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
(5)修改配置文件让rs不会主动对外说明或回应其mac地址,以避免ip地址冲突(因为VIP被配在了3台主机上)
[root@rs1 ~]# echo "1" > /proc/sys/net/ipv4/conf/lo/arp_ignore [root@rs1 ~]# echo "1" > /proc/sys/net/ipv4/conf/all/arp_ignore [root@rs1 ~]# echo "2" > /proc/sys/net/ipv4/conf/all/arp_announce [root@rs1 ~]# echo "2" > /proc/sys/net/ipv4/conf/lo/arp_announce
arp_ignore:定义接收到ARP请求时的响应级别 0:默认,只用本地配置的有响应地址都给予响应 1:仅仅在目标IP是本地地址,并且是配置在请求进来的接口上的时候才给予响应 (仅在请求的目标地址配置请求到达的接口上的时候,才给予响应) arp_announce:定义将自己的地址向外通告时的级别 0:默认,表示使用配置在任何接口的任何地址向外通告 1:尽量仅向目标网络通告与其网络匹配的地址 2:仅向与本地接口上地址匹配的网络进行通告
(6)配置VIP
[root@rs1 ~]# ip a a 192.168.147.222/24 dev ens33
[root@rs1 ~]# 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: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:4b:2e:b7 brd ff:ff:ff:ff:ff:ff
inet 192.168.147.150/24 brd 192.168.147.255 scope global noprefixroute ens33
valid_lft forever preferred_lft forever
inet 192.168.147.222/24 scope global secondary ens33
valid_lft forever preferred_lft forever
inet6 fe80::cdc6:b11:e8e:9540/64 scope link noprefixroute
valid_lft forever preferred_lft forever
3.配置DS
(1)安装ipvsadm
yum -y install ipvsadm
(2)配置VIP
ip a a 192.168.147.222/24 dev ens33
(3)添加策略
ipvsadm -A -t 192.168.147.222:80 -s rr
ipvsadm -a -t 192.168.147.222:80 -r 192.168.147.150 -g
ipvsadm -a -t 192.168.147.222:80 -r 192.168.147.151 -g
[root@ds ~]# 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.147.222:80 rr -> 192.168.147.150:80 Route 1 0 0 -> 192.168.147.151:80 Route 1 0 0
(4)修改网卡配置文件,网关指向192.168.147.148
4.检验测试
[root@client ~]# curl 192.168.147.222 rs2 [root@client ~]# curl 192.168.147.222 rs1