3.tomcat负载均衡和集群配置
参考官方配置文档:
a.tomcat6配置文件server.xml和应用程序的web.xml
**开放负载均衡,默认使用ajp协议时使用8009端口(使用http协议时为8080端口)
**修改tomcat 的 conf/server.xml 的<Engine>(使用ajp协议时配置)
把
<!-- You should set jvmRoute to support load-balancing via AJP ie :
<Engine defaultHost="localhost" jvmRoute="jvm1">
-->
<Engine defaultHost="localhost">
改成
<!-- You should set jvmRoute to support load-balancing via AJP ie :
-->
<Engine defaultHost="localhost" jvmRoute="tomcat1">
<!--
<Engine defaultHost="localhost">
-->
说明:
第一台tomcat就把jvmRoute="tomcat1"
第二台tomcat就把jvmRoute="tomcat2"
第三台tomcat就把jvmRoute="tomcat3"
**开放集群
**修改tomcat 的 conf/server.xml (使用ajp协议时配置)
在<Engine> 后面或者 <Host>后面简单的加上
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
也可以加上更详细参数的集群配置内容(这是官方默认,请自行修改相关参数):
<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"
port="4000"
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>
***配置应用的web.xml
***在每个webapps应用中,修改配置文件web.xml文件 添加元素<distributable/>
在web.xml文件中<web-app>元素下增加以下内容:
<!--此应用将与群集服务器复制Session-->
<distributable/>
具体修改如下:
修改前:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://Java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee "
version="2.5">
</web-app>
修改后:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee "
version="2.5">
<!--此应用将与群集服务器复制Session-->
<distributable/>
</web-app>
ajp负载均衡加集群实战(3)
内容版权声明:除非注明,否则皆为本站原创文章。