This article describes how tomcat uses memcache to solve session sharing. I hope this method will be helpful to you.
1. Description
It mainly uses the memcached-session-manager open-source tomcat plug-in to change the original session storage mechanism of tomcat, and stores the session storage in the distributed cache memcache to achieve session sharing.
2. Download the installation package
Jar packages required by memcache-session-manager on tomcat6
This is to put a zip package of the official msm jar for easy download and use.
Official memcache-session-manager
For memcache download, see install memcache.
3. Environment Description
System: centos 5.x
Required software:
Tomcat-6.0.20
Memcache-session-manager-1.4.0
4. installation and configuration steps
4.1 install memcache
4.2 install tomcat 6 See linux nginx Server Load balancer/image cache + tomcat cluster/session sharing part 2
4.3 install and configure msm
Decompress the downloaded msm-atat6-all-dependence.zip file and copy the extracted jar package to the tomcat6/lib directory.
Modify the tomcat6/conf/context. xml file
Add the following configuration in </WatchedResource>:
<Manager className = "de. javakaffee. web. msm. MemcachedBackupSessionManager"
MemcachedNodes = "n1: localhost: 11211"
RequestUriIgnorePattern = ". *. (png | gif | jpg | css | js) $"
TranscoderFactoryClass = "de. javakaffee. web. msm. serializer. kryo. KryoTranscoderFactory"
/>
Start tomcat and you will find that the log contains the log for initializing the msm. If no exception occurs, the plug-in is successfully installed.
Note: The plug-in packages of tomcat5, tomcat6, and tomcat7 are different. Please read the official memcache-session-manager wiki for details. A Configuration article on the Internet may be the configuration of tomcat5, the session sharing is abnormal after being configured on Tomcat 6.