Tomcat Nginx Redis session sharing process diagram

Tomcat Nginx Redis session sharing process diagram

1. Preparation

Middleware: Tomcat, Redis, Nginx

Jar package: commons-pool2-2.4.2.jar, jedis-2.8.0.jar, tomcat-redis-session-manager-2.0.0.jar

2. Configure Tomcat

Multiple Tomacats need to be configured with different port numbers

/lib

Store the jar package in this location

/conf/server.xml

/conf/context.xml

host is the IP address of Redis, port is the port, and database is the database.

Nginx

/conf/nginx.conf

Upstream means the configuration server list. In this example, two tomcats are started, with ports 8080 and 9999 respectively.

proxy_pass means to configure the proxy server.

This configuration means listening to port 80 of the local (192.168.0.113) and forwarding requests to the Tomcat servers at 8080 and 9999 in a round-robin manner.

Redis

Redis does not require any special configuration, just start it.

3. Testing

Start the Redis service, two tomcat servers, and the Nginx server one after another.

Add a mark to the Tomcat startup page to check whether the sessionIds in the two servers are consistent.

/webapps/ROOT/index.jsp:

IV. Results

If you cannot switch to the page corresponding to the port by pressing F5 to refresh the page, it may be due to the browser cache.

Solution: Clear cache and refresh, alt+F5

At this point, you can see that multiple tomcat services are constantly polling, and the sessionId is consistent.

Then use the Redis desktop management tool to view the information:

You can see that the session information has been handed over to Redis for management.

Achieve success.

5. Disadvantages

This method depends on the Tomcat container. If the middleware is replaced with Jetty or other, it will not work.

There is also a better implementation method: Spring Session + Redis

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Complete steps for using Nginx+Tomcat for load balancing under Windows
  • Nginx/Httpd reverse proxy tomcat configuration tutorial
  • Nginx/Httpd load balancing tomcat configuration tutorial
  • Build Tomcat9 cluster through Nginx and realize session sharing
  • How to use Docker to build a tomcat cluster using nginx (with pictures and text)
  • Detailed tutorial on how to monitor Nginx/Tomcat/MySQL using Zabbix
  • Implementation of deploying vue project to nginx/tomcat server
  • Nginx+Tomcat high performance load balancing cluster construction tutorial
  • Analysis of the process of implementing Nginx+Tomcat cluster under Windwos

<<:  MySQL uses aggregate functions to query a single table

>>:  Detailed explanation of the use cases of Vue listeners

Recommend

30 excellent examples of color matching in web design

Today, this article has collected 30 excellent cas...

About the correct way to convert time in js when importing excel

Table of contents 1. Basics 2. Problem Descriptio...

Detailed explanation of MySQL binlog usage

binlog is a binary log file that records all DML ...

Mysql inner join on usage examples (must read)

Grammatical rules SELECT column_name(s) FROM tabl...

Docker generates images through containers and submits DockerCommit in detail

Table of contents After creating a container loca...

How to Apply for Web Design Jobs

<br />Hello everyone! It’s my honor to chat ...

Basic usage of wget command under Linux

Table of contents Preface 1. Download a single fi...

How to understand JavaScript modularity

Table of contents 1. Browser support 2. export ex...

Things to note when writing self-closing XHTML tags

The img tag in XHTML is so-called self-closing, w...

JavaScript manual implementation of instanceof method

1. Usage of instanceof instanceof operator is use...

Tips for Mixing OR and AND in SQL Statements

Today, there is such a requirement. If the logged...