MSM 实现 tomcat session 共享

it2022-05-07  8

1.准备相关jar包

2.修改nginx配置文件nginx.conf:#服务器的集群 http { upstream netitcast.com { #服务器集群名字 #server 127.0.0.1:18080 weight=1;#服务器配置 weight是权重的意思,权重越大,分配的概率越大。 server localhost:18080 weight=1; server localhost:28080 weight=1; }

server { listen 80; server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location / { proxy_pass http://netitcast.com; #使用集群分配的地址(http://netitcast.com/xxxx一定不能这样写,否则session丢失) }

}}3.修改tomcat服务器server.xml配置文件:<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">( jvmRoute="tomcat1" 多个服务器改成不一样的值)<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">( jvmRoute="tomcat2" 多个服务器改成不一样的值)

4.修改tomcat服务器context.xml配置文件:<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:192.168.47.102:11211"(多个用逗号隔开:"n1:192.168.47.102:11211,n2:192.168.47.102:11212") failoverNodes="n1"(指定memcached节点,单机该属性值不需要) sticky="false" lockingMode="auto" sessionBackupAsync="false" requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$" sessionBackupTimeout="1000" transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"/>

5.发布进行测试多个服务器互相切换,sessionId值不变化

转载于:https://www.cnblogs.com/yongwuzhijing/p/6768315.html


最新回复(0)