1. Session retention based on Tomcat's own cluster session mode
1. This experiment is based on running 2 tomcat instances on the same machine for testing
tomcat01: 172.16.68.73:8080
tomcat02: 172.16.68.73:8081
tomcat version: 8.0.51
2.tomcat01 configuration
(1). Modify /usr/local/tomcat01/conf/server.xml to find the registered cluster node, and add the following code after it:
<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=" 172.16.68.73 " --IP address port=" 4000 " --Port 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.ClusterSessionListener"/> </Cluster>
(2). Modify /usr/local/tomcat01/conf/web.xml and add the following code before the last </webapps> of the file
<distributable/> -- add this code
</web-app>
(3). Create a test project test, put /usr/local/tomcat01/conf/web.xml into the project,
#mkdir -p /usr/local/tomcat01/webapps/test/WEB-INF #cp /usr/local/tomcat01/conf/web.xml /usr/local/tomcat01/webapps/test/WEB-INF
Note: In the actual production environment, directly modify the web.xml under the corresponding project, and then add the following code. For example
#vi /usr/local/tomcat/webapps/b2c/web.xml
<distributable/> -- add this code
</web-app>
3.tomcat02 configuration
(1). Modify /usr/local/tomcat01/conf/server.xml to find the registered cluster node, and add the following code after it:
<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=" 172.16.68.73 " --IP address port=" 4001 " -- because it is on the same machine, modify the port to 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.ClusterSessionListener"/> </Cluster>
(2). Modify /usr/local/tomcat02/conf/web.xml and add the following code before the last </webapps> of the file
<distributable/> -- add this code
</web-app>
(3). Create a test project test and put /usr/local/tomcat02/conf/web.xml into the project
#mkdir -p /usr/local/tomcat02/webapps/test/WEB-INF #cp /usr/local/tomcat02/conf/web.xml /usr/local/tomcat02/webapps/test/WEB-INF