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

jdgnovmf  于 2021-06-26  发布在  Mesos
关注(0)|答案(1)|浏览(557)

我有一个运行jupyter网关的容器,它需要两个url来访问http和websocketurl。
例如,在localhost上,这些url是 http://127.0.0.1:8888 以及 ws://127.0.0.1:8888 .
当我用marathon和ssh启动应用程序到运行容器的mesos slave时,我可以使用向jupyter网关发出请求的客户端访问这两个url功能。这说明集装箱里的jupyter网关工作正常。
但是,当我试图通过marathon负载平衡器访问jupyter网关时,我的客户机告诉我它可以访问 http:// url很好,但在尝试连接到 ws:// 我需要能够访问的url。
我相信marathonlb支持转发websockets而不需要额外的配置,所以我不确定问题出在哪里,但我怀疑它可能与我的marathon应用程序标签中的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
lvjbypge

lvjbypge1#

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

"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\u 0和haproxy\u 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。

相关问题