1)整理集成所需jar
kryo-1.0.3.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
2)配置tomcat中context.xml
<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"
/>
3)安装memcached服务
4)集成详细说明:
Tomcat session共享—MSM
一、原理
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 。以达到主备同步之目的。
二、配置
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
三、流程图
1.sticky
2.non-sticky