本文参考
[url=http://blog.youkuaiyun.com/grhlove123/article/details/48047735]nginx+tomcat+redis完成session共享[/url]
下载完成后拷贝到$TOMCAT_HOME/lib中
修改两tomcat的context.xml:
在tomcat/webapps/test放一个index.jsp
访问路径,不断刷新,可以看到虽然Server从1111变为2222,但session的创建时间没有变化,这就完成了session共享。
[url=http://blog.youkuaiyun.com/grhlove123/article/details/48047735]nginx+tomcat+redis完成session共享[/url]
下载完成后拷贝到$TOMCAT_HOME/lib中
修改两tomcat的context.xml:
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
<Valve className="com.orangefunction.tomcat.redissessions.RedisSessionHandlerValve" />
<Manager className="com.orangefunction.tomcat.redissessions.RedisSessionManager"
host="10.10.49.20"
port="6379"
database="0"
maxInactiveInterval="60" />
</Context>
在tomcat/webapps/test放一个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");
%>
访问路径,不断刷新,可以看到虽然Server从1111变为2222,但session的创建时间没有变化,这就完成了session共享。