HAproxy不从虚拟IP路由

时间:2016-07-12 23:39:11

标签: haproxy virtual-ip-address keepalived

我目前正在尝试将HAProxy配置为使用虚拟IP在两台服务器之间路由。

为了测试,我创建了两个实例172.16.4.130和172.16.4.131。然后我使用keepalived创建一个172.16.4.99的虚拟IP地址,它将桥接两个服务器。这两个服务器都运行apache2,它托管一个简单的index.html登陆页面进行测试。所有这些都在运行。

当我转到172.16.4.99时,页面没有加载,也没有重定向到任何一个index.html页面。但是,我可以ping这个IP地址。我觉得这是一个简单的配置问题,因为我对HAproxy不是很有经验,所以我想要一些帮助。下面是我的haproxy.cfg文件,以及keepalived。

global
    log 127.0.0.1   local0
    log 127.0.0.1   local1 notice
    #log loghost    local0 info
    maxconn 4096
    #debug
    #quiet
    user haproxy
    group haproxy

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    retries 3
    option redispatch
    maxconn 2000
    contimeout      5000
    clitimeout      50000
    srvtimeout      50000

listen webfarm 172.16.4.99:80
   mode http
   stats enable
   stats auth user:password
   balance roundrobin
   cookie JSESSIONID prefix
   option httpclose
   option forwardfor
   option httpchk HEAD /check.txt HTTP/1.0
   server webA 172.16.4.130:8080 cookie A check
   server webB 172.16.4.131:8080 cookie B check

keepalived.conf on 172.16.4.130

vrrp_script chk_haproxy {           # Requires keepalived-1.1.13
    script "killall -0 haproxy"     # cheaper than pidof
    interval 2                      # check every 2 seconds
    weight 2                        # add 2 points of prio if OK
}

vrrp_instance VI_1 {
    interface eth0
    state MASTER
    virtual_router_id 51
    priority 101                    # 101 on master, 100 on backup
    virtual_ipaddress {
        172.16.4.99
    }
    track_script {
        chk_haproxy
    }
}

keepalived.conf on 172.16.4.131:

vrrp_script chk_haproxy {           # Requires keepalived-1.1.13
    script "killall -0 haproxy"     # cheaper than pidof
    interval 2                      # check every 2 seconds
    weight 2                        # add 2 points of prio if OK
}

vrrp_instance VI_1 {
    interface eth0
    state MASTER
    virtual_router_id 51
    priority 100                    # 101 on master, 100 on backup
    virtual_ipaddress {
        172.16.4.99
    }
    track_script {
        chk_haproxy
    }
}

1 个答案:

答案 0 :(得分:1)

我已经为MYSQL的平衡事务做了类似的结构。我可以到达虚拟IP后面的MYSQL服务器。也许我的配置会帮助你。

https://serverfault.com/questions/857241/haproxy-dont-balancing-requests-between-nodes-of-galera-cluster

如果对你有所帮助,那就更有意义了。