NGINX+MEMCACHED+TOMCAT implementation load balancing and session sharing

Source: Internet
Author: User
Tags memcached

How to install is not introduced, their own online search.


Configure Nginx. This is then configured on a CAS single sign-on.

[Java] view plain copy upstream 127.0.0.1 {server 127.0.0.1:18080 weight=2;                     Server 127.0.0.1:28080 weight=2;                   Server 127.0.0.1:8080 weight=3; }
Weight is the weight value, the larger the number, the greater the chance of being visited.


Modify apache-tomcat-6.0.37\conf and apache-tomcat1\conf and apache-tomcat2\ separately conf under the Context.xml and Server.xml files, added in Server.xml:

<engine name= "Catalina" defaulthost= "localhost" jvmroute= "tomcat6" > Jvmroute are respectively modified to correspond to the names, For example, my apache-tomcat-6.0.37 changes to Tomcat6, and APACHE-TOMCAT1 to tomcat61, and so on.


The purpose of setting Jvmroute is to differentiate between the session from that container.


Increased in Context.xml


[Java] view plain copy <manager classname= "De.javakaffee.web.msm.MemcachedBackupSessionManager" memcache dnodes= "n1:localhost:11211" "requesturiignorepattern=". (PNG|GIF|JPG|CSS|JS) $ "sessionbackupasync=" false "sessionbackuptimeout=" transcoderfactoryclass= " De.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory "copycollectionsforserialization=" false "/>
Remember to add three Tomcat, this is the session of Tomcat to the memcached management. From here you can see the dependent jar package. I uploaded the jar, downloaded it and put it in Tomcat's lib. Download here


The configuration is almost done. Write a test project. Under \webapps build a Nginx file Plus, build a index.jsp inside, the contents are as follows:

[Java] view plain copy <%@ page contenttype= "text/html; CHARSET=GBK "%> <%@ page import=" java.util.* "%>

Start Nginx and memcached, then start three Tomcat, visit http://127.0.0.1/nginx/index.jsp, and constantly refresh the page to see if the SessionID is changing, explain the problem. Load balancing and session sharing were successful.


This is not a screenshot, very simple.

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.