• Tomcat可以实现Session共享方案


    说明:原来Tomcat也是可以实现Session共享的,这样大大减少的硬编码的实现,并且前面用Nginx分流时不用考虑Session的问题,因为是Web容器提供了Session共享的支持。

    1、在每个Tomcat的conf目录下,找到server.xml文件,增加如下内容:

            <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
                     channelSendOptions="8">
    
              <Manager className="org.apache.catalina.ha.session.DeltaManager"
                       expireSessionsOnShutdown="false"
                       notifyListenersOnReplication="true"/>
    
              <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"
                          port="4000"
                          autoBind="100"
                          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.TcpFailureDetector"/>
                <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
              </Channel>
    
              <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
                     filter=""/>
              <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>

    在这个下面增加<Engine name="Catalina" defaultHost="localhost">即可。

    2、在项目的web.xml中增加<distributable>

    参考:

    http://tomcat.apache.org/tomcat-7.0-doc/cluster-howto.html(官方文档)

    http://blog.csdn.net/qh_java/article/details/45955923

    http://blog.csdn.net/wlwlwlwl015/article/details/48160433

  • 相关阅读:
    MySql锁机制
    Mysql存储引擎
    Linux 系统中安装mysql
    常见的系统架构
    Linux环境下搭建go开发环境
    Ajax概述
    正向代理和反向代理
    Mysql 存储过程以及在.net中的应用示例
    Mysql 事务
    Windows服务器实现自动化部署-Jenkins
  • 原文地址:https://www.cnblogs.com/EasonJim/p/7726618.html
Copyright © 2020-2023  润新知