Redis implements Nginx+Tomcat to configure load balancing session sharing on the windows platform (2)

The previous article implements Nginx+Tomcat to configure load balancing on the windows platform, but the remaining problem is that the session is not shared. This article is mainly for the supplement of the previous article, using Redis to achieve session sharing.

1. Preparation

I will not go into details about Nginx+Tomcat here, but mainly focus on the instructions for using the new tools and the instructions for the integration method.

Download the new tool:

redis-64.3.0.503.zip, this is the Windows version of redis, after downloading, unzip it and put it in any directory (do not put it in the directory with Chinese), you can use the content in the attachment

redis-desktop-manager-0.8.8.384.exe, this is a redis graphical tool, download and install it in any directory ( do not put it in a directory with Chinese)

 

Add jar packages, these jar packages need to be placed in Tomcat's lib

commons-pool2-2.3.jar

jedis-2.7.2.jar

tomcat-redis-session-manager1.2.jar

 

2. Redis configuration

There is not much configuration in redis, readers can check it online, or check the content of this website http://www.runoob.com/redis/redis-conf.html

Special Note:

2.1, requirepass: This is the redis login password setting, which is disabled by default, and readers can modify it according to the actual situation

2.2, port 6379: This is the default port of redis, the reader can modify it according to the actual situation

 

Startup instructions: In order to better manage redis, the bat processing file is specially written. If the reader uses it, it needs to be modified: " the drive letter where redis is located " and "the directory where redis is located", as shown in the figure after startup.

 

 

 

3. Modify Tomcat

In order to realize the session sharing of Tomcat, it is necessary to modify the context.xml file in Tomcat to make tomcat-redis-session-manager-master as the session manager, and specify the redis address and port at the same time.

 

Add the following configuration to context.xml

<Context>

      <Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />

      <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"

           host="localhost"

           port="6379"

           database="0"

           maxInactiveInterval="60" />

 

</Context>

At the same time, put the above jar in Tomcat's lib and restart Tomcat.

 

4. Test feedback

 After Tomcat restarts successfully, visit http://localhost/test/index.jsp in the browser and observe that the instance changes again, but the session does not change, indicating that the session sharing function has been implemented.



 

 Observe that there is only one session value in redis, and it is the same as the one displayed in the interface.



 

Guess you like

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