lvs+keepalived 使用DR

2月 22, 2019 |

配置keepalived.conf
注意这个设置(负载均衡类型forwarding method)lb_kind DR

  virtual_server 192.168.140.100 1358 {
  delay_loop 6
  lb_algo rr
  lb_kind DR
  persistence_timeout 50
  protocol TCP

  real_server 192.168.14.164 6379 {
    weight 1
  }
}

DR模式下需要仔细验证, 很有可能是你的请求直接从客户端到达了realServer

realServer设置
给lo绑定虚拟IP,这样realServer可以将报文直接返回给客户端
ip addr add 192.168.140.100/32 dev lo label lo:40

net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.ens36.rp_filter = 0

rp_filter:

表示收到IP报文后是否校验源IP是否可达
0:不校验
1:严格校验必须从接收网卡可达
2:松校验, 从任意网卡可达

添加只让route响应VIP的ARP请求
echo 1 > /proc/sys/net/ipv4/conf/lo/arp_ignore
echo 2 >/proc/sys/net/ipv4/conf/lo/arp_announce

arp_ignore表示real server 不要响应VIP的arp 请求
arp_announce 表示发送arp请求时,源ip要填写报文发出的哪个网卡绑定的ip

参考文档
https://www.networks.guru/2018/01/27/creating-a-dummy-interface-on-a-linux-unix-based-systems/
https://www.jianshu.com/p/734640384fda

Posted in: Linux

Comments are closed.