使用nginx配置集群后,存在serverA上登录创建session,请求路由到server2时发现没有session,导致重新登录问题,
原因是session没有共享,那该怎么共享呢?通常有两种方法实现,一种集成spring-session,另一种在tomcat中集成session共享,核心思想都是将session存储到一个公用库(redis,mangdb等)
本文主要介绍tomcat session 共享的配置比较简单:
TOMCAT 7.0.54
1、conf/context.xml配置
2、jar包引入
资源下载
nginx的集群配置 自行网上搜索
部署异常
er :com.orangefunction.tomcat.redissessions.JavaSerializer04-Jun-2018 10:31:33.993 SEVERE [localhost-startStop-1] org.apache.catalina.core.StandardContext.startInternal The session manager failed to start org.apache.catalina.LifecycleException: Failed to start component [com.orangefunction.tomcat.redissessions.RedisSessionManager[/ip]] at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:162) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5331) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:753) at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:729) at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1129) at org.apache.catalina.startup.HostConfig$DeployDirectory.run(HostConfig.java:1871) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) at java.util.concurrent.FutureTask.run(FutureTask.java:262) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745)Caused by: java.lang.NoSuchMethodError: org.apache.catalina.Container.getLoader()Lorg/apache/catalina/Loader; at com.orangefunction.tomcat.redissessions.RedisSessionManager.initializeSerializer(RedisSessionManager.java:718) at com.orangefunction.tomcat.redissessions.RedisSessionManager.startInternal(RedisSessionManager.java:295) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145) ... 12 more我
我的测试环境版本是tomcat8 ,所以报这个错误。
https://stackoverflow.com/questions/39725781/how-to-solve-nosuchmethoderror-org-apache-catalina-container-getloaderlorg-a
进入bin目录,version.sh 查看tomcat版本
使用tomcat7.0.54版本后处理成功
支持tomcat8修改
https://github.com/watemei/tomcat-redis-session-manager.git
有问题的同学没分的同学 可以加我的微信公众号留言或者加群下载,
领取专属 10元无门槛券
私享最新 技术干货