java common service cluster building [3] tomcat session sharing

Posted by xwishmasterx on Fri, 08 Nov 2019 23:33:18 +0100

1. Environmental constraints

  • centos 7 64 bit
  • nginx-1.5.0
  • apache-tomcat-8.5.38

2. Preconditions

  • Complete tomcat cluster building and nginx load balancing https://www.jianshu.com/p/c8aa1a323e3a
  • Decompress apache-tomcat-8.5.38 twice, and divide it into tomcat8180 and tomcat8280
  • Modify the ports of server.xml in tomcat8180 to 8105, 8180 and 8109 respectively
  • Modify the ports of server.xml in tomcat8280 to 8205, 8208 and 8209 respectively

3. Modify tomcat8180/conf/server.xml and tomcat8280/conf/server.xml respectively

Add the following configuration after the sentence < engine name = "Catalina" defaulthost = "localhost" >

<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.MessageDispatchInterceptor"/>
          </Channel>

        <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
                 filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;.*\.jsp"/>          
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
        </Cluster> 

4. Modify the webapps/ROOT/WEB-INF/web.xml under the two folders respectively

Under the web app node, add:

<distributable/>

5. Add index1.jsp under tomcat8180/webapps/ROOT / and tomcat8280/webapps/ROOT /

${pageContext.session.id}

6. Startup Test

In the browser, enter:
http://localhost:8180/index1.jsp
http://localhost:8280/index1.jsp
We will see that the sessionid s of the two are the same. At this point, we have completed the session sharing provided by tomcat.

 

Topics: Database Apache xml Session Tomcat