【问题标题】:Dropped WebSocket connection in Rancher's LoadBalancer在 Rancher 的 LoadBalancer 中删除了 WebSocket 连接
【发布时间】:2018-12-23 21:57:54
【问题描述】:

我有一个简单的 WebSocket 连接,从我的浏览器到 Rancher 中的一个服务。 我尝试通过 2 种方式连接到服务:

1) 直接到服务:

browser ---> service

2) 通过 Rancher 的负载均衡器:

browser ---> Load Balancer ---> service

在第一种情况下,一切都很好:建立连接并通过它发送消息。

在第二种情况下,大约 50 秒后连接断开。消息通过连接正确地在两个方向上发送。

是什么原因?

编辑:我在 ws 和 wss 协议上进行了测试。在这两种情况下都有相同的问题。

【问题讨论】:

    标签: websocket rancher


    【解决方案1】:

    Rancher 负载均衡器内部使用 HAProxy,可以根据您的需求进行定制。

    这是一个用于 websockets 的 HAProxy 配置示例:

    global
      maxconn 4096
      ssl-server-verify none
    
    defaults
      mode http
      balance roundrobin
      option redispatch
      option forwardfor
    
      timeout connect 5s
      timeout queue 5s
      timeout client 36000s
      timeout server 36000s
    
    frontend http-in
      mode http
      bind *:443 ssl crt /etc/haproxy/certificate.pem
      default_backend rancher_servers
    
      # Add headers for SSL offloading
      http-request set-header X-Forwarded-Proto https if { ssl_fc }
      http-request set-header X-Forwarded-Ssl on if { ssl_fc }
    
      acl is_websocket hdr(Upgrade) -i WebSocket
      acl is_websocket hdr_beg(Host) -i ws
      use_backend rancher_servers if is_websocket
    
    backend rancher_servers
      server websrv1 <rancher_server_1_IP>:8080 weight 1 maxconn 1024
      server websrv2 <rancher_server_2_IP>:8080 weight 1 maxconn 1024
      server websrv3 <rancher_server_3_IP>:8080 weight 1 maxconn 1024
    

    参考:https://rancher.com/docs/rancher/v1.6/en/installing-rancher/installing-server/basic-ssl-config/#example-haproxy-configuration

    LB 的“Custom haproxy.cfg”部分只能使用相关配置。 看截图:

    这里是 Rancher 中自定义 haproxy 的更多文档的链接:https://rancher.com/docs/rancher/v1.6/en/cattle/adding-load-balancers/#custom-haproxy-configuration

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-10-20
      • 2017-08-26
      • 1970-01-01
      • 2019-10-24
      • 1970-01-01
      • 1970-01-01
      • 2019-10-22
      • 2019-07-19
      相关资源
      最近更新 更多