lvs-dr配置

lvs-dr:direct routing(直接路由) LVS默认类型

1. 实现方式:

  通过为请求报文重新封装一个MAC首部进行转发,源MAC是DRP所在接口的MAC,目标MAC是挑选出的RS的RIP所在接口的MAC地址。;IP首部不会发生变化(源IP为CIP,目标IP始终为VIP);

(1) 确保前端路由器将目标IP为VIP的请求报文一定会发送给Director;
  解决方案:
    1. 在路由器上静态绑定VIP和Director的MAC地址;(Director无法做负载均衡)
    2. 禁止RS响应VIP的ARP请求,禁止RS的VIP进行通告(可通过以下两种方式实现)
      (a) 修改arptables;
      (b) 修改各RS的内核参数,并把VIP绑定在lo(本地环回接口)的别名上;
       需要修改的参数分别为:arp_ignore 及 arp_announce
(2) RS的RIP可以使用私有地址,也可以使用公网地址;
(3) RS跟Director必须在同一物理网络中,RS的网关必须不能指向DIP
(4) 请求报文必须由Director调度,但响应报文必须不能经由Director;
(5) 不支持端口映射;
(6) 各RS可以使用大多数的OS;

lvs-dr(director roting)模型过程:
在各主机(Director,RS)均需配置VIP;因此,要解决地址的冲突问题,目标是让各RS上的VIP不可见,仅用于接收目标地址为VIP的报文,同时可作为响应报文的源地址。
为达到这一目标,有三种解决方案:
(1)在前端的网关接口上静态绑定,需要有路由管理权限
(2)在各RS上使用arptables,添加规则,拒绝自己的VIP向外通告以及响应arp地址解析的请求。
(3)在各RS上修改内核参数,来限制arp响应和通告。

限制响应级别:
  arp_ignore:控制系统在收到外部的arp请求时,是否要返回arp响应
  Define different modes for sending replies in response to received ARP requests that resolve local target IP addresses:
  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
    仅在请求的目标IP在本地主机的接入报文的接口上时,才给予响应。
  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
    只响应目的IP地址为接收网卡上的本地地址的arp请求,并且arp请求的源IP必须和接收网卡同网段。
  3:do not reply for local addresses configured with scope host, only resolutions for global and link addresses are replied
    如果ARP请求数据包所请求的IP地址对应的本地地址其作用域(scope)为主机(host),则不回应ARP响应数据包,如果作用域为全局(global)或链路(link),则回应ARP响应数据包。

  4-7 – reserved
  保留位
  8:do not reply for all local addresses .The max value from conf/{all,interface}/arp_ignore is used when ARP request is received on the {interface}
    所有网络都不响应
限制通告级别:arp_announce
  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. This mode is useful when target hosts reachable via this interface require the source IP address in ARP requests to be part of their logical network configured on the receiving interface. When we generate the request we will check all our subnets that include the target IP and will preserve the source address if it is from such subnet. If there is no such subnet we select source address according to the rules for level 2.
    尽量避免向非本网络通告

  2:Always use the best local address for this target. In this mode we ignore the source address in the IP packet and try to select local address that we prefer for talks with the target host. Such local address is selected by looking for primary IP addresses on all our subnets on the outgoing interface that include the target IP address. If no suitable local address is found we select the first local address we have on the outgoing interface or on all other interfaces, with the hope we will receive reply for our request and even sometimes no matter the source IP address we announce. The max value from conf/{all,interface}/arp_announce is used.
  总是避免
忽略IP数据包的源IP地址,选择该发送网卡上最合适的本地地址作为arp请求的源IP地址。

设计要点:
1、各主机有一个接口即可,但需要在同一物理网络中
2、RIP的网关不能指向DIP,RIP和DIP通常应该在同一网络,但此二者未必会与VIP在同一网络。
3、如果基于内核参数来设定,各RS需要先设置内核参数,再设置VIP及路由。

拓扑结构:

猜你喜欢

转载自blog.51cto.com/11975865/2106368