Tomcat DeltaManager集群共享session

在Tomcat集群机器不多的情况下可以使用共享session的方法,5台机器左右没什么问题,共享session会占用网络资源同步数据。
vim /usr/local/tomcat-1/conf/web.xml
必须修改 所有集群内Tomcat都需要修改 加入以下内容

<distributable/>

vim /usr/local/tomcat-1/conf/server.xml

<Engine name="Catalina" defaultHost="www.aaa.com" jvmRoute="tomcatA">  #在此行下加入
<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.1"
                        port="45564"
                        frequency="500"
                        dropTime="3000"/>
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                      address="10.125.192.2"
                      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>

注:集群内server.xml配置文件几乎相同,注意IP地址和jvmRoute改成本地的

配置完成后启动检查
catalina.sh stop
catalina.sh configtest
catalina.sh start

查看端口
lsof -i :4000
查看日志
tailf /usr/local/tomcat/logs/catalina.2019-03-07.log
Manager [www.aaa.com#/webapps], requesting session state from org.apache.catalina.tribes.membership.MemberImpl[tcp://{10, 125, 192, 3}:4000,{10, 125, 192, 3},4000, alive=146807, securePort=-1, UDP Port=-1
, id={57 123 97 -35 -56 -112 74 -106 -82 6 35 100 -2 94 18 -109 }, payload={}, command={}, domain={}, ]. This operation will timeout if no session state has been received within 60 seconds
表示集群创建成功

猜你喜欢

转载自blog.csdn.net/bjgaocp/article/details/88318911