Redis enables Tomcat cluster session sharing

Source: Internet
Author: User
Tags redis server

1. Deploy two Tomcat nodes and use Nginx to implement the cluster (see http://www.cnblogs.com/zhangzhi0556/articles/nginx.html);

2, Redis installation (see http://www.cnblogs.com/zhangzhi0556/articles/redis.html) 3, build a simple Web project, package publish to each Tomcat, Used to test whether the session is really shared (how to build a test project yourself) 4, download open source components Tomcat-redis-session-manager Download method one: https://github.com/jcoleman/ Tomcat-redis-session-manager/downloads (This is an early, unsupported redis3.0 cluster) Download Method II (recommended): https://github.com/ran-jit/ Tomcatclusterredissessionmanager (support for REDIS3 clusters and TOMAT8) is best downloaded from the following address:
https://github.com/ran-jit/TomcatClusterRedisSessionManager/wiki/Tomcat-Cluster-Redis-Session-Manager
You can download the Tomcatredissessionmanager-1.0.zip package and include the required jar packages and configuration files after decompression. As shown below: Commons-logging-1.2.jarcommons-pool2-2.4.1.jarjedis-2.8.0.jarcommons-pool2-2.4.1.jarcommons-logging-1.2.jarredisdata cache.properties 5, copy the above jar package to each Tomcat's Lib directory, and Redisdatacache.properties to the Tomcat conf directory. &NBSP;6, configuration file Modification (1) Modify the Redisdatacache.properties configuration file as follows:# redis hosts ex: 127.0.0.1:6379,  127.0.0.2:6379, 127.0.0.2:6380, ....redis.hosts=192.168.187.131:6379 (Redis server IP and port number) # Redis  passwordredis.password= Redis (password set in Redis configuration file) # set true to enable redis  cluster moderedis.cluster.enabled=false  (2) Add the following two lines to the Tomcat/conf/context.xml file:<valve  Classname= "Com.r.tomcat.session.management.requestsessionhandlervalve"/> <manager classname= " Com.r.tomcat.session.management.requestsessionmanager "/>  (3) Set the session period in Tomcat/conf/web.xml     <session-config>         <session-timeout>60<session-timeout>    <session-config> If the session validity is also configured in the project, it will be subject to the project.  7, start Redis First, and then start Tomcat to access the test project for testing.

Redis for Tomcat cluster 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.