(例如/usr/local/apache-tomcat-6.0.35/webapps/ROOT/WEB-INF\web.xml )
1. 安装Nginx和Tomcat,(Nginx可以从
http://nginx.org/en/download.html下载,tomcat可以从
http://tomcat.apache.org/download-60.cgi下载) 在这里假定Nginx安装在axs3-nginx,tomcat分别安装在axs3-r1和axs3-r2上; 2. 修改/etc/nginx/nginx.conf文件,
- http
{ - …
-
upstream axs3-nginx { -
server 172.16.86.161:8080 weight=1; -
server 172.16.86.162:8080 weight=2; -
} -
server { -
… -
listen 80; -
server_name axs3-nginx; -
location / { -
proxy_pass http://axs3-nginx; -
} -
… -
} - …
- }
5. 修改两个tomcat的conf/server.xml文件,对Engine节点分别添加jvmRoute=”tomcat1”和jvmRoute=”tomcat2”,并添加以下内容:
<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”tomcat1”>
- <Cluster
className=“org.apache.catalina.ha.tcp.SimpleTcpCluster” -
channelSendOptions=“6”> -
-
-
<Manager className=“org.apache.catalina.ha.session.DeltaManager” -
expireSessionsOnShutdown =“false” -
notifyListenersOnReplica tion=“true”/> -
<!– -
<Manager className=“org.apache.catalina.ha.session.BackupManager” -
expireSessionsOnShutdown =“false” -
notifyListenersOnReplica tion=“true” -
mapSendOptions=“6”/> -
–> -
<Channel className=“org.apache.catalina.tribes.group.GroupChannel”> -
<Membership className=“org.apache.catalina.tribes.membership.McastService” -
address=“228.0.0.5” -
port=“45564” -
frequency=“500” -
dropTime=“3000”/> -
<Receiver className=“org.apache.catalina.tribes.transport.nio.NioReceiver” -
address=“172.16.86.161” -
port=“4009” -
selectorTimeout=“100” -
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.MessageDispatch15Interce ptor”/> -
</Channel> -
<Valve className=“org.apache.catalina.ha.tcp.ReplicationValve” filter=“.*/.gif;.*/.js;.*/.jpg;.*/.png;.*/.htm;.*/.html;.*/.css;.*/.txt;”/> -
-
<ClusterListener className=“org.apache.catalina.ha.session.JvmRouteSessionIDBinderL istener”/> -
<ClusterListener className=“org.apache.catalina.ha.session.ClusterSessionListener”/> - </Cluster>
6. 所有的Tomcat webapp的web.xml加上(例如/usr/local/apache-tomcat-6.0.35/webapps/ROOT/WEB-INF\web.xml ) 实现tomcat的session复制。
7.修改文件/usr/local/apache-tomcat-6.0.35/conf/web.xml,代码如下,
- <html>
- <head>
-
<title></title> - </head>
- <body>
- <%
-
String mydata = request.getParameter(“mydata”); -
if (mydata != null && mydata.length() != 0) { -
session.setAttribute(“mydata”, mydata); -
} -
-
out.println(“request.getLocalAddr(): ” + request.getLocalAddr()); -
out.println(“<br/>“); -
out.println(“request.getLocalPort(): ” + request.getLocalPort()); -
out.println(“<br/>“); -
out.println(“Session ID: ” + session.getId()); -
out.println(“<br/>“); -
-
out.println(“mydata: ” + session.getAttribute(“mydata”)); - %>
- <form>
-
<input type=text size=20 name=“mydata”> -
<br> -
<input type=submit> - </form>
- </body>
- </html>
9. 启动Tomcat和Nginx,访问 http://axs3-nginx参考资料: http://nginx.org/en
http://wiki.nginx.org/Main