Linux下搭建Apache+Tomcat负载均衡集群

之前写了一篇文章Apache服务器的安装及相关问题处理方案  ,本文就是为了补充当时的那篇文章而写。现在再次想尝试一下怎么在Linux下搭建Apache+Tomcat负载均衡集群,但是发现自己记得不是很清楚了,然后就写下了这篇文章。

负载均衡集群配置(1):Tomcat的配置

修改“ tomcat/conf/server.xml ”文件
编辑server.xml文件,找到“<Connector>”元素节点,在server.xml文件里面未注释掉的有两个<Connector>元素节点。找到第二个也就是上面一行注释为

<!-- Definean AJP 1.3 Connector on port 8009 -->

的节点。将其修改为
———————————–需要操作的代码———————————————-

<!-- Define an AJP 1.3 Connector on port 8009 --> <Connector port="8009" protocolhandlerclassname="org.apache.jk.server.jkcoyotehandler" protocol="AJP/1.3" redirectPort="8443" />

注意:如果是在一台PC上同时运行多个tomcat,须将每个tomcat对的server.xml文件里面的“<Connector>”元素节点里面的port(端口号)设置为不同的值。这里不同上面只改第二个,而是两个“<Connector>”元素节点都须要修改。

负载均衡集群配置(2):

接下来继续修改这个文件,找到“<Connector>”元素节点下面的注释如下

<!-- An Engine represents the entry point (within Catalina) that processes every request. The Engine implementation for Tomcat stand alone analyzes the HTTP headers included with the request, and passes them on to the appropriate Host (virtual host). Documentation at /docs/config/engine.html --> <!-- You should set jvmRoute to support load-balancing via AJP ie : <Engine defaultHost="localhost" jvmRoute="jvm1"> -->

​里面有

<Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">

将其注释打开。这里进行tomcat的命名,即修改jvmRoute的值为tomcat实例名,不同的tomcat设置不同的值(这里不管是否是同一PC都须不同)。比如我的修改为tomcat1和tomcat2
———————————–需要操作的代码———————————————-

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1" >

负载均衡集群配置(3):

接下来还是操作tomcat的server.xml文件,在<Engine>或<Host>元素节点下添加以下内容
———————————–需要操作的代码———————————————-

<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"> <Manager className="org.apache.catalina.ha.session.BackupManager" expireSessionsOnShutdown="false" notifyListenersOnReplication="true" mapSendOptions="6"/> <!-- <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.1.99" port="45564" frequency="500" dropTime="3000"/> <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" address="192.168.11.128" port="4002" autoBind="100" selectorTimeout="100" 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>

上述添加的代码的用处请继续看第4步。

负载均衡集群配置(4):

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/82debfbbe20a9701eac57d187c41a5e8.html