SSM+shiro+redis 作分布式项目时,在生产环境中遇到 org.apache.shiro.session.UnknownSessionException: There is no session with idweb
这个bug。排查了以后。问题点有如下两种:redis
(1):shiro的JSESSIONID 与Tomcat 、Jetty默认的JSESSIONID 冲突了。这时候须要改一下shiro对应的JSESSIONID:apache
<bean id="sessionManager" class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager"> <property name="sessionDAO" ref="redisSessionService" /> <property name="sessionIdCookie" ref="sessionIdCookie"/> <property name="sessionValidationInterval" value="3600000"/> <!-- 相隔多久检查一次session的有效性 --> <property name="globalSessionTimeout" value="3600000"/> <!-- session 有效时间为半小时 (毫秒单位)--> </bean> <!--设置cookie--> <!-- 会话Cookie模板 --> <bean id="sessionIdCookie" class="org.apache.shiro.web.servlet.SimpleCookie"> <constructor-arg value="sid"/> <!--设置Cookie名字,默认为JSESSIONID--> <property name="name" value="shiroUserid" /> <property name="path" value="/"/> </bean>
(2)排查redis的配置的maxmemory 是否设置有误:cookie
# NOTE: since Redis uses the system paging file to allocate the heap memory, # the Working Set memory usage showed by the Windows Task Manager or by other # tools such as ProcessExplorer will not always be accurate. For example, right # after a background save of the RDB or the AOF files, the working set value # may drop significantly. In order to check the correct amount of memory used # by the redis-server to store the data, use the INFO client command. The INFO # command shows only the memory used to store the redis data, not the extra # memory used by the Windows process for its own requirements. Th3 extra amount # of memory not reported by the INFO command can be calculated subtracting the # Peak Working Set reported by the Windows Task Manager and the used_memory_peak # reported by the INFO command. # # maxmemory <bytes> maxmemory 6000000000
个人生产环境是window Server 32G 的。原先配置的是32G的3/4 但这样设置每过一段时间就出现这样的bug。我假设内存是8G,配置了8G的3/4。就解决这个问题了session