四、 详细配置:
1. 修改tomcat7_a/conf/server.xml, 我们采用的是默认的配置,在<Engine>节点下添加:
<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"
<!—tcpListenPort如果是同一机器部署两个tomcat7应用,则修改tomcat7_b为4001,以免冲突. 不同机器下,不用更改此项。—>
[color=red]port="4000"[/color]
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>
2. <Connector port="8081" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" /> 修改,仅为了调试方便。
3. tomcat7_a\webapps\cluster\WEB-INF\web.xml中加入<distributable/>
4. <Engine defaultHost="localhost" jvmRoute="tomcat7_a">,添加jvmRoute属性,此项为后面apache负载均衡用到。
五、 复制一份tomcat7_a应用,改名为tomcat7_b.只是为了图方便,实际应该复制的是前面的cluster工程。注意以下几点配置就ok.
1. 修改tomcat7_a/conf/server.xml 中的Server port属性<Server port="8006" shutdown="SHUTDOWN">,因为是同一台机器两个tomcat应用,所以改一下。
2. 修改<connector port="8082" protocol="HTTP/1.1" onnectionTimeout="20000" edirectPort="8443" />,同理,为了避免同一台机器端口号冲突。部置在不同的机器是不用管的。
3. 修改<Engine defaultHost="localhost" jvmRoute="tomcat7_b">,此项为后面apache负载均衡用到。
4. 修改<Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="auto" port="4001" autoBind="100" selectorTimeout="5000" maxThreads="6"/>
5. tomcat7_b\ebapps\cluster\WEB-INF\web.xml中加入<distributable/>
到此集群配置完成.