五、配置Tomcat负载均衡、集群
1.修改tomcat 的 conf/server.xml 的<Engine>
去掉注释<Engine defaultHost="localhost" jvmRoute="tomcat1">
jvmRoute是tomcat路由标示,由此区分两台tomcat主机,那么第二台就改为
<Engine defaultHost="localhost" jvmRoute="tomcat2">
加上注释<Engine defaultHost="localhost">
2.修改tomcat 的 conf/server.xml 的<Connector>
去掉注释<Connector port="8009"
enableLookups="false" redirectPort="8443" debug="0"
protocol="AJP/1.3" />
3.修改tomcat 的 conf/server.xml 的<Cluster>
<!--
< Cluster className = " org.apache.catalina.cluster.tcp.SimpleTcpCluster "
managerClassName = " org.apache.catalina.cluster.session.DeltaManager "
expireSessionsOnShutdown = " false "
useDirtyFlag = " true "
notifyListenersOnReplication = " true " >
< Membership
className = " org.apache.catalina.cluster.mcast.McastService "
mcastAddr = " 228.0.0.4 "
mcastPort = " 45564 "
mcastFrequency = " 500 "
mcastDropTime = " 3000 " />
< Receiver
className = " org.apache.catalina.cluster.tcp.ReplicationListener "
tcpListenAddress = " auto "
tcpListenPort = " 4001 "
tcpSelectorTimeout = " 100 "
tcpThreadCount = " 6 " />
< Sender
className = " org.apache.catalina.cluster.tcp.ReplicationTransmitter "
replicationMode = " pooled "
ackTimeout = " 5000 " />
< Valve className = " org.apache.catalina.cluster.tcp.ReplicationValve "
filter = " .*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt; " />
< Deployer className = " org.apache.catalina.cluster.deploy.FarmWarDeployer "
tempDir = " /tmp/war-temp/ "
deployDir = " /tmp/war-deploy/ "
watchDir = " /tmp/war-listen/ "
watchEnabled = " false " />
< ClusterListener className = " org.apache.catalina.cluster.session.ClusterSessionListener " />
</ Cluster >
-->
把上面的注释拿掉 就ok 了!
4.在每个webapps应用中,修改web.xml文件 添加元素<distributable/>
最后完工,重启tomcat,apahce测试平衡负载,新建jsp页面
<%
Runtime lRuntime = Runtime.getRuntime();
out.println("*** BEGIN MEMORY STATISTICS ***<br/>");
out.println("Free Memory: "+lRuntime.freeMemory()/1024/1024+"M<br/>");
out.println("Max Memory: "+lRuntime.maxMemory()/1024/1024+"M<br/>");
out.println("Total Memory: "+lRuntime.totalMemory()/1024/1024+"M<br/>");
out.println("Available Processors : "+lRuntime.availableProcessors()+"<br/>");
out.println("*** END MEMORY STATISTICS ***");
%>
<br>
<%= request.getSession().getId() %>
放入到两台tomcat的ROOT目录中测试
再测试集群(session复制)