tomcat8的会议共享实现
下载tomcat
版本:apache-tomcat-8.0.53.zip
实现步骤,只需要两步
-
<李>两个tomcat的server.xml都增加一样集群配置
<代码> & lt;集群className=皁rg.apache.catalina.ha.tcp.SimpleTcpCluster” channelSendOptions=" 8 "比; 经理& lt; className=" org.apache.catalina.ha.session.DeltaManager " expireSessionsOnShutdown=" false " notifyListenersOnReplication=" true "/比; & lt;通道 className=皁rg.apache.catalina.tribes.group.GroupChannel”比; 加入& lt; className=" org.apache.catalina.tribes.membership.McastService " 港口地址=" 228.0.0.4 "=" 45564 "频率=" 500 " dropTime=" 3000 "/比; & lt;接收机 className=" org.apache.catalina.tribes.transport.nio.NioReceiver " 地址=白远倍丝?" 4000 " autoBind=" 100 " selectorTimeout=" 5000 " maxThreads=" 6 "/比; 发送者& lt; className=皁rg.apache.catalina.tribes.transport.ReplicationTransmitter”比; & lt;运输 className=" org.apache.catalina.tribes.transport.nio。PooledParallelSender”/比; & lt;/Sender> & lt;拦截器 className=" org.apache.catalina.tribes.group.interceptors.TcpFailureDetector "/比; & lt;拦截器 className=" org.apache.catalina.tribes.group.interceptors.MessageDispatch25Interceptor "/比; & lt;/Channel> & lt;阀className=" org.apache.catalina.ha.tcp.ReplicationValve " 过滤器="/比; & lt;阀 className=" org.apache.catalina.ha.session。JvmRouteBinderValve”/比; & lt;部署人员 className=" org.apache.catalina.ha.deploy.FarmWarDeployer " tempDir="/tmp/war-temp/" deployDir=?tmp/war-deploy/? watchDir="/tmp/war-listen/" watchEnabled=癴alse”/比; & lt; ClusterListener className=" org.apache.catalina.ha.session。ClusterSessionListener”/比; & lt;/Cluster> 代码>李> <李>两个tomcat的应用的web . xml下都增加& lt;可分配/祝辞
比如在:
/用户/da/图书馆/tomcat/apache - tomcat - 8.0.53 - 8081/webapps/根/web - inf/web . xml
增加:
& lt;可分配/祝辞李> <李>然后重启两台tomcat即可李>
新建jsp测试
session.jsp
<代码> & lt; html> & lt; head> & lt; title> test2 & lt;/head> & lt; body> SessionID是 & lt; %=session.getId() %比; & lt; BR>SessionIP是 & lt; %=request.getServerName() %比; & lt; BR>SessionPort是 & lt; %=request.getServerPort() %比; & lt; % 出去了。tomcat2 println(“回应”); %比; & lt;/body> & lt;/html> 代码>
比如放置在:
/用户/da/图书馆/Tomcat/apache - Tomcat - 8.0.53 - 8082/webapps/根/session.jsp
另一台一样。
访问:
http://localhost: 8081/session.jsp
http://localhost: 8082/session.jsp
sessionid一致:
<代码> SessionID是6 e5d26e07fde6fb5d01a59f457d64333 SessionIP是tomcat.chinaunicom.tech SessionPort从tomcat1 80响应 SessionID是6 e5d26e07fde6fb5d01a59f457d64333 SessionIP是tomcat.chinaunicom.tech SessionPort 80响应从tomcat2 代码>
注意事项
-
<李>需要使用tomcat8版本(上述测试在8.0.53上通过)。如果需要tomcat7,请告诉我,不是这种配置,我需要修改一下李>
<李>不要漏了可分配的配置,漏了会话也不能共享李>
<李>这种方案只适用于并发量较少的应用,目前可以先用着,明天我再尝试并发量大的复杂一点的方案看行不行李>
参考官网:
http://localhost: 8082/docs/cluster-howto.html
http://tomcat.apache.org/tomcat - 8.0 - doc/config/cluster.html
翻译:http://wiki.jikexueyuan.com/project/tomcat/clustering.html