nginx+tomcat+memcached 共享session问题,跪求各位大神显圣。

bing0726 发布于 2015/12/02 18:04
阅读 295
收藏 0

我们的环境是nginx+2台tomcat实现负载,memcached实现session同步。我的tomcat,context.xml配置文件如下。

tomcat1的context.xml配置

    <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
    memcachedNodes="n1:10.12.13.202:11211,n2:10.12.13.203:11211"
    failoverNodes="n1"
    lockingMode="all"
    requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
    sessionBackupAsync="false"
    sessionBackupTimeout="100"
    transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
    copyCollectionsForSerialization="false"
    />

tomat2的context.xml配置

    <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
    memcachedNodes="n1:10.12.13.202:11211,n2:10.12.13.203:11211"
    failoverNodes="n2"
    lockingMode="all"
    requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
    sessionBackupAsync="false"
    sessionBackupTimeout="100"
    transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
    copyCollectionsForSerialization="false"
    />
使用jsp网上写的jsp测试

<%@ page contentType="text/html; charset=GBK" %>
<%@ page import="java.util.*" %>
<html><head><title>Cluster App Test</title></head>
<body>
 Server Info:
<%
out.println (request.getLocalAddr() + " : " + request.getLocalPort ()+"<br>");%>
<%
out.println ("<br> ID " + session.getId ()+"<br>");
String dataName = request.getParameter ("dataName");
if  (dataName != null && dataName.length () > 0) {
String dataValue = request.getParameter ("dataValue");
session.setAttribute (dataName, dataValue);
}
out.print ("<b>Session list</b>");
Enumeration e = session.getAttributeNames ();
while  (e.hasMoreElements ()) {
String name =  (String)e.nextElement ();
String value = session.getAttribute (name).toString ();
out.println ( name + " = " + value+"<br>");
System.out.println ( name + " = " + value);
}
%>
<form action="test.jsp" method="POST">
name:<input type=text size=20 name="dataName">
<br>
key:<input type=text size=20 name="dataValue">
<br>
<input type=submit>
</form>
</body>
</html>
The time on desktop 20 is:<%= new java.util.Date() %>
测试是正常,session不变

但是正常程序测试的时候报如下错


在网上查询说是时间没有同步,我的时间已经保持一致。跪求各位大神显圣。

加载中
返回顶部
顶部