【问题标题】:Getting IP floating right for HAproxy/Keepalived为 HAproxy/Keepalived 获得 IP 浮动权
【发布时间】:2017-06-03 00:06:23
【问题描述】:

这对我来说是全新的。请多多包涵。对不起,如果我没有正确表达我的问题。我想设置 ip 浮动以使用 HAproxy 和 Keepalived。

我有以下 ip:
LB1: 192.168.1.27 #first load balancer
LB2: 192.168.1.32 #second load balancer
www1: 192.168.1.28 #first web server
www2: 192.168.1.29 #second web server
浮动ip: 192.168.1.200

当我关闭负载平衡器 1 (LB1) 时,流量不会重定向到浮动 IP。我不知道要检查什么,这样我才能使整个设置成功运行。我怀疑 LB2 是问题所在(除了我:)),因为当 LB1 关闭时,浮动 ip 无法正常工作。

我还遵循了 '8.0 以下链接中的检查过程部分。验证正确的故障转移”但无济于事: How to create Floating IP and use it to configure HAProxy。 单独来说,只有在 HAproxy 开启时,5 个 ips 才能正常工作。我只能说这些了。

你能帮帮我吗?谢谢。

编辑

我的配置:

在 lb1 上安装 HAPROXY

global
    log 127.0.0.1 local2
    daemon
    stats socket /run/haproxy/admin.sock mode 660 level admin
    stats timeout 30s
    user haproxy
    group haproxy

defaults
    log global
    mode http
    option httplog
    timeout connect 5000
    timeout client 50000
    timeout server 50000
    retries 3
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http

listen stats
    bind :1936
    stats enable
    stats hide-version
    stats realm Loadbalanced\ Servers
    stats uri /haproxy?stats
    stats auth haproxy:haproxy

frontend http-in
    bind *:80
    default_backend webservers

backend webservers
    balance roundrobin
    option httpchk GET /haproxy_check
    stick-table type ip size 20k peers mypeer
    server www1 192.168.1.28:80 cookie LSW_WWW1 check inter 500 fall 3 rise 2
    server www2 192.168.1.29:80 cookie LSW_WWW2 check inter 500 fall 3 rise 2

peers mypeer
    peer lb1hostname 192.168.1.27:1024
    peer lb2hostname 192.168.1.32:1024 backup

HAPROXY 安装在 lb2:

global
    log 127.0.0.1 local2
    daemon
    stats socket /run/haproxy/admin.sock mode 660 level admin
    stats timeout 30s
    user haproxy
    group haproxy

defaults
    log global
    mode http
    option httplog
    timeout connect 5000
    timeout client 50000
    timeout server 50000
    retries 3
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http

listen stats
    bind :1936
    stats enable
    stats hide-version
    stats realm Loadbalanced\ Servers
    stats uri /haproxy?stats
    stats auth haproxy:haproxy

frontend http-in
    bind *:80
    default_backend webservers

backend webservers
    balance roundrobin
    option httpchk GET /haproxy_check
    server www1 192.168.1.28:80 cookie LSW_WWW1 check inter 500 fall 3 rise 2
    server www2 192.168.1.29:80 cookie LSW_WWW2 check inter 500 fall 3 rise 2

保持在 LB1

vrrp_script chk_haproxy {
    script "pidof haproxy"
    interval 2} 
vrrp_instance VI_1 {
    interface eth0
    state MASTER
    virtual_router_id 51
    priority 200
    virtual_ipaddress {
            192.168.1.200
    }
    track_script {
            chk_haproxy
    }}

保持在 LB2 上

vrrp_script chk_haproxy {
    script "pidof haproxy"
    interval 2}

vrrp_instance VI_1 {
    interface eth0
    state BACKUP
    virtual_router_id 51
    priority 100
    virtual_ipaddress {
            192.168.1.200
    }
    track_script {
            chk_haproxy
    }}

在 LB1 和 LB2 上,在 Keepalived 中:

nano /etc/sysctl.conf

已添加net.ipv4.ip_nonlocal_bind=1

sysctl -p

在 lb1 上:

sudo service keepalived alived stop 然后检查 lb2 是否工作。它是!!!但是当 LB1 上的 Haproxy 关闭时,流量仍然不会重定向到 LB2。

【问题讨论】:

    标签: haproxy virtual-ip-address


    【解决方案1】:

    这可能表明故障转移 ip 时 arp 更新有问题,如果浮动 ip 指向 lb2 mac addr,请检查设备上的 arp 表

    【讨论】:

      猜你喜欢
      • 2021-03-30
      • 2014-05-21
      • 2017-08-22
      • 2015-05-31
      • 2017-08-05
      • 1970-01-01
      • 2016-05-30
      • 2021-08-21
      • 2016-02-25
      相关资源
      最近更新 更多