Cause of the incident: A main project "pictures describing beautiful things", and another sub-function is the brand owner's entry function, which is a project separate from the main project. In order to share logged-in user information, session sharing is achieved, two tomcats, one tomcat6, a tomcat7
Realizing session sharing under web project windows system
First step:
Configure the following code in the context.xml files of the two tomcats:
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"memcachedNodes="n1:127.0.0.1:11211"lockingMode="auto"sticky="true"requestUriIgnorePattern=".*/.(ico|png|gif|jpg| css|j s)$"sessionBackupAsync="false"sessionBackupTimeout="100"transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"copyCollectionsForSerialization="true"/>
Step two:
Jar package added under Tomcat6:
Jar package added under tomcat7:
PS: Use memcache to save tomcat session
The main purpose of writing this article is to correct some errors on the Internet.
Prerequisites:
1. memcached is working normally
2. Tomcat is working normally.
1. Installation method and installation package
javolution-5.4.3.1.jar
memcached-2.4.2.jar
memcached-session-manager-1.3.0.jar
msm-javolution-serializer-cglib-1.3.0.jar
msm-javolution-serializer-jodatime-1.3.0.jar
Installation method: Put these packages in /usr/local/tomcat6.0/lib.
2. Edit the tomcat configuration file.
<This is important because most articles on the Internet talk about modifying the configuration in server. At present, it is found that editing the context.xml file can immediately throw the session into memcache. >
# vim /usr/local/tomcat6.0/conf/context.xml <Context> <!-- Add the following content under this field. Please fill in your memcached server ip and port number when entering the node --> <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:10.254.41.197:11211" requestUriIgnorePattern=".*/.(png|gif|jpg|css|js)$" sessionBackupAsync="false" sessionBackupTimeout="100" transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory" copyCollectionsForSerialization="false" /> </Context>
3. How to test?
My current testing method is to implement load balancing through apache's mod_jk (written in a previous article) and enable session replication between tomcats.
The result is that the seesion ID will change the node with each user submission, but the ID will not change.
For example:
ID CFC1ACAC6B0B8C27BEA76919F3A99BF8-n1.tomcat2
The next submission will become: <The node is switched, but the ID remains unchanged>
ID CFC1ACAC6B0B8C27BEA76919F3A99BF8-n1.tomcat1
Combined with the status of memcache: <When I failed to successfully throw the session to memcached, cmd_set was 0>
# perl memcached-tool.pl 10.254.41.197:11211 stats
cmd_get 27
cmd_set 15
get_hits 12
# perl memcached-tool.pl 10.254.41.197:11211 stats
cmd_get 31
cmd_set 17
get_hits 14
I think based on the above judgment, the configuration is successful!