当前位置: 首页 > 面试题库 >

Tomcat的群集/会话复制无法正确复制

轩辕阳焱
2023-03-14
问题内容

我正在本地计算机上的Tomcat 7上设置群集/复制,以评估它是否可与我的环境/代码库一起使用。

建立

我在不同端口上运行的同级目录中有两个相同的tomcat服务器。我已经在其他两个端口上监听了httpd,并作为VirtualHosts连接到了两个tomcat实例。我可以在配置的端口上访问两种环境并与之交互。一切都按预期进行。

Tomcat服务器在server.xml中启用了集群功能:

   <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="auto"
                  port="4001"
                  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"/>
      </Channel>

      <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
             filter=""/>
      <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

      <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                tempDir="/tmp/war-temp/"
                deployDir="/tmp/war-deploy/"
                watchDir="/tmp/war-listen/"
                watchEnabled="false"/>

      <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
      <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
   </Cluster>

并且我在web.xml的开头添加了可分发标签:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
  version="3.0">
  <distributable />

  (lots more...)

</web-app>

在做什么

服务器启动时,它们会记录

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是一个可序列化的类,仅包含一个字段,即有关帐单信息的HashMap信息。

在此行或其他任何行处理过程中,都不会写任何日志语句,并且我看不到任何证据表明会话信息确实在共享。

欢迎任何建议或其他问题。


问题答案:

我们有这个相同的问题。尽管没有任何地方的文档,但是对我来说,解决方法是将 标记从server.xml移到全局context.xml(将其从
…组中移出并移入 组)。一旦做到这一点,一切“神奇地”开始工作。这仅适用于Tomcat 7 …
Tomcat 6可以与您上面描述的设置(以及文档描述的)完美配合。

<Context>
    <Manager className="org.apache.catalina.ha.session.DeltaManager"
             expireSessionsOnShutdown="false"
             notifyListenersOnReplication="true" />
</Context>

现在,只需从server.xml的“群集”组中删除 标记,就可以完成。



 类似资料:
  • 我使用redisson在运行tomcat V8.5的3个tomcat吊舱中复制spring应用程序的tomcat会话。我还在同一个Kubernetes集群中部署了Redis。下面是我的tomcat context.xml配置 我的redisson配置如下: 当我在所有pod上运行我的应用程序和负载平衡请求时,它会为发送到不同pod的每个请求创建一个新的JSESSIONID cookie 这应该验证

  • 我正在实现tomcat会话复制以实现集群之间的负载平衡,但是复制需要会话中的所有对象都是可序列化的。 在集群之前,有很多类不是Serirazable并存储在会话中,我们更改为实现Serilazable,但是随着将来的类的添加,可能会发生这种情况,有人可能会错过序列化,这将导致会话复制时出错。 我在考虑扩展tomcat提供的HttpSession实现并覆盖setAtcm以摄入Serializable

  • 我正在尝试在两个MySQL集群之间使用单个复制通道设置复制。我已经看了mysql.com的文档几次了,但似乎不能让它正常工作。 我遇到的问题是,对未配置为主服务器的SQL节点进行的查询不会复制NDBCLUSTER表的任何INSERT、UPDATE或DELETE查询,然而,当我在作为主服务器的SQL节点上插入、更新或删除一行时,它会很好地复制到其他集群。 我知道复制是设置的,因为如果我在主集群中的任

  • 我需要一种跨不同dropwizard web服务共享会话的方法。在Jetty中,有一种方法可以做到这一点,即使用JDBCSessionManager和jdbcssessionmanager(http://wiki.eclipse.org/Jetty/Tutorial/Session_Clustering). 问题是dropwizard(0.7.1)没有公开所需org.eclipse.jetty.s

  • 本文向大家介绍详解Tomcat集群如何同步会话,包括了详解Tomcat集群如何同步会话的使用技巧和注意事项,需要的朋友参考一下 Tocmat集群中最重要的交换信息就是会话消息,对某个tomcat实例某会话做的更改要同步到集群其他tomcat实例的该会话对象,这样才能保证集群所有实例的会话数据一致。在tribes组件的基础上完成这些工作就相当容易些,tribes是tomcat实现的一个通信框架。 如

  • 问题内容: 我从笔记中发现了两个有关复制数组的示例。 下面给出的第一个示例指出,这不是复制数组的方法。但是,当我尝试运行代码时,它设法将所有值从array1复制到array2。 给出的第二个示例是说复制数组的正确方法。 我的问题是,这两个示例是否适合在编码中应用,还是首选示例2?如果您是我的讲师,那么我将应用示例1。与示例2的方法相比,我将获得更少的评分或完全相同? 问题答案: 第一个示例不复制任