1. Implement session sharing in a distributed deployment scenario. Here is my test environment and configuration.
Version 2.Redis 3.0.6 Tomcat version: 7.0 JDK version: 1.7
3. The required jar package and version
Commons-pool-1.3.jar
Jedis-2.0.0.jar
Tomcat-redis-session-manager-1.2-tomcat-7-java-7.jar
4.Reids installation Configuration
Redis uses a master and standby configuration (installed on a single machine, so you need to configure a different port number). The installation directory is as follows:
Redis-3.0.6-master Redis-3.0.6-slave
Where Master is the default configuration. Port good for the default 6379,slave needs to be modified accordingly.
Slave configuration file redis.conf port and SLAVOF
Where port is modified to 6380
Modify the salveof to correspond to the master IP and port.
Slaveof 192.168.2.64 6379
5. Test procedures
The test project is myweb, the login page only shows SessionID, the main code of the page is as follows:
<body>
<%
HttpSession s = request.getsession ();
S.setattribute ("SessionId", S.getid ());
%>
The value to get the session is <%=s.getattribute ("SessionId")%>
</body>
Deploy MyWeb on TOMCAT1 and TOMCAT2, respectively. Where TOMCAT1 port number is 8080,TOMCAT2 port number is 8081
Configuration of 6.Tomcat
A. Modify the port numbers for TOMCAT1 and TOMCAT2, respectively, 8080,8081 for testing.
B. At the same time, you need to copy the required jar package to the Lib under Tomcat. Commons-pool-1.3.jar, Jedis-2.0.0.jar, Tomcat-redis-session-manager-1.2-tomcat-7-java-7.jar
C. Modify the Context.xml file for TOMCAT1 and TOMCAT2. Add support for Redis. In the context, add the following configuration:
<valve classname= "Com.radiadesign.catalina.session.RedisSessionHandlerValve"/>
<manager classname= "Com.radiadesign.catalina.session.RedisSessionManager"
Host= "192.168.2.64"
Port= "6379"
database= "0"
Maxinactiveinterval= "/>"
7. Start the master and slave of Redis, and the TOMCAT1 and TOMCAT2 of Tomcat, respectively. Access TOMCAT1 Displays the SessionID as:
The value to get the session is CCA7E2B7A254323F63658828F9DE2B10
Access TOMCAT2 Displays the SessionID as:
The value to get the session is CCA7E2B7A254323F63658828F9DE2B10
Also look at the SessionID in Redis as:
127.0.0.1:6379> Get CCA7E2B7A254323F63658828F9DE2B10
"\xac\xed\x00\x05w\b\x00\x00\x01t{\xaa\x7fnsr\x00\x0
8. Through the above configuration, to achieve the different Tomcat under the session of the sharing. The front desk can be done by Nginx Proxy, to achieve different tomcat under the switch.
Tomcat under Redis implements session sharing