不同的tomact实现sesson复制,共享session

步骤:

1、打开tomcat/conf/server.xml文件,增加如下内容到<Engine></Engine>标记对里:

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster">
<Membership
className="org.apache.catalina.cluster.mcast.McastService"
mcastBindAddress="127.0.0.1"
mcastAddr="228.0.0.4"
mcastPort="45564"
mcastFrequency="500"
mcastDropTime="3000"/>
<Receiver
className="org.apache.catalina.cluster.tcp.ReplicationListener"
tcpListenAddress="192.168.0.253" //配置IP地址
tcpListenPort="4001" //配置端口,不能与其它tomcat的server.xml端口相同
tcpSelectorTimeout="100"
tcpThreadCount="6"/>
</Cluster>

2、修改WEB-INF/web.xml文件,添加distributable属性,表示tomcat要为此web应用复制session。配置如下:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5">

  <display-name>Welcome to Tomcat</display-name>
  <description>
     Welcome to Tomcat
  </description>
<distributable/>
</web-app>
  

经上两个步骤,可以实现在同一主机上tomcat之间的session共享,没错,是同一机上,在网上查了相关资料,sessionid与域名有关系,http://192.168.1.1/index.jsp与http://192.168.1.2/index.jsp光是配置以上信息是达不到效果的,需要在两个tomcat上加一个负载均衡设备或者负载均衡软件(apache、nginx等),以后再说吧

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值