ǰ��
���ڸ߷��������߲���������վ��webӦ����˵��Ŀǰ����Ľ������Ӧ�þ������ø��ؾ������server��Ⱥ������Ƚ����е�nginx+memcache+tomcat����Ⱥ֮�����������N��Tomcat���û��ڷ������ǵ���վʱ�п��ܵ�һ������ַ���tomcat1�£����ڶ��������ַַ�����tomcat2�£��й�web������������Ѷ�֪����ʱsession��һ�»ᵼ�������ĺ��������������Ҫ���һ�¶��tomcat֮��session���������⡣
������
����������Ҫ����tomcat����������ѡ��tomcat7�Ľ�ѹ���棺

������ɺ������½�һ��Ŀ¼��tomcat_cluster��tomcat��Ⱥ����˼����ֱ�ӽ�ѹ���غõ�tomcat����������Ϊtomcat1�����Կ���Ŀ¼�ṹ���£�

��һ�����web��Ŀ����IDE�д������𣬿����������ɣ�������index.jsp���������£�
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
SessionID:<%=session.getId()%>
<BR>
SessionIP:<%=request.getServerName()%>
<BR>
SessionPort:<%=request.getServerPort()%>
<%
out.println("This is Tomcat Server 11111");
%>
</body>
</html>
�������������������ˣ�������Ҫ��tomcat�������ļ������Ǵ�conf�µ�server.xml�ļ����ҵ�������һ�У�
<Engine name="Catalina" defaultHost="localhost">
����Ҫ���κ��ģ�����һ�е�����������´��룺
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelSendOptions="8">
<Manager className="org.apache.catalina.ha.session.DeltaManager"
expireSessionsOnShutdown="false"
notifyListenersOnReplication="true"/>
<Channel className="org.apache.catalina.tribes.group.GroupChannel">
<Membership className="org.apache.catalina.tribes.membership.McastService"
address="228.0.0.4"
port="45564"
frequency="500"
dropTime="3000"/>
<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
address="auto"
port="4000"
autoBind="100"
selectorTimeout="5000"
maxThreads="6"/>
<Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
<Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
<Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel>
<Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
filter=""/>
<Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
tempDir="/tmp/war-temp/"
deployDir="/tmp/war-deploy/"
watchDir="/tmp/war-listen/"
watchEnabled="false"/>
<ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
<ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>
�������tomcat�Դ��ļ�Ⱥ�����ˣ����ǿ�����tomcat�ٷ��ĵ��е�cluster-howto.html�п������ע�����������һ����Ҫע��һ�£�
Make sure your web.xml has the <distributable/> element
��������˵���ǵ�web��Ŀ��web.xml�ļ�����Ҫ��<distributable/>���Ԫ�أ����������Ǹղ������web��Ŀ�������ϵ��ġ�
�������ǵĻ������þ�����ˣ���Ϊ�Ǽ�Ⱥ��������tomcat_clusterĿ¼�¿���һ��tomcat1������������tomcat2��

ע��һ����Ҫ�ĵĵط���
1�����ȿ϶��Ƕ˿ںţ�����port���������ö���һ�±�֤�������ظ��������ォtomcat1�Ķ˿���Ϊ7080��tomcat2�Ķ˿���Ϊ9080��
2����webapps�µ���Ŀ�е�index.jsp�ļ�����ΪҪ����session���������б�Ҫ����һ�£���jsp�м���һ�о�̬�ı����ɣ�����������“This is Tomcat Server 111111”��“This is Tomcat Server 22222”���������ֵģ�����ֱ���������tomcat���в��ԣ����Ƿֱ�����binĿ¼�µ�startup.bat�����ֵ�һ��tomcat����֮�ڶ�����������������Ϊ�����ű���startup.bat��û���ģ�����ͬ����CATALINA_HOME��Ȼ�ᱨ����������ע������ĵ����㡣
3��Ϊ���ǵ�������tomcat����������������——CATALINA_HOME2��CATALINA_HOME3�ֱ�ָ��������tomcat�İ�װĿ¼��

Ȼ��ֱ�������tomcat��binĿ¼�µ������ű���startup.bat��catalina.bat����tomcat1�е��������ļ��е�%CATALINA_HOME%�滻Ϊ%CATALINA_HOME2%����tomcat2�е��������ļ��е�%CATALINA_HOME%�滻Ϊ%CATALINA_HOME3%������������tomcat���ᷢ������tomcat���������������ˣ���ѹ���tomcat��Ҫ��������һ�¡���������м��һ��tomcat�Ƿ���Գɹ����ʣ�

OK���ٷ���һ�����ǵIJ�����Ŀ������session�Ƿ�һ�£�

���Է�����������tomcat�µ���������ĿSession��ȫһ�£�ˢ��Ҳ����䣬����Ϊֹ���Ǿ���ɹ�ʵ����Session������Ҳ����˵����tomcat�Ѿ��ɹ����������ʣ��Ľ���nginx��OK�ˡ������ǿ��һ�£�������testdemo��web.xml����Ҫ����ôԪ�أ�

�ܽ�
���Ľ�����tomcat��Ⱥ֮ǰ�ıر�����——session���������ã��Լ�ͬʱ��������tomcat��ѹ������Ҫע������⣬ϣ���Կ�����ͬѧ���������ɣ�The End��
�������ø��µ�ַ��//m.ajphoenix.com/linux/24544.html