Tomcat+memcached Implementing session Sharing

Source: Internet
Author: User

In the previous example, I implemented the Tomcat cluster session sharing using Tomcat's official session replication method. Today, I use another way memcached-session-manager to realize Session sharing. Words not much to say, on the example.

Memcached-session-manager serializes the Session to Memcache, with a number of serialized components, such as:

Msm-kryo-serializer,msm-javolution-serializer, etc., used here Msm-javolution-serializer, the jar packages required to use different components are different. Required JAR Packages:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6F/88/wKiom1WfLYixWuTmAAF_-rhGWb8085.jpg "title=" Required jar package. png "alt=" wkiom1wflyixwutmaaf_-rhgwb8085.jpg "/>

If you use MAVEN, these jar packages can be:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6F/85/wKioL1WfL5myLLFFAAOuxfOtnOQ806.jpg "title=" Pom.png "alt=" Wkiol1wfl5myllffaaouxfotnoq806.jpg "/>

In this example, the first 5 jar packages are required because Msm-javolution-serializer is used as a component of the serialization session.

Copy the 5 jar packages into the two Tomcat Lib directories, such as:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6F/89/wKiom1WfLk3gffHdAAZirdLTQD0861.jpg "title=" Tomcat's Lib.png "alt=" Wkiom1wflk3gffhdaazirdltqd0861.jpg "/>

In order to serialize the session to Memcache, you need to change the default Standardmanager of Tomcat

Add the following configuration to the context element of the $catalina_home/conf/context.xml file:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6F/85/wKioL1WfMY6y2kQaAAHVZjP9ch8102.jpg "title=" Context.png "alt=" Wkiol1wfmy6y2kqaaahvzjp9ch8102.jpg "/>

If the Msm-kryo-serializer component is used, the value of the transcoderfactoryclass here should be

De.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory

At the same time, in order to be able to see the Memcached-session-manager output log in the Tomcat console ($CATALINA _home/logs/catalina.out), we $catalina_home/conf/ The last additions to the Logging.properties file are configured as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6F/89/wKiom1WfMJnQZUbvAAAxOf2UU04932.jpg "title=" Logging configuration. png "alt=" wkiom1wfmjnqzubvaaaxof2uu04932.jpg "/>

Server.xml files do not need to be changed

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6F/89/wKiom1WfMRGRp-rjAAhiaLo_myU775.jpg "title=" Server.png "alt=" wkiom1wfmrgrp-rjaahialo_myu775.jpg "/> Since to save the session to Memcache, Memcache is essential, here does not introduce. Start two memcached

Memcached-d-P 11211-u Root

Memcached-d-P 11212-u Root

Also, for load balancing, you need to start Nginx

Service Nginx Start

Finally, start two Tomcat respectively

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6F/89/wKiom1WfMlLzfh2QAAUwydGTBnU574.jpg "title=" Listening port. png "alt=" wkiom1wfmllzfh2qaauwydgtbnu574.jpg "/>

The exciting moment is up, let's see Tomcat's boot log

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/6F/86/wKioL1WfNNeRD4-3AC3oKfXuN4A116.jpg "title=" log. png "alt=" Wkiol1wfnnerd4-3ac3okfxun4a116.jpg "/>

Next, use our previous test as an example to see if it is possible to achieve load balancing +session sharing

The answer is yes, the result is the same as the effect of the previous copy of the session

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M01/6F/89/wKiom1WfNWyRT6chAANE95q7hv8796.jpg "title=" 2015-07-10_110042.png "alt=" Wkiom1wfnwyrt6chaane95q7hv8796.jpg "/>

Finally, take a look at the console

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6F/86/wKioL1WfN1vQaByVABst7WBzLHE463.jpg "title=" View the log. png "alt=" wkiol1wfn1vqabyvabst7wbzlhe463.jpg "/>

Success!


Reference:

http://my.oschina.net/smallsun512/blog/164107

Http://www.tuicool.com/articles/VZz6bm
http://chenzhou123520.iteye.com/blog/1650212

http://www.iteye.com/topic/1125301

Http://blog.chinaunix.net/uid-26719405-id-4683071.html


This article is from the "ten-li Rice flower" blog, please be sure to keep this source http://5880861.blog.51cto.com/5870861/1672825

Tomcat+memcached Implementing session Sharing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.