nginx+tomcat7+redis session共享

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

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

--------------------------------------------------------------------------------------------------------------------------------------------------------------------web

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

修改两tomcat的context.xml:tomcat

单点配置session

<Context>app

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

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

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

        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="Java" %>  
<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共享。

相关文章
相关标签/搜索