Tomcat Session集群
2023-06-13 09:15:42 时间
Tomcat Session集群(问题)
ReplicationValve 检测哪些请求需要检测Session,Session数据是否有了变化,需要启动复制过程
官方文档:https://tomcat.apache.org/tomcat-8.5-doc/cluster-howto.html
Cluster className= org.apache.catalina.ha.tcp.SimpleTcpCluster channelSendOptions= 8 Manager className= org.apache.catalina.ha.session.DeltaManager expireSessionsOnShutdown= false notifyListenersOnReplication= true / Channel className= org.apache.catalina.tribes.group.GroupChannel Membership className= org.apache.catalina.tribes.membership.McastService address= 230.100.100.8 port= 45564 #45564/UDP frequency= 500 dropTime= 3000 / Receiver className= org.apache.catalina.tribes.transport.nio.NioReceiver address= auto #此项建议修改为当前主机的IP port= 4000 autoBind= 100 selectorTimeout= 5000 maxThreads= 6 / Sender className= org.apache.catalina.tribes.transport.ReplicationTransmitter Transport className= org.apache.catalina.tribes.transport.nio.PooledParallelSender / /Sender Interceptor className= org.apache.catalina.tribes.group.interceptors.TcpFailureDetector / Interceptor className= org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor / /Channel Valve className= org.apache.catalina.ha.tcp.ReplicationValve filter= / Valve className= org.apache.catalina.ha.session.JvmRouteBinderValve / Deployer className= org.apache.catalina.ha.deploy.FarmWarDeployer tempDir= /tmp/war-temp/ deployDir= /tmp/war-deploy/ watchDir= /tmp/war-listen/ watchEnabled= false / ClusterListener className= org.apache.catalina.ha.session.ClusterSessionListener / /Cluster
配置说明
Cluster 集群配置 Manager 会话管理器配置 Channel 信道配置 Membership 成员判定。使用什么多播地址、端口多少、间隔时长ms、超时时长ms。同一个多播地址和端口认为同属一个组。使用时修改这个多播地址,以防冲突 Receiver 接收器,多线程接收多个其他节点的心跳、会话信息。默认会从4000到4100依次尝试可用端口 address= auto ,auto可能绑定到127.0.0.1上,所以一定要改为可以用的IP上去 Sender 多线程发送器,内部使用了tcp连接池。 Interceptor 拦截器ReplicationValve 检测哪些请求需要检测Session,Session数据是否有了变化,需要启动复制过程
使用 Cluster className= org.apache.catalina.ha.tcp.SimpleTcpCluster /
添加到 Engine 所有虚拟主机都可以启用Session复制
添加到 Host ,该虚拟主机可以启用Session复制
最后,在应用程序内部启用了才可以使用
前提:
时间同步,确保NTP或Chrony服务正常运行。 防火墙规则。本次把多播复制的配置放到缺省虚拟主机里面, 即Host之下。
特别注意修改Receiver的address属性为一个本机可对外的IP地址。
t2的server.xml中,如下
Host name= t1.magedu.com appBase= /data/webapps autoDeploy= true 其他略去 Receiver className= org.apache.catalina.tribes.transport.nio.NioReceiver address= 10.0.0.101 port= 4000 autoBind= 100 selectorTimeout= 5000 maxThreads= 6 /
t3的server.xml中,如下
Host name= t2.magedu.com appBase= /data/webapps autoDeploy= true 其他略去 Receiver className= org.apache.catalina.tribes.transport.nio.NioReceiver address= 10.0.0.102 port= 4000 autoBind= 100 selectorTimeout= 5000 maxThreads= 6 /
Tomcat重启后,ss命令能看到tomcat监听在4000端口上
尝试使用刚才配置过得负载均衡(移除Session黏性),测试发现Session还是变来变去。
准备web.xml
在应用中增加WEB-INF,从全局复制一个web.xml过来
# cp /usr/local/tomcat/conf/web.xml /data/webapps/ROOT/WEB-INF/
为web.xml的 web-app 标签增加子标签 distributable/ 来开启该应用程序的分布式。
重启全部Tomcat,通过负载均衡调度到不同节点,返回的SessionID不变了。
本文链接:http://www.yunweipai.com/35185.html
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/52747.html
apachenginxTomcat相关文章
- Tomcat的基本使用
- 怎么给idea配置jdk_ideaj配置tomcat
- tomcat闪退问题整理
- Linux下同时启动两个Tomcat进行设置.
- Tomcat 到底干了啥
- Maven配置Tomcat_maven和tomcat的区别
- tomcat出现乱码怎么办_tomcat输出日志乱码
- Tomcat配置域名_tomcat nginx
- 浅谈Tomcat之Servlet-request获取请求参数及常用方法
- 云服务器宝塔面板+Tomcat+LNMP部署JAVA WEB
- The temporary upload location [/tmp/tomcat.***/work/Tomcat/localhost/ROOT] is not valid
- Docker安装tomcat, mysql,redis(单机版)
- Linux系统下Tomcat使用80端口的方法
- Linux中查看Tomcat启动日志的技巧(linux查看tomcat启动日志)
- [tomcat] 连接池参数maxActive、maxIdle 、maxWait 等详解编程语言
- spring boot上传文件错误The temporary upload location [/tmp/tomcat.******/work/Tomcat/localhost/ROOT] is not valid详解编程语言
- Linux下重启Tomcat的操作步骤(linux重启tomcat)
- Linux修改Tomcat端口号的步骤(linux修改tomcat端口)
- MySQL与Tomcat:强强联合的绝佳组合(mysql与tomcat)
- Tomcat与MySQL助力Web应用程序开发(tomcat和mysql)
- dockerfile生产案例-制作自定义tomcat业务镜像
- Eclipse启动Tomcat超时问题的解决方法