不进行多播的tomcat集群session复制

如何为静态集群设置会话复制?

分为三步:

第一步:

举个例子:我们有两台服务器(192.168.91.88和192.168.91.89)。然后192.168.91.88下的tomcat的server.xml文件应该包含:

<Cluster 
        channelSendOptions="8" 
        channelStartOptions="3" 
        className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
    <Manager 
        className="org.apache.catalina.ha.session.DeltaManager" 
        expireSessionsOnShutdown="false" 
        notifyListenersOnReplication="true"
    />
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">
        <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
        </Sender>
        <Receiver 
            address="192.168.91.88" 
            autoBind="0" 
            className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
            maxThreads="6" 
            port="4100" 
            selectorTimeout="5000"
        />
        <!-- <Interceptor className="com.dm.tomcat.interceptor.DisableMulticastInterceptor" /> -->
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
            <Member 
                className="org.apache.catalina.tribes.membership.StaticMember" 
                port="4100" 
                host="192.168.91.89" 
                uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,2}" 
            />
        </Interceptor>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
    </Channel>
    <Valve 
        className="org.apache.catalina.ha.tcp.ReplicationValve" 
        filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;" 
    />
    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>

 

同时 192.168.91.89服务器下的tomcat的server.xml应该包含:

<Cluster 
        channelSendOptions="8" 
        channelStartOptions="3" 
        className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
    <Manager 
        className="org.apache.catalina.ha.session.DeltaManager" 
        expireSessionsOnShutdown="false" 
        notifyListenersOnReplication="true"
    />
    <Channel className="org.apache.catalina.tribes.group.GroupChannel">
        <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
            <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender" />
        </Sender>
        <Receiver 
            address="192.168.91.89" 
            autoBind="0" 
            className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
            maxThreads="6" 
            port="4100" 
            selectorTimeout="5000"
        />
        <!-- <Interceptor className="com.dm.tomcat.interceptor.DisableMulticastInterceptor" /> -->
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpPingInterceptor" staticOnly="true"/>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector" />
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.StaticMembershipInterceptor">
            <Member 
                className="org.apache.catalina.tribes.membership.StaticMember" 
                port="4100" 
                host="192.168.91.88" 
                uniqueId="{0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}" 
            />
        </Interceptor>
        <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor" />
    </Channel>
    <Valve 
        className="org.apache.catalina.ha.tcp.ReplicationValve" 
        filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;" 
    />
    <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener" />
</Cluster>

 

第二步:

确定你的防火墙的4000端口是开启的。可以采用以下命令:

nc -w 1   IP地址    端口 < /dev/null && echo "tcp port ok"

该命令可能有三种返回值:

  1. Connection refused:这意味着在此端口并没有运行任何东西(是可以访问的)
  2. Accepted:意味着在此端口运行着东西(可以访问)
  3. Timeout:意味着该端口没有开放

 

第三步:

在项目下面的web.xml文件下面加入如下语句:

<distributable/>

</web-app>

 怎么确定session复制是否起效:

 

查看tomcat  log文件夹下的catalina.out,如果包含以下信息,就说明是成功的:

WARNING: Member added, even though we werent notified:org.apache.catalina.tribes.membership.MemberImpl[tcp://192.168.91.89:4100,192.168.91.89,4100, alive=0,id={0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 }, payload={}, command={}, domain={}, ]
Mar 26, 2015 6:42:35 PM org.apache.catalina.ha.tcp.SimpleTcpCluster memberAdded
INFO: Replication member added:org.apache.catalina.tribes.membership.MemberImpl[tcp://192.168.91.89:4100,192.168.91.89,4100, alive=0,id={0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 }, payload={}, command={}, domain={}, ]
INFO: Starting clustering manager at /...
Nov 12, 2015 3:57:07 PM org.apache.catalina.ha.session.DeltaManager getAllClusterSessions
WARNING: Manager [localhost#/...], requesting session state from org.apache.catalina.tribes.membership.MemberImpl[tcp://192.168.210.81:4100,192.168.210.81,4100, alive=0,id={0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 }, payload={}, command={}, domain={}, ]. This operation will timeout if no session state has been received within 60 seconds.
Nov 12, 2015 3:57:07 PM org.apache.catalina.ha.session.DeltaManager waitForSendAllSessions
INFO: Manager [localhost#/MicroStrategy]; session state send at 11/12/15 3:57 PM received in 265 ms.

 

相关推荐
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页