1.下载安装tomcat、memcached、nginx
2.解压tomcat,copy一份,然后更改copy之后tomcat的端口。
3.准备好jar包(附件),把jar放到tomcat安装目录的lib下面
4.配置两个tomcat,在con/context.xml文件里面增加如下配置:
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:localhost:11211"
requestUriIgnorePattern=".*/.(png|gif|jpg|css|js)$"
sessionBackupAsync="false"
sessionBackupTimeout="100"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
copyCollectionsForSerialization="false"
/>
5.在一个个tomcat的 webapps/ROOT目录下写一个测试页面test.jsp
<%@ page language="java" %>
<html>
<head><title>Tomcat1</title></head>
<body>
<h1><font color="red">Tomcat1</font></h1>
<table align="centre" border="1">
<tr>
<td>Session ID</td>
<% session.setAttribute("test","test"); %>
<td><%= session.getId() %></td>
</tr>
</table>
</body>
</html>
另一个tomcat
<%@ page language="java" %>
<html>
<head><title>Tomcat2</title></head>
<body>
<h1><font color="red">Tomcat2</font></h1>
<table align="centre" border="1">
<tr>
<td>Session ID</td>
<% session.setAttribute("test","test"); %>
<td><%= session.getId() %></td>
</tr>
</table>
</body>
</html>
6.配置ngnix
http节点下面配置
upstream localhost {
server 127.0.0.1:8090 weight=1 max_fails=2 fail_timeout=30s;
server 127.0.0.1:8091 weight=1 max_fails=2 fail_timeout=30s;
}
server节点
location / {
root html;
index index.html index.htm;
proxy_pass http://localhost;
}
7.测试。启动两个tomcat和ngnix,用ngnix访问,因为是默认80端口,直接访问http://localhost/test.jsp,页面不断变化,但是sessionId没变。