* tomcat1 192.168.10.153* tomcat2 192.168.10.154
Tomcat 工作模式必须为Nio 模式。
##添加如下内容, 注意更换 address="192.168.10.154" 为本机IP
vim /usr/local/tomcat/conf/server.xml<Cluster className&#61;"org.apache.catalina.ha.tcp.SimpleTcpCluster"channelSendOptions&#61;"8"><Manager className&#61;"org.apache.catalina.ha.session.DeltaManager"expireSessionsOnShutdown&#61;"false"notifyListenersOnReplication&#61;"true"/><Channel className&#61;"org.apache.catalina.tribes.group.GroupChannel"><Membership className&#61;"org.apache.catalina.tribes.membership.McastService"address&#61;"228.0.0.4"port&#61;"45564"frequency&#61;"500"dropTime&#61;"3000"/><Receiver className&#61;"org.apache.catalina.tribes.transport.nio.NioReceiver"address&#61;"192.168.10.154"port&#61;"4000"autoBind&#61;"100"selectorTimeout&#61;"5000"maxThreads&#61;"6"/><Sender className&#61;"org.apache.catalina.tribes.transport.ReplicationTransmitter"><Transport className&#61;"org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>Sender><Interceptor className&#61;"org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/><Interceptor className&#61;"org.apache.catalina.tribes.group.interceptors.MessageDispatchInterceptor"/>Channel><Valve className&#61;"org.apache.catalina.ha.tcp.ReplicationValve"filter&#61;""/><Valve className&#61;"org.apache.catalina.ha.session.JvmRouteBinderValve"/><Deployer className&#61;"org.apache.catalina.ha.deploy.FarmWarDeployer"tempDir&#61;"/tmp/war-temp/"deployDir&#61;"/tmp/war-deploy/"watchDir&#61;"/tmp/war-listen/"watchEnabled&#61;"false"/><ClusterListener className&#61;"org.apache.catalina.ha.session.ClusterSessionListener"/>Cluster>
#
vim /usr/local/tomcat/webapps/ROOT/WEB-INF/web.xml
##添加测试文件
vim index.jsp
<%&#64; page contentType&#61;"text/html; charset&#61;GBK" %>
<%&#64; page import&#61;"java.util.*" %>
<html> <head> <title>Cluster App Testtitle> head> <body> Server Info: <% out.println(request.getLocalAddr() &#43; " : " &#43; request.getLocalPort()&#43;"
");%> <% out.println("
ID " &#43; session.getId()&#43;"
"); // 如果有新的 Session 属性设置 String dataName &#61; request.getParameter("dataName"); if (dataName !&#61; null && dataName.length() > 0) { String dataValue &#61; request.getParameter("dataValue"); session.setAttribute(dataName, dataValue); } %>body>
html>
upstream tomcatserver {server 192.168.10.153:8080 weight&#61;5;server 192.168.10.154:8080 weight&#61;5;} location / {proxy_pass http://tomcatserver; }
本文转自 295631788 51CTO博客&#xff0c;原文链接&#xff1a;http://blog.51cto.com/hequan/2066415&#xff0c;如需转载请自行联系原作者