Tomcat的群集/会话复制无法正确复制
我正在本地计算机上的Tomcat 7上设置群集/复制,以评估它是否与我的环境/代码库一起使用。
建立
我在不同端口上运行的兄弟目录中有两个相同的tomcat服务器。 我有httpd监听另外两个端口并连接到两个tomcat实例作为VirtualHosts。 我可以在配置的端口上访问和交互两个环境; 一切都按预期工作。
tomcat服务器在server.xml中启用了这样的集群:
我将distributable标记添加到web.xml的最开头:
(lots more...)
什么工作
当服务器启动时,它们会记录
Sep 16, 2013 1:44:23 PM org.apache.catalina.ha.tcp.SimpleTcpCluster startInternal INFO: Cluster is about to start Sep 16, 2013 1:44:23 PM org.apache.catalina.tribes.transport.ReceiverBase getBind FINE: Starting replication listener on address:10.0.0.100 Sep 16, 2013 1:44:23 PM org.apache.catalina.tribes.transport.ReceiverBase bind INFO: Receiver Server Socket bound to:/10.0.0.100:4001 Sep 16, 2013 1:44:23 PM org.apache.catalina.tribes.membership.McastServiceImpl setupSocket INFO: Setting cluster mcast soTimeout to 500 Sep 16, 2013 1:44:23 PM org.apache.catalina.tribes.membership.McastServiceImpl waitForMembers INFO: Sleeping for 1000 milliseconds to establish cluster membership, start level:4 Sep 16, 2013 1:44:24 PM org.apache.catalina.tribes.membership.McastServiceImpl waitForMembers INFO: Done sleeping, membership established, start level:4 Sep 16, 2013 1:44:24 PM org.apache.catalina.tribes.membership.McastServiceImpl waitForMembers INFO: Sleeping for 1000 milliseconds to establish cluster membership, start level:8 Sep 16, 2013 1:44:25 PM org.apache.catalina.tribes.membership.McastServiceImpl waitForMembers INFO: Done sleeping, membership established, start level:8
当第二台服务器启动时,第一台服务器会记录
Sep 16, 2013 2:17:30 PM org.apache.catalina.tribes.group.interceptors.TcpFailureDetector messageReceived FINE: Received a failure detector packet:ClusterData[src=org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 0, 0, 100}:4000,{10, 0, 0, 100},4000, alive=112208, securePort=-1, UDP Port=-1, id={118 6 107 -67 88 98 72 95 -73 41 4 -108 58 -5 -127 -41 }, payload={}, command={}, domain={}, ]; id={25 110 120 -2 -25 6 78 -97 -84 -34 2 -11 49 -62 -8 -56 }; sent=2013-09-16 14:17:30.139] Sep 16, 2013 2:17:30 PM org.apache.catalina.tribes.transport.nio.NioReplicationTask remoteEof FINE: Channel closed on the remote end, disconnecting Sep 16, 2013 2:17:30 PM org.apache.catalina.tribes.membership.McastServiceImpl memberDataReceived FINE: Mcast add member org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 0, 0, 100}:4001,{10, 0, 0, 100},4001, alive=1010, securePort=-1, UDP Port=-1, id={82 -45 -109 -56 -110 -5 78 -10 -103 61 -40 -59 -36 -79 104 120 }, payload={}, command={}, domain={}, ] Sep 16, 2013 2:17:30 PM org.apache.catalina.ha.tcp.SimpleTcpCluster memberAdded INFO: Replication member added:org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 0, 0, 100}:4001,{10, 0, 0, 100},4001, alive=1011, securePort=-1, UDP Port=-1, id={82 -45 -109 -56 -110 -5 78 -10 -103 61 -40 -59 -36 -79 104 120 }, payload={}, command={}, domain={}, ]
当一个关闭时,另一个记录
Sep 16, 2013 2:28:05 PM org.apache.catalina.tribes.membership.McastServiceImpl memberDataReceived FINE: Member has shutdown:org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 0, 0, 100}:4001,{10, 0, 0, 100},4001, alive=422279, securePort=-1, UDP Port=-1, id={54 43 17 -9 13 -11 72 -63 -107 -78 -8 65 -21 -77 115 88 }, payload={}, command={66 65 66 89 45 65 76 69 88 ...(9)}, domain={}, ] Sep 16, 2013 2:28:05 PM org.apache.catalina.tribes.group.interceptors.TcpFailureDetector memberDisappeared INFO: Verification complete. Member disappeared[org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 0, 0, 100}:4001,{10, 0, 0, 100},4001, alive=422279, securePort=-1, UDP Port=-1, id={54 43 17 -9 13 -11 72 -63 -107 -78 -8 65 -21 -77 115 88 }, payload={}, command={66 65 66 89 45 65 76 69 88 ...(9)}, domain={}, ]] Sep 16, 2013 2:28:05 PM org.apache.catalina.ha.tcp.SimpleTcpCluster memberDisappeared INFO: Received member disappeared:org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 0, 0, 100}:4001,{10, 0, 0, 100},4001, alive=422279, securePort=-1, UDP Port=-1, id={54 43 17 -9 13 -11 72 -63 -107 -78 -8 65 -21 -77 115 88 }, payload={}, command={66 65 66 89 45 65 76 69 88 ...(9)}, domain={}, ]
所以我知道他们彼此都知道。
最后,当我在jconsole中使用Cluster / Operations MBean尝试将属性“foo”设置为“bar”时,jconsole报告“方法成功调用”,并且服务器日志
Sep 16, 2013 2:30:18 PM org.apache.catalina.ha.tcp.SimpleTcpCluster setProperty WARNING: Dynamic setProperty(foo,value) has been disabled, please use explicit properties for the element you are trying to identify
我不太担心那个错误; 主要包括用于演示setProperty创建日志语句。
什么不起作用
据我所知,我的应用程序中没有复制会话信息。
tomcat管理器仅列出在其监视的服务器上启动的会话,而不是群集中的另一个会话。
我的印象是每当应用程序调用HttpSession.setAttribute时,该属性应该被复制到其他群集节点,我希望会记录一些这样的记录。 我的应用包括以下内容:
public static void saveBillingInfo(IPageContext pageContext, BillingInfo billingInfo) { pageContext.getSession().setAttribute("billingInfo", billingInfo); //etc... }
其中BillingInfo是一个只包含一个字段的Serializable类,一个关于计费信息的HashMap。
当此处理或任何其他行处理时,不会写入任何日志语句,并且我没有看到任何证据表明实际上正在共享会话信息。
欢迎提出任何建议或进一步的问题。
我们有同样的问题。 虽然没有在任何地方记录,但为我解决的问题是将
现在只需从server.xml中的群集组中删除
在server.xml上添加:
并在您的context.xml中:
它对我有用,我正在使用Tomcat 7和Tomcat 8
我们的解决方案是将
标记添加到
元素下的WEB-INF/web.xml
文件中。 不知道为什么这对我们有用而不是OP。
顺便说一句,杰森的解决方案也适用于我们。
如果要为特定部署的应用程序启用群集,可以使用下面的示例
server.xml中
根据Tomcat文档,你需要做这两个中的一个(不是两个):
-
在web.xml
指定以启用群集并使用server.xml中指定的默认
或… -
在context.xml中的应用程序级别添加