下载tomcat--session-manager相应的jar包

    https://page61.ctfile.com/fs/Vtq167749542

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

下载完成后拷贝到$TOMCAT_HOME/lib中

修改两tomcat的context.xml:

单点配置

<Context>

   <WatchedResource>WEB-INF/web.xml</WatchedResource>

   <ValveclassName="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"/>

   <Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"

        host="192.168.254.10"

        port="6379"

        database="0"

         maxInactiveInterval="60"/>

</Context>

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

基于redis的集群配置如下:

<ValveclassName="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve"/>        

<ManagerclassName="com.orangefunction.tomcat.redissessions.RedisSessionManager" 

    maxInactiveInterval="60"

    sentinelMaster="mymaster"

    sentinels="127.0.0.1:26379,127.0.0.1:26380,127.0.0.1:26381,127.0.0.1:26382"/>

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

在tomcat/webapps/ROOT放一个index.jsp

<%@ page language="" %>  

<html>  
  <head><title>TomcatA</title></head>  
  <body>  
   
    <table align="centre" border="1">  
      <tr>  
        <td>Session ID</td>  
        <td><%= session.getId() %></td>  
      </tr>  
      <tr>  
        <td>Created on</td>  
        <td><%= session.getCreationTime() %></td>  
     </tr>  
    </table>  
  </body>  
</html>  
sessionID:<%=session.getId()%>   
<br>   
SessionIP:<%=request.getServerName()%>   
<br>   
SessionPort:<%=request.getServerPort()%>   
<%   
//为了区分,第二个可以是222  
out.println("This is Tomcat Server 1111");   
%>    

通过访问http://127.0.0.1/index.jsp

可以看到虽然Server从1111变为2222,但session的创建时间没有变化,这就完成了session共享。