tomcat負(fù)載均衡配置:集群和應(yīng)用部分的代碼
前文,我們介紹了tomcat負(fù)載均衡安裝和配置的內(nèi)容,前面主要針對的是負(fù)載均衡的配置代碼介紹。那么接下來,就是針對于tomcat集群配置的代碼內(nèi)容,之后的應(yīng)用配置也做了簡要的敘述。
◆tomcat集群配置
(1)負(fù)載均衡配置的條件下配置tomcat集群
(2)分別修改三個tomcat的配置文件conf/server.xml,修改內(nèi)容如下
修改前
- <!--
 - <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>
 - -->
 
#p#修改后
- <!-- modify by whh -->
 - <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>
 - !-- modify by whh -->
 
將集群配置選項的注釋放開即可,如上。
(3)重啟三個tomcat。到此負(fù)載均衡配置下tomcat的集群已配置完成。#p#
◆應(yīng)用配置
對于要進(jìn)行負(fù)載和集群的的tomcat目錄下的webapps中的應(yīng)用中的WEB-INF中的web.xml文件要添加如下一句負(fù)載均衡配置
- <distributable/>
 
配置前
- <?xml version="1.0" encoding="UTF-8"?>
 - <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
 - <display-name>TomcatDemo</display-name>
 - </web-app>
 
配置后
- <?xml version="1.0" encoding="UTF-8"?>
 - <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
 - <display-name>TomcatDemo</display-name>
 - <distributable/>
 - </web-app>
 















 
 
 
 
 
 
 