shiro.session There is no session with id問題點排查

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

相關文章
相關標籤/搜索