Session sharing of Nginx(1.3.9)+Tomcat(1.7)+Redis(3.0)

Build environment: The IPs of the two virtual machines are: 192.168.1.111, 192.168.1.112, Redis deployed on 192.168.1.111 has jdk1.7, tomcat1.7 installed and configured nginx on 192.168.1.112 (these are all ready to start Build it!)

1. Download tomcat-redis-session-manager-1.2-tomcat-7.jar, commons-pool-1.6.jar, jedis-2.1.0.jar from the Internet

2. Put the above three jar packages under the lib package of tomcat respectively

3. Configure the context.xml in the conf directory of tomcat separately (save the sessionId in redis on 192.168.1.111)

Fourth, configure nginx In the nginx installation directory (that is, when you install nginx./configure --prefix=your nginx directory), the conf/nginx.conf weight represents the weight value (50% chance of being distributed to these two machines respectively) tomcat machine)

5. Create a web project and deploy it to two tomcats respectively, and mark it under the index page (the sessionId is passed from Servlet, I deployed the project to ubuntu, and then modified one of the index.jsp, the rest are the same)  

6. Then start nginx, enter http://192.168.1.111/share/HelloServlet on the browser, the result index.jsp is displayed as shown in the figure above, nginx distributes the request to two tomcats and the sessionId is the same

Seven, look at the value of redis: You can see that the sessionId of accessing different servers is the same, which means that my session sharing is successful.   

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326884573&siteId=291194637