首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >平衡节点Js - WebSockets的HaProxy配置

平衡节点Js - WebSockets的HaProxy配置
EN

Stack Overflow用户
提问于 2014-08-08 22:21:58
回答 1查看 1.5K关注 0票数 2

我刚刚在我的HaProxy系统上安装了Debian1.6,我想用它来分发WebSocket (WS://)连接。系统正在运行同一WebSocket服务的5个服务器实例;这些实例具有相同的IP地址,但端口不同:

代码语言:javascript
复制
192.168.10.1:801
192.168.10.1:802
192.168.10.1:803
192.168.10.1:804
192.168.10.1:805

我正在寻找一些建议,以创建一个简单的配置文件来侦听端口800上的请求并均匀分布(也许?)在服务器之间。

代码语言:javascript
复制
defaults
    mode http
    # Set timeouts to your needs
    timeout client  5s
    timeout connect 5s
    timeout server  5s

frontend all 0.0.0.0:800
    mode http
    timeout client 120s

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

    acl is_sockjs path_beg /echo /broadcast /close
    acl is_stats  path_beg /stats

    use_backend sockjs if is_sockjs
    use_backend stats if is_stats
    default_backend static


backend sockjs
    # Load-balance according to hash created from first two
    # directories in url path. For example requests going to /1/
    # should be handled by single server (assuming resource prefix is
    # one-level deep, like "/echo").
    balance uri depth 2
    timeout server  120s
    server srv_sockjs1 127.0.0.1:12345
    # server srv_sockjs2 127.0.0.1:9998

backend static
    balance roundrobin
    server srv_static 127.0.0.1:801

backend stats
    stats uri /stats
    stats enable

通过使用上面下载的配置文件,我设法使其正常工作。但对我来说,它看起来太复杂了,一次只接受一个连接。如果有第二个客户端连接,HA代理将断开前一个客户端/第一个客户端的连接,并连接新的/第二个客户端。

EN

回答 1

Stack Overflow用户

发布于 2015-01-19 04:28:46

最简单的方法是为所有的websocket机器定义一个后端,并像这样轮询它们:

代码语言:javascript
复制
frontend ft_web
  bind 192.168.10.1:800 name http
  maxconn 10000
  default_backend bk_web

backend bk_web                      
  balance roundrobin
  server websrv1 192.168.10.1:801 maxconn 10000 weight 10 cookie websrv1 check
  server websrv2 192.168.10.1:802 maxconn 10000 weight 10 cookie websrv2 check
...

如果没有帮助,看起来你的超时太短了,试着像这样定义它们:(在默认情况下)

代码语言:javascript
复制
 timeout client          25s
  timeout connect          5s
  timeout server          25s
# timeout tunnel available in ALOHA 5.5 or HAProxy 1.5-dev10 and higher
  timeout tunnel        3600s
  timeout http-keep-alive  1s
  timeout http-request    15s
  timeout queue           30s
  timeout tarpit          60s
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25205693

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档