JDK1.8 + + Tomcat9 + Redis + Redisson实现session共享

方案 01/08 阅读 137 views次 人气 0
摘要:

通过nginx反向代理,实现Tomcat集群。需要实现Tomcat应用中的Session共享的问题,通过Redis来实现的session共享较为简单。

集群.png


Nginx、Tomcat相关配置,参考:

http://www.what21.com/sys/view/webserver_n_1456896357046.html

http://www.what21.com/sys/view/webserver_n_1456896358052.html

http://www.what21.com/sys/view/webserver_n_1456896357548.html


http://www.what21.com/sys/view/service_web-app_1456896347318.html


Tomcat9 + Redis + Redisson,百度网盘下载:

链接:https://pan.baidu.com/s/1ghd6J4JKT2NscPciDlLV2A 

提取码:egvv 


具体参数配置可参考:

https://github.com/redisson/redisson/tree/master/redisson-tomcat

https://github.com/redisson/redisson/blob/dfcf183fb99e2718a748148942926256f650ee24/redisson-tomcat/README.md

https://github.com/redisson/redisson/wiki/2.-Configuration#26-single-instance-mode

https://github.com/redisson/redisson/wiki/2.-Configuration


Tomcat9配置,%tomcat_home%/conf/context.xml:

<Manager className="org.redisson.tomcat.RedissonSessionManager"
          configPath="${catalina.base}/conf/redisson.conf" readMode="MEMORY" updateMode="DEFAULT"/>


拷贝jar包到tomcat下,%tomcat_home%/lib/:

redisson-all-3.10.0.jar、redisson-tomcat-9-3.10.0.jar


Redisson配置,%tomcat_home%/conf/redisson.conf:

{
   "singleServerConfig":{
      "idleConnectionTimeout":10000,
      "pingTimeout":1000,
      "connectTimeout":10000,
      "timeout":3000,
      "retryAttempts":3,
      "retryInterval":1500,
      "password":null,
      "subscriptionsPerConnection":5,
      "clientName":null,
      "address": "redis://127.0.0.1:6379",
      "subscriptionConnectionMinimumIdleSize":1,
      "subscriptionConnectionPoolSize":50,
      "connectionMinimumIdleSize":32,
      "connectionPoolSize":64,
      "database":0,
      "dnsMonitoringInterval":5000
   },
   "threads":0,
   "nettyThreads":0,
   "codec":{
      "class":"org.redisson.codec.JsonJacksonCodec"
   },
   "transportMode":"NIO"
}


启动%tomcat_home%/bin/startup.bat,即可。


评论

表情

分享到: