首页 > 代码库 > Tomcat集群的session复制配置

Tomcat集群的session复制配置

  此处我们采用的是在一台服务器上配置3台Tomcat,为了达到访问任何一台Tomcat都共享session的目的,我们这里采用Tomcat在集群中的session复制,以下是具体的配置

  1、我们将Tomcat复制3份,更改名字为Tomcat1、Tomcat2、Tomcat3,修改每个Tomcat中的Server节点端口分别为8005、8006、8007

1 #Tomcat1
2 <Server port="8005" shutdown="SHUTDOWN">
3 #Tomcat2
4 <Server port="8006" shutdown="SHUTDOWN">
5 #Tomcat3
6 <Server port="8007" shutdown="SHUTDOWN">

  2、修改每个Tomcat的http监听端口为8080、8081、8082,因为是在同一台服务器上,HTTPS的端口也要变,这里我们设置为8443、8444、8445

 1 #Tomcat1
 2 <Connector port="8080" protocol="HTTP/1.1"
 3              connectionTimeout="20000"
 4              redirectPort="8443" />
 5 #Tomcat2
 6 <Connector port="8081" protocol="HTTP/1.1"
 7              connectionTimeout="20000"
 8              redirectPort="8444" />
 9 #Tomcat3
10 <Connector port="8082" protocol="HTTP/1.1"
11              connectionTimeout="20000"
12              redirectPort="8445" />

  3、为了实现集群下的session复制,我们需要打开位于<Engine>节点下的集群配置节点<Cluster>

1 <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

  4、该配置就能够满足一般的要求,这个配置是一个简化的配置,相当于以下的配置,具体的详情可以参见Tomcat集群Cluster实现原理剖析(session复制实现方式)

<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="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"/>
          </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> 

 

Tomcat集群的session复制配置