我目前正在开发一个websocket应用程序,该应用程序部署在Tomcat服务器上。由于用户数量巨大,我想将工作负载分配给多个 Tomcat 实例。我决定使用 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:
正如我在 Apache 日志文件中看到的,这个 sessionID 是针对 StickySession 进行评估的:
...发现粘性会话的值 C28C13EEEC525D203F8CA4E827605E0B.jvm1
席德
...找到路线 jvm1
...balancer://http-localhost: 工作人员
(htttps://mcsgest1.desy.de:8443/Whiteboard/) 重写为
htttps://mcsgest1.desy.de:8443/Whiteboard//?file=octocenter.xml&address=///&sid=C28C13EEEC525D203F8CA4E827605E0B.jvm1
第二个 https 请求仍在端口 8443 上,但升级到 websocket 协议后,ws-balancer 不会评估 sessionID 并重写为 8444:
...balancer://ws-localhost: 工作人员
(wss://mcsgest1.desy.de:8444/Whiteboard/) 重写为
wss://mcsgest1.desy.de:8444/Whiteboard//whiteboardendpoint
我必须在 Apache 配置中更改哪些内容才能为 wss 协议启用粘性会话?我真的需要两个平衡器(http 和 ws)来平衡 websocket 吗?