tomcat 设置集群

本文介绍的是使用tomcat内置的集群功能。跟官方文档的区别是没有使用广播,而是使用了static membership的方式。

需要修改server.xml

放在哪个元素下来的,是Host还是啥记不清了

      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8" channelStartOptions="3">
        <Manager className="org.apache.catalina.ha.session.DeltaManager"
                 expireSessionsOnShutdown="false"
                 notifyListenersOnReplication="true"/>

        <Channel className="org.apache.catalina.tribes.group.GroupChannel">

          <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                    address="localhost"
                    port="4110"
                    autoBind="9"
                    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.TcpPingInterceptor"/>
          <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.StaticMembershipInterceptor">
                <!--Member className="org.apache.catalina.tribes.membership.StaticMember"
                  port="4110"
                  host="localhost"
                  domain="delta-static"
                  uniqueId="{0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}"
                /-->
                <Member className="org.apache.catalina.tribes.membership.StaticMember"
                  port="4210"
                  host="localhost"
                  domain="delta-static"
                  uniqueId="{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,0}"
                />
                <Member className="org.apache.catalina.tribes.membership.StaticMember"
                  port="4310" securePort="-1"
                  host="localhost"
                  domain="delta-static"
                  uniqueId="{2,3,4,5,6,7,8,9,10,11,12,13,14,15,0,1}"
                />
          </Interceptor>

        </Channel>
        <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
        <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

        <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
        <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
      </Cluster>

 这个使用直接的

有几个点需要注意 

1. Receiver.address这个属性如果是是暴露在127.0.0.1上,跑在别的机器上的是看不到它的,使用  netstat -lntp 查看一下

2. Cluster.channelStartOptions 必须这样设置才能真正的禁用广播

3. TcpPingInterceptor 这个是用来检查其他节点的状态的。 如果不设置这个,其他的节点挂了看不出来。

4. 每一个member是集群中的一个节点,不要当前节点放进去

5. webapp/youapp/WEB-INF/web.xml里添加<distributable/>标签。

 

转载于:https://www.cnblogs.com/easyroom/p/5858334.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值