您的位置:首页 > 运维架构 > Tomcat

Tomcat会话保持之session server

2017-09-03 00:01 323 查看
author:JevonWei

版权声明:原创作品

Tomcat会话保持之session server

拓扑图



环境

tomcatA    172.16.253.108
tomcatB    172.16.253.105
memcachedA 172.16.253.108
memcachedB 172.16.253.105
代理服务器 172.16.253.191


程序下载

https://github.com/magro/memcached-session-manager/wiki/SetupAndConfiguration

下载相关程序到Tomcat主机的//usr/share/java/tomcat目录下

javolution-5.4.3.1.jar
memcached-session-manager-1.8.3.jar
memcached-session-manager-tc7-1.8.3.jar
msm-javolution-serializer-1.8.3.jar
spymemcached-2.11.1.jar /usr/share/java/tomcat

memcachedA

[root@TomcatA ~]# yum -y install memcached
[root@TomcatA ~]# systemctl start memcached.service
[root@TomcatA ~]# ss -ntl

memcachedB

[root@TomcatB ~]# yum -y install memcached
[root@TomcatB ~]# systemctl start memcached.service
[root@TomcatB ~]# ss -ntl

Tomcat A

在Tomcat安装完成的基础上
将程序包下载到 /usr/share/java/tomcat

[root@TomcatA ~]# vim /etc/tomcat/server.xml
<Engine name="Catalina" defaultHost="localhost">
</Host>
<Host name="localhost"  appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/test" docBase="test" reloadable="true">
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:172.16.253.108:11211,n2:172.16.253.105:11211" \\指定memcached的服务器,并使用n1,n2区别节点
failoverNodes="n1"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
/>
</Context>
</Host>
[root@TomcatA ~]# systemctl start tomcat
[root@TomcatA ~]# ss -ntl

Tomcat B

在Tomcat安装完成的基础上
将程序包下载到 /usr/share/java/tomcat

[root@TomcatB ~]# vim /etc/tomcat/server.xml
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tcB">
<Host name="localhost"  appBase="webapps"
unpackWARs="true" autoDeploy="true">
<Context path="/test" docBase="test" reloadable="true">
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:172.16.253.108:11211,n2:172.16.253.105:11211"
failoverNodes="n1"
requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
/>
</Context>
</Host>
[root@TomcatB ~]# systemctl start tomcat
[root@TomcatB ~]# ss -ntl

代理服务器

[root@danran conf.d]# vim tomcat-http.conf
<proxy balancer://appsrvs>
BalancerMember http://172.16.253.108:8080 BalancerMember http://172.16.253.105:8080 ProxySet lbmethod=byrequests
</Proxy>
<VirtualHost *:80>
ServerName www.danran.com
ProxyVia On
ProxyRequests Off
ProxyPreserveHost On
<Proxy *>
Require all granted
</Proxy>
ProxyPass / balancer://appsrvs/
ProxyPassReverse / balancer://appsrvs/
<Location />
Require all granted
</Location>
</VirtualHost>

client

TomcatA.magedu.com

Session ID  Session ID  D63DF5FE54F9D8EADB833AEE0E7DD00B-n2.tcA \\n2为创建会话时的Tomcat主机,tcA为当前Tomcat

Created on  1504354197906

TomcatB.magedu.com

Session ID  D63DF5FE54F9D8EADB833AEE0E7DD00B-n2.tcB
Created on  1504354197906
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: