tmcat8 集群配置

2017-11-29  本文已影响20人  水车
  1. 项目的web.xml中配置

    <distributable/>
    
  2. 在tomcat中配置Engine标签

#默认这条语句是被注释起来的:
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
#开启集群,我们只需要吧这条注释放开就可以了
  1. 上面的情况是tomcat都部署到了不同的服务器上,所用才用默认的配置都是不会出错的,但是,如果我们在一台服务器上配置了多个tomcat,那么问题就来了,会有端口冲突的问题,所用我们得配置更多的信息
<!--下面的代码是开启集群和实现session复制功能-->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="6">
      <Channel className="org.apache.catalina.tribes.group.GroupChannel">
        <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                  address="192.168.100.63"    <!—这里填写本机IP地址-->
                  port="5000"
                  selectorTimeout="100" />
      </Channel>
 </Cluster>
  1. 更复杂的配置
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!--下面的代码是实现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="192.168.100.63"    <!—这里填写本机IP地址-->
                  port="5000"
                  selectorTimeout="100" />
        <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;"/>
      <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.JvmRouteSessionIDBinderListener"/>
      <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>

参考

tomcat集群负载均衡配置

上一篇下一篇

猜你喜欢

热点阅读