为HAproxy / Keepalived获取正确的IP权限

时间:2017-01-18 14:45:11

标签: haproxy virtual-ip-address

这对我来说都是新的。请多多包涵。对不起,如果我没有正确地说出我的问题。我想设置ip floating以使用HAproxy和Keepalived。

我有以下的ips:
  LB1:192.168.1.27 #first load balancer
  LB2:192.168.1.32 #second负载均衡器
  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。验证正确的故障转移'但无济于事: How to create Floating IP and use it to configure HAProxy。 单独地,5 ips仅在HAproxy打开时才能正常工作。这就是我能说的全部。

你能帮帮我吗?感谢。

修改

我的配置:

在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

在lb2上安装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
    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

on lb1:

sudo service keepalived alived stop 然后检查lb2是否正常工作。它是!!!但是当LB1上的Haproxy停机时,交通仍然没有被重定向到LB2。

1 个答案:

答案 0 :(得分:0)

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