<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:192.168.1.23:11211"
sticky="false"
lockingMode="uriPattern:/path1|/path2"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
Tomcat session共享—MSM
1、原理
MSM(memcached-session-manager) 支持tomcat6 和tomcat7 ,利用 Value(Tomcat 閥)對Request進行跟蹤。Request請求到來時,從memcached加載session,Request請求結束時,將tomcat session更新至memcached,以達到session共享之目的, 支持 sticky 和 non-sticky 模式。
Sticky 模式:tomcat session 爲 主session, memcached 爲備 session。Request請求到來時, 從memcached加載備 session 到 tomcat (僅當tomcat jvmroute發生變化時,不然直接取tomcat session);Request請求結束時,將tomcat session更新至memcached,以達到主備同步之目的。
Non-Sticky模式:tomcat session 爲 中轉session, memcached1 爲主 sessionmemcached 2 爲備session。Request請求到來時,從memcached 2加載備 session 到 tomcat,(當 容器 中仍是沒有session 則從memcached1加載主 session 到 tomcat, 這種狀況是隻有一個memcached節點,或者有memcached1 出錯時),Request請求結束時,將tomcat session更新至 主memcached1和備memcached2,而且清除tomcat session 。以達到主備同步之目的。
2、配置
1.sticky
<Context>
<Manager className=" de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:localhost:11211 n2:localhost:11212"
failoverNodes="n1"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
2.non-sticky
<Context>
<Manager className=" de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:localhost:11211 n2:localhost:11212"
sticky="false"
lockingMode="uriPattern:/path1|/path2"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
3.jvmroute
配置$CATALINA_HOME/conf/server.xml
#每臺機器jvmRoute不能相同 jvmRoute="tomcat2"
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
配置$CATALINA_HOME/conf/context.xml<Context> 詳見下
4.日誌
在該日誌文件中添加配置。$CATALINA_HOME/conf/logging.properties.
de.javakaffee.web.msm.level=FINE
5.jar
kryo-1.03.jar
kryo-serializers-0.8.jar
memcached-2.4.2.jar
memcached-session-manager-1.5.0.jar
memcached-session-manager-tc6-1.5.0.jar
minlog-1.2.jar
msm-kryo-serializer-1.5.0.jar