一,tomcat/conf/server.xml增加如下配置
<!-- 基于网络广播的策略,一个节点session发生变化,其他节点同步复制,节点多或数据量大时性能低下 -->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="6">
<Manager className="org.apache.catalina.ha.session.BackupManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"
mapSendOptions="6"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto" --如果节点在不同主机,这里配置各个节点自己的IP
port="5000" -- 如果节点部署在同一主机,则port要配置不同端口
selectorTimeout="100"
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.MessageDispatch15Interceptor"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;"/>
<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>
二,项目工程里面的web.xml增加<distributable/> 表示支持集群
三,开启Membership 和 Receiver 的端口
/sbin/iptables -I INPUT -p udp --dport 45564 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 4000 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 4001 -j ACCEPT
/etc/rc.d/init.d/iptables save
tomcat服务集群实现
最新推荐文章于 2023-01-11 16:15:37 发布