Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Session sharing based on Redis+Tomcat+Nginx

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report