nginx_tomcat_redis builds a load balancing shared session

Note: All the rack packages used are already in it. The target does not support tomcat8. After querying the source code, it is found that the tomcat 's own rack package is missing. The class RedisSessionManager in the tomcat integrated redis rack package uses the LifecycleSupport class, and the LifecycleSupport class is in The tomcat rack package does not exist, and the environment is currently built based on tomcat 7 .


The structure diagram is as follows:


Here are the steps to use the configuration:

Step 1: Configure the Nginx server

1. Configure the Nginx proxy server, which is mainly used to solve the problem of reverse high concurrency proxy. The version I use is nginx-1.9.5

First enter the conf folder to find nginx.conf, open the configuration as shown below

 

  1.  upstream localhost {
  2.     The #weigth parameter represents the weight, the higher the weight, the greater the probability of being assigned
  3.         server localhost:8080 weight=1;
  4.         server localhost:8081 weight=1;
  5.     }

2. To start the Nginx server, you can directly click the nginx.exe file or enter the directory through the cmd command to start it through the command line

 

Step 2: Configure tomcat

1. In the conf directory, find the server.xml file and configure the port number. Because you need multiple tomcats, you can copy two tomcats, but the port numbers to access are different. First configure the two port numbers 8080 and 8081

It is important to modify one of the ports to prevent port conflicts at startup

2、  配置context.xml,需要加上这行配置,主要用来tomcat和redis第三方架包共享session存储,因为经常会遇到session丢失问题,所以通过redis来存储

这里就要注意了,因为网上很多架包都有问题的,要看清楚自己的tomcat版本

前面的host是redis数据库部署的服务器ip地址,port是端口号,database是哪个数据库,maxInactiveInterval是最大空闲时间

 

第三步:配置redis数据库

1、  配置redis数据库,redis-2.4.5-win32-win64这个版本直接可以使用启动里面的服务即可redis-server.exe

2、  通过客户端插件链接redis可以看到

 

第四步:测试、在tomcat/webapp/root目录下放入一个jsp页面进行测试下

发现sessionid已经是相同的了说明已经共享了,再去redis数据库看看sessionid有没有存入进去

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325341509&siteId=291194637