Session sharing Scheme for production -tomcat
After deploying the Nginx+tomcat cluster,nginx uses load-balanced rotation mode, where each tomcat application will overwrite each other SessionID, causing SessionID is constantly changing, causing Some Java functionality to be implemented abnormally. The author has consulted a number of documents, and in the test environment and pre-production environment for various types of testing, there are two methods feasible.
should be for the purpose just to achieve session sharing, to eliminate the session constantly changing, so the simpler the better, this article belongs to the practice document, not too much involved in the principle and technical aspects of the East, Google has detailed related technical introduction.
1 Introduction to the experimental environment1. CentOS 6.52. jdk1.6_3.83. apache-tomcat-6.0.352 based onTomcatof the clusterSessionshared
Tomcat each node of the cluster is created by TCP Link to complete Session copy , detailed explanation of the details can be Google simpletcpcluster. The author in the experiment is that the simplest configuration for success is:
1. Configuration Steps
in the {Tomcst_home}/conf/server.xml
Cancel the following code comment:
<clusterclassname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
For a complete cluster configuration, you can see the following articles:
http://zyycaesar.iteye.com/blog/296606
http://my.oschina.net/fenno/blog/111188
2. Summary of advantages and disadvantagesAsimple configuration, can meetSessionthe sharedb confined to the network environment, ifTomcatThe server is not on the same network segment and is likely to fail with a full configurationTomcatcluster, and will involveTcpnetwork transmission, resulting in increased system complexity, which increases the complexity of troubleshooting. 3 based onMemcachedStorageSessionshared
because of the Tomcat-based session sharing, the test environment with the network segment is easy to implement, but the production environment across the network segment resulting in a simple configuration can not be achieved, the completion of configuration is not conducive to future operations and troubleshooting, and based on memcached storing session sharing is a good alternative.
1. Configuration StepsAWhat you need in the downloadJarpackage, this is in the repeated test, confirmed the need for the full version of theJarPackage,:Http://code.google.com/p/memcached-session-manager/wiki/SetupAndConfigurationThere are Daniel translations into Chinese:http://chenzhou123520.iteye.com/blog/1650212
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6F/87/wKioL1WfQ5mAdiUbAAE_aXpnJmI756.jpg "title=" 001. PNG "alt=" wkiol1wfq5madiubaae_axpnjmi756.jpg "/>
Note that it is recommended that you first carefully read the above link in the document, pay special attention to Tomcat7,tomcat8, the downloaded jar package is different, the author before reading the official document, First look at the relevant documents of Baidu, the results found that the various documents referenced by the jar are different, completely can not be implemented, when the tomcat boot due to the jar package causes, resulting in an error:
java.lang.reflect.invocationtargetexception at SUN.REFLECT.NATIVEMETHODACCESSORIMPL.INVOKE0 (Native method) at sun.reflect.nativemethodaccessorimpl.invoke (nativemethodaccessorimpl.java:39) atsun.reflect.delegatingmethodaccessorimpl.invoke (DELEGATINGMETHODACCESSORIMPL.JAVA:25) at java.lang.reflect.method.invoke (Method.java:597) at org.apache.catalina.startup.bootstrap.start (Bootstrap.java:289) at org.apache.catalina.startup.bootstrap.main (Bootstrap.java:414) caused by: java.lang.abstractmethoderror Atorg.apache.catalina.core.StandardContext.start (standardcontext.java:4714) at org.apache.catalina.core.containerbase.start (Containerbase.java:1057) at Org.apache.catalina.core.StandardHost.start (standardhost.java:840) at org.apache.catalina.core.containerbase.start (containerbase.java:1057) at org.apache.catalina.core.standardengine.start (standardengine.java:463) atorg.apache.catalina.core.standardservice.start (standardservice.java:525) atorg.apache.catalina.core.standardserver.start (StandardServer.java:754) at org.apache.catalina.startup.catalina.start (Catalina.java:595) ... 6 more
Finally, using the official jar package, the final test is successful and the build must be aware of the jar package.
b Configuration{Tomcst_homer}/conf/context.xml
Add the following statement to the <Context> tab:
<managerclassname= " De.javakaffee.web.msm.MemcachedBackupSessionManager " memcachednodes= "You_memcache_addr:port" requesturiignorepattern= ". *\. (ICO|PNG|GIF|JPG|CSS|JS) $ " transcoderfactoryclass= "De.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory" />
The above scheme is based on sticky sessions + kryo, Sticky session Management , because production is not used memcached cluster, so the changes have been made, you can also be based on their own production structure, the appropriate adjustment.
This article is from the "Ops Road" blog, please be sure to keep this source http://vekergu.blog.51cto.com/9966832/1672833
Session sharing scheme for production-tomcat