无法使用Marathon-lb访问websocket(ws://)网址 [英] Can't access websocket (ws://) url using marathon-lb
问题描述
我有一个运行jupyter网关的容器,该容器需要两个URL才能访问http和websocket URL.
I have a container running a jupyter gateway which requires two urls to be accessible a http and websocket url.
例如,在localhost上,这些URL是http://127.0.0.1:8888
和ws://127.0.0.1:8888
.
On localhost, for example, these urls are http://127.0.0.1:8888
and ws://127.0.0.1:8888
.
当我使用马拉松程序和ssh进入运行容器的mesos从属服务器启动我的应用程序时,我可以使用向jupyter网关发出请求的客户端来访问这两个url功能.告诉我容器中的jupyter网关工作正常.
When I start my app with marathon and ssh into the mesos slave running the container I can access both of these urls functionality using my client that makes requests to the jupyter gateway. Which tells me the jupyter gateway in the container is working fine.
但是,当我尝试通过马拉松负载平衡器访问jupyter网关时,我的客户端告诉我它可以正常访问http://
网址,但是在尝试连接到我需要的ws://
网址时会超时能够访问.
However when I am trying to access the jupyter gateway through the marathon load balancer my client tells me it can reach the http://
url fine but it times out when trying to connect to the ws://
url which I need to be able to access.
我相信marathon-lb支持转发网络套接字而无需额外配置,因此我不确定问题出在哪里,但我怀疑它可以与我的马拉松应用标签中的以下haproxy配置有关.
I believe marathon-lb supports forwarding websockets without extra configuration so I am not sure what the issue is but I suspect it could do with the following haproxy config in my marathon app labels.
标签:
HAPROXY_0_MODE=http
HAPROXY_0_PATH=/jupyter-gateway-container-path
HAPROXY_0_VHOST=ourwebsite.com
编辑以添加更多日志:
下面是客户端和服务器日志.服务器是Jupyter网关.客户端是他们在示例存储库中提供的python客户端.您可以看到客户端成功完成了https://请求,并且在服务器日志中显示了201 POST.但是ws://请求超时.
Below are the client and server logs. The server is the Jupyter gateway. The client is the python client they provide in the examples repository. You can see that a https:// request goes through successfully from the client and it shows a 201 POST in the server's log. But the ws:// request times out.
客户端日志https://请求可以,但ws://超时.
Client log https:// request is fine but ws:// times out.
$ 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请求,没有提及其他连接.
Server log recieves https request ok, no mention of further connections.
[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
推荐答案
很可能您遇到了对端口进行正确检查的问题,因此您将需要以下内容:
Most likely you ran into an issue of having the correct check for the ports therefore you'll need something like the following:
"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
Notice the HAPROXY_0 and HAPROXY_1 you'll need to configure it for each defined port in your application
要使Websocket实际运行,您需要确保已识别连接:
To have the websockets actually running you'll need to make sure that the connection is identified:
acl is_websocket hdr(Upgrade) -i WebSocket
use_backend {backend} if is_websocket
在您的应用程序上下文中,您需要按以下方式对其进行配置:
In the context of your application you'll need to configure it like the following:
"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一起使用.
Also note here, I made sure the default configuration is still available so everything else works as the default but also with websockets.
这篇关于无法使用Marathon-lb访问websocket(ws://)网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!