无法使用marathon-lb访问websocket(ws://)url

时间:2017-05-17 00:57:16

标签: websocket jupyter haproxy mesos marathon

我有一个运行jupyter网关的容器,需要两个URL才能访问http和websocket url。

例如,在localhost上,这些网址为http://127.0.0.1:8888ws://127.0.0.1:8888

当我使用marathon启动我的应用程序并将ssh引入运行容器的mesos slave时,我可以使用向jupyter网关发出请求的客户端访问这两个URL功能。这告诉我容器中的jupyter网关工作正常。

但是,当我尝试通过马拉松负载均衡器访问jupyter网关时,我的客户端告诉我它可以到达http://网址但是在尝试连接到ws://网址时会超时我需要能够访问。

我相信marathon-lb支持转发websockets而无需额外配置,因此我不确定问题是什么,但我怀疑它可以在我的马拉松应用程序标签中使用以下haproxy配置。

标签:

HAPROXY_0_MODE=http
HAPROXY_0_PATH=/jupyter-gateway-container-path
HAPROXY_0_VHOST=ourwebsite.com

编辑以添加更多日志:

以下是客户端和服务器日志。服务器是Jupyter网关。客户端是他们在示例存储库中提供的python客户端。您可以看到https://请求从客户端成功通过,并在服务器日志中显示201 POST。但是ws://请求超时。

客户端日志https://请求没问题,但是ws://超时。

  $ python client.py
https://<websitename>.io/7c5e1967-b8e4-4e6d-bb68-80881d7f3de1
ws://<websitename>.io/7c5e1967-b8e4-4e6d-bb68-80881d7f3de1
Created kernel 11e9b48b-d0b9-4419-b13a-205eaee7f2c7. Connect other clients with the following command:
            docker-compose run client --kernel-id=11e9b48b-d0b9-4419-b13a-205eaee7f2c7

ws://<websitename>.io/7c5e1967-b8e4-4e6d-bb68-80881d7f3de1/api/kernels/11e9b48b-d0b9-4419-b13a-205eaee7f2c7/channels
Traceback (most recent call last):
  File "client.py", line 178, in <module>
    IOLoop.current().run_sync(main)
  File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py", line 453, in run_sync
    return future_cell[0].result()
  File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1014, in run
    yielded = self.gen.throw(*exc_info)
  File "client.py", line 125, in main
    ws = yield websocket_connect(ws_req)
  File "/usr/local/lib/python2.7/dist-packages/tornado/gen.py", line 1008, in run
    value = future.result()
  File "/usr/local/lib/python2.7/dist-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
tornado.httpclient.HTTPError: HTTP 599: Timeout

服务器日志收到https请求,没有提及进一步的连接。

[KernelGatewayApp] Jupyter Kernel Gateway at http://0.0.0.0:8888
[KernelGatewayApp] Kernel started: 11e9b48b-d0b9-4419-b13a-205eaee7f2c7
[I 170519 01:12:22 web:1971] 201 POST /7c5e1967-b8e4-4e6d-bb68-80881d7f3de1/api/kernels (10.0.0.173) 35.77ms

1 个答案:

答案 0 :(得分:0)

您很可能遇到了正确检查端口的问题,因此您需要以下内容:

"HAPROXY_0_BACKEND_HTTP_HEALTHCHECK_OPTIONS": "  option  httpchk GET {healthCheckPath}
 HTTP/1.1\\r\\nHost:\\ www\n
  timeout check {healthCheckTimeoutSeconds}s\n",
"HAPROXY_1_BACKEND_HTTP_HEALTHCHECK_OPTIONS": "  option  httpchk GET {healthCheckPath}
 HTTP/1.1\\r\\nHost:\\ www\n
  timeout check {healthCheckTimeoutSeconds}s\n",

请注意HAPROXY_0和HAPROXY_1您需要为应用程序中的每个已定义端口配置它

要让websockets实际运行,您需要确保已确定连接:

acl is_websocket hdr(Upgrade) -i WebSocket
use_backend {backend} if is_websocket

在您的应用程序环境中,您需要按以下方式对其进行配置:

"HAPROXY_HTTP_FRONTEND_ACL": "  acl host_{cleanedUpHostname} hdr(host) -i {hostname}\\r\\n
  use_backend {backend} if host_{cleanedUpHostname}\\r\\n
  acl is_websocket hdr(Upgrade) -i WebSocket\\r\\n
  use_backend {backend} if is_websocket"

另请注意,我确保默认配置仍然可用,因此其他所有内容都可以作为默认配置,但也可以使用websockets。