tomcat负载均衡配置:集群和应用部分的代码

网络 网络优化 网络运维
本文针对的是负载集群配置下的tomacat集群配置代码的全部内容。通过完成下述的代码配置,产能将整个tomcat负载均衡配置全部完成。

前文,我们介绍了tomcat负载均衡安装和配置的内容,前面主要针对的是负载均衡的配置代码介绍。那么接下来,就是针对于tomcat集群配置的代码内容,之后的应用配置也做了简要的叙述。

◆tomcat集群配置

(1)负载均衡配置的条件下配置tomcat集群

(2)分别修改三个tomcat的配置文件conf/server.xml,修改内容如下

修改前

<!--   
<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>  
-->    
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.

#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 -->   
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.

将集群配置选项的注释放开即可,如上。

(3)重启三个tomcat。到此负载均衡配置下tomcat的集群已配置完成。#p#

◆应用配置

对于要进行负载和集群的的tomcat目录下的webapps中的应用中的WEB-INF中的web.xml文件要添加如下一句负载均衡配置

<distributable/> 
  • 1.

配置前

<?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> 
  • 1.
  • 2.
  • 3.
  • 4.

配置后

<?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> 
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.

 

责任编辑:佟健 来源: 互联网
相关推荐

2010-04-20 22:19:29

tomcat负载均衡配

2010-04-22 16:31:09

配置网络负载均衡

2014-07-28 11:37:49

NginxTomcat

2010-05-06 15:04:51

Tomcat负载均衡

2010-04-22 10:09:28

负载均衡器

2010-05-06 15:24:35

Tomcat负载均衡

2010-04-22 16:24:42

配置网络负载均衡

2010-04-20 21:27:28

tomcat负载均衡配

2010-04-21 12:28:50

Oracle负载均衡

2019-05-28 15:05:10

NginxTomcat负载均衡

2010-04-28 11:35:25

集群负载均衡

2010-04-23 10:03:42

tomcat负载均衡技术

2018-09-13 08:47:09

Tomcat负载均衡服务器

2020-03-11 19:38:39

Tomcat负载均衡配置

2010-04-27 13:20:38

负载均衡集群

2010-04-28 11:59:52

集群负载均衡

2010-04-22 11:47:58

集群负载均衡

2010-04-22 13:56:51

集群负载均衡

2019-12-24 14:28:00

KeepalivedNginxTomcat

2012-04-02 15:43:45

nginxtomcat
点赞
收藏

51CTO技术栈公众号