3 ways of session sharing in tomcat cluster

The first two need to use memcached or redis to store sessions, and the last one uses terracotta server sharing. 
It is recommended to use redis, not only because it can persist the cached content, but also because the single object it supports is relatively large, and the data types are rich, 
not only for caching sessions, but also for other purposes, killing two birds with one stone. 

1. It is recommended to use the filter method to store 
this method, because it has a wide range of servers, not only limited to tomcat, and the principle of implementation is relatively simple and easy to control. 
You can use memcached-session-filter 
official website: http://code.google.com/p/memcached-session-filter/Official 
introduction: To solve the java web container session sharing in a cluster environment, use filter interceptor and memcached to achieve. It has passed the test on tomcat 6 and websphere 8. The current network has 2,000 concurrent transactions and 11 million daily PVs. 
Session events including create destory and attribute change are not supported for 
the time being. It is very good and small in size, but this stuff needs to be used with spring, and the objects stored in memcached are required to implement the serialization interface of java. As 
you all know, java itself has Serialization performance is also mediocre. 
I simply extended it, no longer relying on spring, and using javolution to achieve serialization, the cached objects are no longer limited. 
I haven't found the implementation of redis for the time being. I will use redis to store my own implementation and use kyro for serialization. The details will be written out separately when I have time. 


2. Use the tomcat session manager method to store 
this method The server can only use tomcat, but there are implementations for memcached and redis on the Internet, just configure it directly. 
Memcached implementation: 
URL: http://code.google.com/p/memcached-session-manager/ 
Modify the context.xml file in the conf directory of tomcat: 
  <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager "    
  memcachedNodes="n1:localhost:11211 n2:localhost:11212"    
  failoverNodes="n2"    
  requestUriIgnorePattern=".*\.(png|gif|jpg|css|js)$"    
  sessionBackupAsync="false"    
  sessionBackupTimeout="100"    
  transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"    
  copyCollectionsForSerialization="false" 


memcached-session-manager-1.3.0.jar 
msm-javolution-serializer-1.3.0.jar 
javolution-5.4.3.1.jar 
memcached-2.4.2.jar 

redis implementation 
: https://github.com/jcoleman /tomcat-redis-session-manager 
also modifies the context.xml file in the conf directory of tomcat: 
<Valve className="com.radiadesign.catalina.session.RedisSessionHandlerValve" /> 
<Manager className="com.radiadesign. catalina.session.RedisSessionManager" 
         host="localhost" 
         port="6379" 
         database="0" 
         maxInactiveInterval="60"/> The 
above is an example of version 1.2, the required jar package: 
tomcat-redis-session-manager -1.2-tomcat-6.jar 
jedis-2.1.0. jar 
commons-pool-1.6.jar 


3. Using the terracotta server to share 
the configuration is a bit complicated. Let's search on the Internet. 

After the above configuration is successful, the front end uses nginx for load balancing, and uses Gzip compression and static file caching at the same time. 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326831016&siteId=291194637