Tomcat 不复制会话属性

Tomcat 不复制会话属性

我正在努力配置 Tomcat 集群中的会话复制。Ramki 的文章Tomcat Clustering 帮了我大忙。负载平衡和粘性会话运行良好。

会话 ID 已复制,但仅复制 ID。会话属性未复制,它们仅在主节点上更改。缺少完整会话的 Apache Tribes 复制。

我的环境:Oracle Linux 6.6、Tomcat 8.0.20、JRE 7u55-b13

Apache httpd.conf

LoadModule    jk_module  modules/mod_jk.so
JkWorkersFile conf/workers.properties

JkLogFile     logs/mod_jk.log
JkLogLevel    emerg
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions     +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat     "%w %V %T"

JkMount /status stat
JkMount /* balancer

JkMount /uzel1* uzel1
JkMount /uzel2* uzel2
JkMount /uzel3* uzel3

工人.属性

worker.list=balancer,stat

worker.uzel1.type=ajp13
worker.uzel1.port=8021
worker.uzel1.host=localhost
worker.uzel1.lbfactor=10

worker.uzel2.type=ajp13
worker.uzel2.port=8022
worker.uzel2.host=localhost
worker.uzel2.lbfactor=10

worker.uzel3.type=ajp13
worker.uzel3.port=8023
worker.uzel3.host=localhost
worker.uzel3.lbfactor=10

worker.balancer.type=lb
worker.balancer.balance_workers=uzel1,uzel2,uzel3

worker.stat.type=status

Tomcat1(uzel1)server.xml(其他节点使用增加的端口号,例如 8022、4001 等)

<Connector port="8021" protocol="AJP/1.3" redirectPort="8441" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="uzel1">
    <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="224.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"/>
      <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
    </Cluster>

当新的会话被创建时,这将被登录uzel1/catalina.out

12-Mar-2015 15:56:53.540 FINE [ajp-nio-8021-exec-1] org.apache.catalina.ha.session.DeltaManager.sendCreateSession Manager [localhost#] send new session (6BB91945986B0B389849887109F97864.uzel1)
12-Mar-2015 15:56:53.542 FINE [ajp-nio-8021-exec-1] org.apache.catalina.ha.session.DeltaManager.createSession Created a DeltaSession with Id [6BB91945986B0B389849887109F97864.uzel1] Total count=1
12-Mar-2015 15:56:53.547 FINE [ajp-nio-8021-exec-1] org.apache.catalina.ha.session.DeltaManager.requestCompleted Manager [localhost#]: create session message [6BB91945986B0B389849887109F97864.uzel1] delta request.

Tomcat2 将其写入uzel2/catalina.out

12-Mar-2015 15:56:53.545 FINE [Tribes-Task-Receiver-5] org.apache.catalina.ha.session.DeltaManager.messageReceived Manager [localhost#]: Received SessionMessage of type=(SESSION-MODIFIED) from [org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 0, 1, 61}:4001,{10, 0, 1, 61},4001, alive=193202, securePort=-1, UDP Port=-1, id={67 84 5 -55 -55 -93 72 -27 -88 19 109 68 117 4 -82 56 }, payload={}, command={}, domain={}, ]]
12-Mar-2015 15:56:53.546 FINE [Tribes-Task-Receiver-5] org.apache.catalina.ha.session.DeltaManager.handleSESSION_CREATED Manager [localhost#]: received session [6BB91945986B0B389849887109F97864.uzel1] created.
12-Mar-2015 15:56:53.554 FINE [Tribes-Task-Receiver-6] org.apache.catalina.ha.session.DeltaManager.messageReceived Manager [localhost#]: Received SessionMessage of type=(SESSION-DELTA) from [org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 0, 1, 61}:4001,{10, 0, 1, 61},4001, alive=193202, securePort=-1, UDP Port=-1, id={67 84 5 -55 -55 -93 72 -27 -88 19 109 68 117 4 -82 56 }, payload={}, command={}, domain={}, ]]
12-Mar-2015 15:56:53.555 FINE [Tribes-Task-Receiver-6] org.apache.catalina.ha.session.DeltaManager.handleSESSION_DELTA Manager [localhost#]: received session [6BB91945986B0B389849887109F97864.uzel1] delta.

因此第二个节点知道有新会话。但是,它不会复制它。

在端口 4001-4003 处未捕获任何 TCP 数据包

#tcpdump -nnq dst port 4001 or dst port 4002 or dst port 4003 

您知道应该检查、丢弃和检验什么吗?

任何帮助都将不胜感激!

狮子座

答案1

解决了!

有两个问题

  • 错误示例应用:Ramki 的例子index.jsp 不支持会话状态复制
  • 集装箱<Manager className="org.apache.catalina.ha.session.DeltaManager"必须从 移动到server.xml$CATALINA_HOME/conf/context.xml如帖子中所述Tomcat 的集群/会话复制无法正确复制

会话复制适用于 Apache Tomcat 示例 servlet SessionExample,可从以下网址访问 http://主机:端口/示例/servlets/servlet/SessionExample

相关内容