12.修改两个tomcat的配置文件 context.xml。
修改后的tomcat node1配置文件
[root@node1 ~]# cd /data/node1/conf/
[root@node1 conf]# tail context.xml
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:192.168.1.84:11211"
requestUriIgnorePattern=".*\.(png|gif|jpg|css|js|ico|jpeg|htm|html)$"
sessionBackupTimeout="1800000"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
修改后的tomcat node2配置文件
[root@node2 ~]# cd /data/node2/conf/
[root@node2 conf]# tail context.xml
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
memcachedNodes="n1:192.168.1.84:11211"
requestUriIgnorePattern=".*\.(png|gif|jpg|css|js|ico|jpeg|htm|html)$"
sessionBackupTimeout="1800000"
transcoderFactoryClass="de.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"
/>
</Context>
13.修改之后,创建一个index.jsp测试session共享的文档,重启两个tomcat实例。
重启实例node1。
[root@node1 ROOT]# cat index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Tomcat+memcached共享session测试</title>
</head>
<body>
SessionID:<%=session.getId()%>
<BR>
SessionIP:<%=request.getServerName()%>
<BR>
SessionPort:<%=request.getServerPort()%>
<BR>
<%
out.println("This is Tomcat Server 8081.");
%>
%</body>
%</html>
/data/node1/bin/shutdown.sh
[root@node1 ~]# ps -ef | grep java
root 9063 1907 0 17:20 pts/1 00:00:00 grep java
/data/node1/bin/startup.sh
[root@node1 ~]# netstat -anpt | grep 8080
tcp 0 0 :::8080 :::* LISTEN 9072/java
tcp 0 0 ::ffff:127.0.0.1:8080 ::ffff:127.0.0.1:40496 TIME_WAIT -
14.重启实例tomcat node2。
[root@node2 ROOT]# cat index.jsp
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Tomcat+memcached共享session测试</title>
</head>
<body>
SessionID:<%=session.getId()%>
<BR>
SessionIP:<%=request.getServerName()%>
<BR>
SessionPort:<%=request.getServerPort()%>
<BR>
<%
out.println("This is Tomcat Server 8081.");
%>
%%</body>
%%</html>
[root@node2 ~]# /data/node2/bin/shutdown.sh
[root@node2 ~]# ps -ef | grep java
root 2830 2081 0 17:22 pts/0 00:00:00 grep java
[root@node2 ~]# /data/node2/bin/startup.sh
[root@node2 ~]# netstat -anpt | grep 8080
tcp 0 0 :::8080 :::* LISTEN 2840/java
15.访问nginx代理的服务器IP,192.168.1.15
16.把node1停掉,然后再测试192.168.1.15
[root@node1 ~]# /data/node1/bin/shutdown.sh
Using CATALINA_BASE: /data/node1
Using CATALINA_HOME: /data/node1
Using CATALINA_TMPDIR: /data/node1/temp
Using JRE_HOME: /data/jdk1.7.0_71/jre
Using CLASSPATH: /data/node1/bin/bootstrap.jar:/data/node1/bin/tomcat-juli.jar
[root@node1 ~]# ps -ef | grep java
root 9132 1907 0 17:29 pts/1 00:00:00 grep java