不一樣的tomact實現sesson複製,共享session

步驟:java

一、打開tomcat/conf/server.xml文件,增長以下內容到<Engine></Engine>標記對裏:nginx

<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>
web

二、修改WEB-INF/web.xml文件,添加distributable屬性,表示tomcat要爲此web應用複製session。配置以下:apache

<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

經上兩個步驟,能夠實如今同一主機上tomcat之間的session共享,沒錯,是同一機上, 在網上查了相關資料,sessionid與域名有關係,http://192.168.1.1/index.jsp與http: //192.168.1.2/index.jsp光是配置以上信息是達不到效果的,須要在兩個tomcat上加一個負載均衡設備或者負載均衡軟件 (apache、nginx等),之後再說吧session

相關文章
相關標籤/搜索