Session replication does not work with tomcat7

In my nginx, I installed upstream and set up a sticky session with:

upstream tomcat { ip_hash; server localhost:XXXX; server localhost:XXXY; server localhost:XXYY; } 

I added the <distributable/> to my web.xml (in all cats)

Add this to my tomcat / conf / server.xml file:

 <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6"> <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="5000" selectorTimeout="100" 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"/> <Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/> </Channel> <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=".*\.gif|.*\.js|.*\.jpeg|.*\.jpg|.*\.png|.*\.htm|.*\.html|.*\.css|.*\.txt"/> <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> 

Add this to my tomcat / conf / context.xml:

 <Manager className="org.apache.catalina.ha.session.BackupManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" mapSendOptions="6"/> 

But now I can enter my application. What happens if all 3 or two instances are started and I log in, I see JSESSIONID e..g xyz234.tomcat1

Now, if I disable tomcat1, it will return me to the login page as tomcat1 is shutting down. I log back in and create a session called tomcat2, meanwhile tomcat1 will return again, my application will return me to the login page. So, I have two problems:

  • I want to stay on the system, even my Tomcat (holding session) goes down.
  • And if this tomcat reappears, I still have to stay.

Note. I use the JSF2 application, so I'm not sure if it has anything to do with it.

+5
source share

Source: https://habr.com/ru/post/1237694/


All Articles