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

Docker binding fixed IP/cross-host container mutual access operation

Preface Previously, static IPs assigned using pip...

How to set the style of ordered and unordered list items in CSS

In an unordered list ul>li, the symbol of an u...

How to build ssh service based on golang image in docker

The following is the code for building an ssh ser...

How to make a website front end elegant and attractive to users

The temperament of a web front-end website is a fe...

Batch replace part of the data of a field in Mysql (recommended)

Batch replace part of the data of a field in MYSQ...

How to use boost.python to call c++ dynamic library in linux

Preface Recently I started using robot framework ...

Vue button permission control introduction

Table of contents 1. Steps 1. Define buttom permi...

Alibaba Cloud Server Domain Name Resolution Steps (Tutorial for Beginners)

For novices who have just started to build a webs...

JavaScript to achieve the effect of clicking on the self-made menu

This article shares the specific code of JavaScri...

GZIP compression Tomcat and improve web performance process diagram

1. Introduction I recently worked on a project an...

Vue implements fuzzy query-Mysql database data

Table of contents 1. Demand 2. Implementation 3. ...

Detailed explanation of the two modes of Router routing in Vue: hash and history

hash mode (default) Working principle: Monitor th...