0

我正在尝试使用 HAProxy 对 socket.io 请求进行负载平衡。以下是我的配置:

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        timeout connect 5000
        timeout client  50000
        timeout server  50000

frontend all 0.0.0.0:8888
    mode http
    timeout client 120s

    option forwardfor
    # Fake connection:close, required in this setup.
    option http-server-close
    option http-pretend-keepalive

    acl is_socketio path_beg /socket.io

    use_backend socket-servers if is_socketio
    default_backend http-servers


backend http-servers
    balance roundrobin
    option httpclose
    option forwardfor

    # Roundrobin switching
    server node-1 172.14.2.25:8887 check
    server node-2 172.14.2.28:8887 check


backend socket-servers
    mode http
    timeout server  120s
    balance roundrobin
    # based on cookie set in header
    # haproxy will add the cookies for us
    option forwardfor
    cookie SERVERID insert indirect nocache
    server node1 172.14.2.25:8887 cookie node1 weight 1 maxconn 1024 check
    server node2 172.14.2.28:8887 cookie node2 weight 1 maxconn 1024 check

当我尝试创建套接字连接时,此配置会超时。

但是,如果我删除最后两行中的任何一个 [ server node1 172.14.2.25:8887 cookie node1 weight 1 maxconn 1024 checkserver node2 172.14.2.28:8887 cookie node2 weight 1 maxconn 1024 check ],套接字连接正确。

我不明白配置有什么问题。任何帮助将不胜感激。

蒂亚:)

4

1 回答 1

1

后端 socket-servers的配置中,我不得不将 balance roundrobin 更改为balance source。那行得通!:)

于 2016-06-02T07:49:11.230 回答