Nginx+tomcat+redis Complete Session Sharing

Source: Internet
Author: User
Tags session id

This document records the process of Nginx+redis+tomcat implementing session sharing.

Nginx Installation: http://blog.csdn.net/grhlove123/article/details/47834673

Redis Installation: http://blog.csdn.net/grhlove123/article/details/47783471

Prepare two Tomcat, modify the appropriate port


Name Ip Port Tomcat version Jdk
Tomcat1 10.10.49.23 8080 7.0.40 1.7.0_25
Tomcat2 10.10.49.15 8081 7.0.40 1.7.0_25

Modify nginx.conf Plus:

    Upstream backend {        server 10.10.49.23:8080 Max_fails=1 fail_timeout=10s;        Server 10.10.49.15:8081 Max_fails=1 fail_timeout=10s;    }
Modify the location of the nginx.conf into
    Location/{        root   html;        Index  index.html index.htm;        Proxy_pass http://backend;     }

Start Nginx.

Download Tomcat-redis-session-manager the corresponding jar package, there are three main:

wget https://github.com/downloads/jcoleman/tomcat-redis-session-manager/ Tomcat-redis-session-manager-1.2-tomcat-7-java-7.jar
wget Http://central.maven.org/maven2/redis/clients/jedis/2.5.2/jedis-2.5.2.jar
wget Http://central.maven.org/maven2/org/apache/commons/commons-pool2/2.0/commons-pool2-2.0.jar

Copy to $tomcat_home/lib when download is complete

Modify the Context.xml of two tomcat:

<Context>    <!--Default set of monitored resources--    <WatchedResource>WEB-INF/web.xml< /watchedresource>    <!--Uncomment this to disable session persistence across Tomcat restarts-    <!--    <manager pathname= ""/>    -<!--uncomment this to enable Comet connection tacking (provides Eve NTS on session expiration as well as         WebApp lifecycle)-    <!--    <valve classname= " Org.apache.catalina.valves.CometConnectionManagerValve "/>    -  <valve classname=" Com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve "/>  <manager classname=" Com.orangefunction.tomcat.redissessions.RedisSessionManager "   host=" 10.10.49.20 "   port=" 6379   " database= "0"   maxinactiveinterval= "/></context>"

Put a index.jsp in tomcat/webapps/test.

<%@ page language= "java"%>

Started Tomcat, found an exception: Com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve class could not find

Open three jar packages respectively, do not have this class, the solution can be consulted:

http://blog.csdn.net/qinxcb/article/details/42041023


by visiting http://10.10.49.20/test/


Refresh:

You can see that although server has changed from 1111 to 2222, the session creation time has not changed, which completes the session sharing.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Nginx+tomcat+redis Complete Session Sharing

Related Article

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.