Get the App
SLTechnology News&Howtos  ›  Servers  › 

Session sharing based on Redis+Tomcat+Nginx

Shulou Source: shulou.com Published: 2022-06-03 03:15:20 09月22日 Update

To achieve session sharing, you need to achieve load balancing. Please refer to the previous article: http://doctorcai.blog.51cto.com/1892682/1970913

Introduction to 1.redis and download and installation

Redis is an open source high-performance key-value database with rich key-value storage types and API in multiple languages. Different from the general database, redis uses memory as the main memory, and uses the hard disk to achieve data persistence, and redis periodically writes the data to the hard disk. This means that in the event of a power outage or restart of our server, we are likely to lose data, so it is not recommended to use redis to store critical data. Of course, because redis uses memory to read and write data, its speed is very fast, so it is very suitable for us to store some temporary data.

First download the redis,windows version download address https://github.com/ServiceStack/redis-windows

Redis is installation-free under windows. When the download is complete, unzip it and copy the folder to one of your own disks.

(attached: open the redis configuration file redis.windows.conf, find requirepass 123456 and set the password. I set it to 123456)

Next let's open redis. First open cmd, enter our redis directory, and type redis-server.exe redis.windows.conf. When the following interface appears, it opens successfully. Don't be lazy and want to double-click redis-server.exe to finish, so that although it can be opened, the configuration file will not be loaded.

two。 Download the required jar package

3. Copy the required jar package to the lib directory in the tomcat folder

4. Modify the context.xml under the conf folder in the Tomcat folder

Add the following configuration to the tag:

Port number-- >

Database= "0"

Password= "123456" password is not required-- >

MaxInactiveInterval= "60" / >

5. Start nginx, redis, Tomcat, and open the test page

The test page is divided into Tomcat An and Tomcat B code as follows: (page B is omitted and the content is the same)

Tomcat A

Session ID

Created on

At this point, the sessionID of the two pages is the same, and session sharing has been implemented.

Tags: Data files folders pages configuration memory address password situation database directory hard disk test different balanced successful two temporary main memory host Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MariaDB Apple Linux MySQL