在上图的DR模型中,所有机器(包括Director)都配置了一个额外的IP地址,即vip
该模型需要解决一下几个问题
1、当一个客户client上VIP发去一个连接请求是,此请求必须要连接到Director的VIP上,而不是real server上的lo:0的,因为LVS主要目的就是要Director负责调度这些连接请求到real server上,所以到ARP广播请求时,仅将Director的MAC地址响应给client就可以了。
解决此问题,
(1)可以再路由器上做静态的mac-ip绑定、或arp地址过滤。
(2)在本地的linux主机上通过arp_ignore、arp_announce来解决。
在这我们就用第二种方法来解决。
关于arp_ignore、arp_announce在linux的2.4和2.6的版本中以引入。
Arp_announce --arp宣告 有3个值
0 - (default) Use any local address, configured on any interface.
1 - Try to avoid local addresses that are not in the target's subnet for this interface.
2 - Always use the best local address for this target. --自己与arp请求的目标ip地址不符,不回答。
Arp_ignore --arp忽略 有8个值
0 - (default): reply for any local target IP address, configured on any interface.
1 - reply only if the target IP address is local address configured on the incoming interface. --仅响应与本地的进接口一致的请求
2 - reply only if the target IP address is local address configured on the incoming interface and both with the sender's IP address are part from same subnet on this interface.
3 - do not reply for local address configured with scope host,only resolutions for golbal and link addresses are replied.
4-7 - reserved
8 - do not reply for all local addresses
2、real server必须要有与director的VIP一样的ip地址,即可以配置Looback地址
3、Real server 必须要有到client的路由
安装ipvsadm
yum -y install ipvsadm
添加规则使Director成为虚拟的web服务
Ipvsadm -A -t 192.168.2.1:80 -s rr
指明后方的real server
Ipvsadm -a -t 192.168.2.1:80 -r 192.168.2.100 -g (默认就是-g 即DR)
Ipvsadm -a -t 192.168.2.1:80 -r 192.168.2.200 -g
service ipvsadm save
service ipvsadm start
chkconfig ipvsadm on