2.manager决定如何管理集群的session信息
- className-指定实现org.apache.catalina.ha.ClusterManager接口的类,用于信息之间的管理.
- expireSessionsOnShutdown-设置为true时,一个节点关闭,将导致集群下的所有Session失效
- notifyListenersOnReplication-集群下节点间的Session复制、删除操作,是否通知session listeners
3.Channel是Tomcat节点之间进行通讯的工具。
- Channel包括5个组件:Membership、Receiver、Sender、Transport、Interceptor
4.Membership维护集群的可用节点列表。用于检测新增节点及掉线节点
- address-组播地址(任意定义组播地址),如果需要阿里云ECS部署tomcat,因为ECS不支持组播,建议改用memcache或redis存储session实现会话保持
- port-组播端口 (两个tomcat组播端口要一致)
- frequency-发送心跳(向组播地址发送UDP数据包)的时间间隔(单位:ms)。默认值为500
- dropTime-Membership在dropTime(单位:ms)内未收到某一节点的心跳,则将该节点从可用节点列表删除。默认值为3000
5.Receiver : 接收器
- address-接收消息的地址(默认auto,但是在虚拟机上开启tomcat会报错,建议配置本机IP地址)
- port-接收消息的端口(如果在一台服务器配置多个tomcat,需区分开端口)
- autoBind-端口的变化区间
如果port为4000,autoBind为100,接收器将在4000-4099间取一个端口,进行监听
- selectorTimeout-NioReceiver 轮询超时时间
- maxThreads-线程池的最大线程数
6.sender:发送器负责发送消息
- <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
- <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
- </Channel>
7.Valve :过滤器
8.Deployer:同步集群下的所有节点的一致性
9.ClusterListener : 监听器,监听Cluster组件接收的消息,使用DeltaManager时,Cluster接收的信息通过ClusterSessionListener传递给DeltaManager
配置web.xml
在web.xml中添加属性,用于告诉web容器,该项目属于分布式项目
添加标签到web项目WEB-INF目录

会话保持验证
webapps/ROOT/index.jsp 创建测试页面获取sessionID
- tomcatA
- <%@ page language="java" %>
- <html>
- <head><title>TomcatA</title></head>
- <body>
- <h1><font color="red">TomcatA</font></h1>
- <table align="centre" border="1">
- <tr>
- <td>Session ID</td>
- <% session.setAttribute("TomcatA","TomcatA"); %>
- <td><%= session.getId() %></td>
- </tr>
- <tr>
- <td>Created on</td>
- <td><%= session.getCreationTime() %></td>
- </tr>
- </table>
- </body>
- </html>
- tomcatB
- <%@ page language="java" %>
- <html>
- <head><title>TomcatB</title></head>
- <body>
- <h1><font color="red">TomcatB</font></h1>
- <table align="centre" border="1">
- <tr>
- <td>Session ID</td>
- <% session.setAttribute("TomcatB","TomcatB"); %>
- <td><%= session.getId() %></td>
- </tr>
- <tr>
- <td>Created on</td>
- <td><%= session.getCreationTime() %></td>
- </tr>
- </table>
- </body>
- </html>
(编辑:晋中站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|