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