Tomcat cluster---Cluster node configuration

Modify web.xml in the web project to add the following
<distributable/>



Modify tomcat/conf/server.xml
<!--
    Cluster (cluster, family) node, if you want to configure a tomcat cluster, you need to use this node.
    className indicates that when a tomcat cluster is used, that class is used to transfer information to each other to realize the transfer of information between them.
    channelSendOptions can be set to 2, 4, 8, 10, each number represents a way
    2 = Channel.SEND_OPTIONS_USE_ACK (confirm send)
    4 = Channel.SEND_OPTIONS_SYNCHRONIZED_ACK (synchronous send)
    8 = Channel.SEND_OPTIONS_ASYNCHRONOUS (send asynchronously)
    In asynchronous mode, the reliability can be improved by adding Acknowledge, at this time channelSendOptions is set to 10
-->
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
    <!--
        The Manager decides how to manage the session information of the cluster. Tomcat provides two kinds of Manager: BackupManager and DeltaManager
        BackupManager - All sessions under the cluster will be placed on a backup node. All nodes under the cluster can access this backup node
        DeltaManager - Sessions generated and changed by a node in the cluster will be replicated to other nodes.
        DeltaManager is Tomcat's default cluster manager, which can meet general development needs
        Using DeltaManager, the applications deployed on each node must be the same; using BackupManager, the applications deployed on each node can be different.

        className - specifies the class that implements the org.apache.catalina.ha.ClusterManager interface, and the management of information.
        expireSessionsOnShutdown - When set to true, a node shuts down, which will invalidate all sessions under the cluster
        notifyListenersOnReplication - Session replication and deletion between nodes under the cluster, whether to notify session listeners
        maxInactiveInterval - the effective time of the session under the cluster (unit: s).
        Sessions that are not active within maxInactiveInterval will be recycled by Tomcat. The default value is 1800 (30min)
    -->
    <Manager className="org.apache.catalina.ha.session.DeltaManager"
             expireSessionsOnShutdown="false"
             notifyListenersOnReplication="true"/>

    <!--
        Channel is a tool for communication between Tomcat nodes.
        Channel includes 5 components: Membership, Receiver, Sender, Transport, Interceptor
    -->
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">
         <!--
            Membership maintains a list of available nodes for the cluster. It can check for newly added nodes or nodes without heartbeats
            className - Specifies the class used by Membership
            address - multicast address
            port - multicast port
            frequency - time interval (unit: ms) for sending heartbeats (sending UDP packets to multicast addresses). Default is 500
            dropTime-Membership does not receive a heartbeat from a node within dropTime (unit: ms), then delete the node from the list of available nodes. The default value is 3000

            Note: Multicast: A one-to-many network connection between a sender and multiple receivers.
                A sender transmits the same data to multiple receivers at the same time, and only needs to make a copy of the same data packet.
                It improves data transfer efficiency and reduces the likelihood of congestion in the backbone network
                Tomcat nodes with the same multicast address and port can form sub-clusters under the cluster
         -->
        <Membership className="org.apache.catalina.tribes.membership.McastService"
                    address="228.0.0.4"
                    port="45564"
                    frequency="500"
                    dropTime="3000"/>

        <!--
            Receiver : the receiver, responsible for receiving messages
            There are two types of receivers: BioReceiver (blocking), NioReceiver (non-blocking)

            className - specifies the class used by the Receiver
            address - the address to receive the message
            port - the port on which to receive the message
            autoBind - the change interval of the port
            If port is 4000 and autoBind is 100, the receiver will take a port between 4000-4099 and listen
            selectorTimeout - timeout for polling within NioReceiver
            maxThreads - the maximum number of threads in the thread pool
        -->
        <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                  address="auto"
                  port="4000"
                  autoBind="100"
                  selectorTimeout="5000"
                  maxThreads="6"/>

        <!--
            Sender : sender, responsible for sending messages
            Sender embeds the Transport component, and Transport is really responsible for sending messages
        -->
        <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
            <!--
                Transport is divided into two types: bio.PooledMultiSender (blocking), nio.PooledParallelSender (non-blocking)
            -->
            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
        </Sender>

        <!--
            Interceptor : Cluster's interceptor
            TcpFailureDetector - When the network and system are busy, Membership may not be able to update the list of available nodes in time.
            At this time, TcpFailureDetector can intercept the information that a node is closed.
            and try to connect to this node via TCP to make sure this node is really down, thus updating the list of nodes available to the cluster                 
        -->
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>

        <!--
            MessageDispatch15Interceptor - to see if the way the Cluster component sends messages is set to
            Channel.SEND_OPTIONS_ASYNCHRONOUS (when channelSendOptions under the Cluster tab is 8).
            When set to Channel.SEND_OPTIONS_ASYNCHRONOUS,
            MessageDispatch15Interceptor first queues the messages waiting to be sent, and then forwards the queued messages to the Sender
        -->
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
    </Channel>

    <!--
        Valve : Can be understood as Tomcat's interceptor
        ReplicationValve - log before and after processing requests; filter requests that do not involve Session changes                   
        vmRouteBinderValve - When an error occurs in Apache's mod_jk, it ensures that requests from the same client are sent to the same node in the cluster
    -->
    <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
    <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

    <!--
        Deployer : Synchronize the consistency of all nodes under the cluster. Deployer has not been tested successfully. . .
     -->
     <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                   tempDir="/tmp/war-temp/"
                   deployDir="/tmp/war-deploy/"
                   watchDir="/tmp/war-listen/"
                   watchEnabled="true"/>
    <!--
        ClusterListener : a listener that listens for messages received by the Cluster component
        When using the DeltaManager, the information received by the Cluster is passed to the DeltaManager through the ClusterSessionListener
    -->
    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326304938&siteId=291194637