我目前正在开发一个websocket应用程序,部署在Tomcat服务器上。由于用户数量巨大,我希望将工作负载分配到多个Tomcat实例中。我决定使用Apache进行负载平衡。
现在我在实现Apache负载平衡和websockets请求的黏性会话时遇到了问题。这是我的Apache配置:
现在我在实现Apache负载平衡和websockets请求的黏性会话时遇到了问题。这是我的Apache配置:
ProxyRequests off
SSLProxyEngine on
RewriteEngine On
<Proxy balancer://http-localhost/>
BalancerMember https://mcsgest1.desy.de:8443/Whiteboard/ route=jvm1 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
BalancerMember https://mcsgest1.desy.de:8444/Whiteboard/ route=jvm2 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
ProxySet lbmethod=byrequests
ProxySet stickysession=JSESSIONID|sid scolonpathdelim=On
</Proxy>
<Proxy balancer://ws-localhost/>
BalancerMember wss://mcsgest1.desy.de:8443/Whiteboard/ route=jvm1 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
BalancerMember wss://mcsgest1.desy.de:8444/Whiteboard/ route=jvm2 keepalive=On smax=1 connectiontimeout=10 retry=600 timeout=900 ttl=900
ProxySet lbmethod=byrequests
ProxySet stickysession=JSESSIONID|sid scolonpathdelim=On
</Proxy>
RewriteCond %{HTTP:Upgrade} =websocket
RewriteRule /jddd/(.*) balancer://ws-localhost/$1 [P,L]
ProxyPassReverse /jddd/ balancer://ws-localhost/
RewriteCond %{HTTP:Upgrade} !=websocket
RewriteRule /jddd/(.*) balancer://http-localhost/$1 [P,L]
ProxyPassReverse /jddd/ balancer://http-localhost/
第一个https请求被平衡到8443端口。升级后的wss请求也被转发到了8443端口。
第二个https请求包含第一个请求的sessionID: https://...&sid=C28C13EEEC525D203F8CA4E827605E0B.jvm1
根据Apache日志文件,我可以看到该sessionID被用于stickySession:
第二个https请求仍然在8443端口,但升级到websocket协议后,ws-balancer不会评估sessionID并重写到8444:...为stickysession sid找到值C28C13EEEC525D203F8CA4E827605E0B.jvm1
...找到路由jvm1
...balancer://http-localhost:worker(htttps://mcsgest1.desy.de:8443/Whiteboard/)被重写为htttps://mcsgest1.desy.de:8443/Whiteboard//?file=octocenter.xml&address=///&sid=C28C13EEEC525D203F8CA4E827605E0B.jvm1
我需要在Apache配置中更改什么以启用wss协议的stickysession?我真的需要两个负载均衡器(http和ws)才能获得websocket平衡吗?...balancer://ws-localhost: worker (wss://mcsgest1.desy.de:8444/Whiteboard/)被重写为 wss://mcsgest1.desy.de:8444/Whiteboard//whiteboardendpoint
<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
。 - user1516873