我有一个集群环境,其中Apache2.2.6和mod_proxy通过带有Sticky Sessions的AJP13指向Tomcat7.0.26。
httpd.conf配置如下:
<Proxy balancer://mycluster2>
BalancerMember ajp://192.168.0.1:8009 route=tomcat1
BalancerMember ajp://192.168.0.2:8009 route=tomcat2
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass /MyApp balancer://myCluster2/MyApp stickysession=JSESSIONID
ProxyPassReverse /MyApp https://apache_server/MyApp在我的tomcat server.xml文件中,我已经在<Host>标签内正确地配置了集群(只发布了tomcat1文件,tomcat2是相同的,只是改变了ip):
<Executor name="tomcatThreadPool" namePrefix="catalina-exec-"
maxThreads="150" minSpareThreads="4"/>
<Connector executor="tomcatThreadPool"
port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />..。
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false" notifyListenersOnReplication="true" />
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService" address="228.0.0.4" port="45564" frequency="500" dropTime="3000" />
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="192.168.0.1" port="4000" autoBind="100" selectorTimeout="5000" maxThreads="6" />
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor" />
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter="" />
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve" />
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener" />
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>这种配置在任何jsp webapp中都很有吸引力,它可以复制会话,并通过经典的故障转移步骤测试用例完美地工作在故障转移上:
1.- Tomcat1 starts.
2.- Tomcat2 starts.
3.- A request is processed by the balancer: https://apache_server/MyApp and sent to Tomcat1.
4.- Some operations are performed (i. e. refresh page with a counter as session attribute).
5.- Tomcat1 is killed.
6.- User refresh page and the session counter follows counting in Tomcat2.因此,在这一点上,我很清楚,在apache和Tomcat上都没有错误的配置。那我就选MyApp吧。首先,它在web.xml中有<distributable/>标记。
接下来,我成功地将其部署在Tomcat1和Tomcat2上,并且我看到Tomcat正在为我的应用程序在节点之间多播和共享信息:
INFO: Gestor [/MyApp], requiriendo estado de sesión desde org.apache.catalina.tribes.membership.MemberImpl[tcp://{192, 168, 0, 1}:4000,{192, 168, 0, 1},4000, alive=5113068, securePort=-1, UDP Port=-1, id={-31 113 14 29 99 -58 77 -75 -111 66 -103 86 102 -108 120 61 }, payload={}, command={}, domain={}, ]. Esta operación se agotará si no se recibe estado de sesión dentro de 60 segundos.
19-sep-2013 18:49:51 org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor report
INFO: ThroughputInterceptor Report[
Tx Msg:1 messages
Sent:0,00 MB (total)
Sent:0,00 MB (application)
Time:0,00 seconds
Tx Speed:0,12 MB/sec (total)
TxSpeed:0,12 MB/sec (application)
Error Msg:0
Rx Msg:1 messages
Rx Speed:0,00 MB/sec (since 1st msg)
Received:0,00 MB]
19-sep-2013 18:49:51 org.apache.catalina.ha.session.DeltaManager waitForSendAllSessions
INFO: Gestor [/MyApp]; estado de sesión enviado a las 19/09/13 18:49 recibido en 106 ms.我尝试重现前面提到的导航,我可以在两个节点的Tomcat管理器中看到我的域对象被复制(它们都实现了Serializable)。
由于某些原因,我的JSF com.sun.faces.renderkit.ServerSideStateHelper.LogicalViewMap不能复制所有对象。事实上,在该会话属性中,备份节点始终比主节点少一个对象。
在点6,杀死Tomcat1并刷新页面后,会话没有恢复,用户被送到注销屏幕,使会话无效。
MyApp以前在非集群环境中工作。以下是MyApp web.xml的STATE-SAVING配置
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>即使我尝试从JSF 2.1.4升级到2.1.21,也得到了同样的错误。如果不改变MyApp中的很多东西,我就无法升级到2.2.3 (这是一个生产中的项目,而且是一个很长时间的开发项目,所以在考虑整个项目的重构之前,我必须尝试所有的东西)。
我试着把它也放到我的web.xml中,结果更糟,因为它在LogicalViewMap中复制的对象更少:
<context-param>
<param-name>com.sun.faces.serializeServerState</param-name>
<param-value>true</param-value>
</context-param>我的faces-config.xml没有什么特别之处。
我还试图将JSF升级到2.2.3,但在这种情况下,项目根本无法工作,因为我使用的是Richfaces 4.0.0-final,并且我需要重构更多的代码。
此时,我认为JSF2与Tomcat集群不兼容。有人使用Tomcat集群和JSF2配置了项目吗?
任何帮助都将不胜感激。
发布于 2013-11-16 05:25:42
我也有类似的问题,但是在weblogic环境中。请参阅jsf session failover
希望这能对你有所帮助。
https://stackoverflow.com/questions/18900874
复制相似问题