| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
12年前发布

Apache+Tomcat集群配置(完整配置)

这几天做Apache和Tomcat集群,我测试成功了,下面给个共享:

    环境说明:
         系统:windows xp
         服务器:apache_2.2、mod_jk_2.2(插件和apache版本一致)
         集群服务器:apache-tomcat6(分配在三台pc上)

   A、安装apache_2.2、apache-tomcat6
        跳过:(注意:apache_2.2默认端口是80,如有其它程序占用可在httpd.conf修改   Listen     80)

   B、负载均衡配置 
        将mod_jk-apache-2.0.59.so copy到Apache的modules目录中。

        在apache的安装目录中找到conf/httpd.conf文件,打开此文件在其末尾添加:
         include "C:\Program Files\Apache Software Foundation\Apache2.2\conf\mod_jk.conf"

        在conf目录下创建你上面引用的文件   (mod_jk.conf)

        内容:
             #加载mod_jk Module
               LoadModule jk_module modules/mod_jk-apache-2.0.59.so
             #指定 workers.properties文件路径
               JkWorkersFile workers.properties
             #指定哪些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器名
               JkMount /*.jsp controller
             如果所有请求都需要负载均衡处理就是  /*

        在conf目录下新建workers.properties文件并添加如下内容:

           worker.list = controller,tomcat1,tomcat2
           #========tomcat1========
           worker.tomcat1.port=9878
           worker.tomcat1.host=192.168.3.199
           worker.tomcat1.type=ajp13
           worker.tomcat1.lbfactor = 1 #加权因子 越大执行的请求越多
           #========tomcat2========
           worker.tomcat2.port=9879
           worker.tomcat2.host=127.0.0.1
           worker.tomcat2.type=ajp13
           worker.tomcat2.lbfactor = 1 
    
           #========controller,负载均衡控制器========
           worker.controller.type=lb
           worker.controller.balanced_workers=tomcat1,tomcat2
           worker.controller.sticky_session=1

         分别配置各个tomcat
          (注意服务器集群分为水平集群[多个服务器在同一台pc上]和垂直集群[不同pc上],如果是后者就不需要做如下配置,只要上面的ajp13端口和server.xml中对应就行)
           将AJP13 Connector port改为9878与上面worker.tomcat2.port对应
           <Connector port="9878" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" />

        修各个tomcat 在下面配置中加 jvmRoute="tomcat1"和tomcat2找规律吧(不分水平集群和垂直集群都要配置)!
         <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

-------------------------------这里负载均衡完成了!!!----------------------------------------------

    C、集群配置

            在server.xml中找到 <Host>节点在里面添加如下配置:
          (注意有些文章说是放开<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>我试过不行,所以不可行,有时间可以试试)

            <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"        
                   channelSendOptions="6">
                   <Manager className="org.apache.catalina.ha.session.BackupManager"
                    expireSessionsOnShutdown="false" notifyListenersOnReplication="true"
                    mapSendOptions="6" />
  
               <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="5000" 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" />
        <Interceptor
             className="org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor" />
           </Channel>
  
           <Valve className="org.apache.catalina.ha.tcp.ReplicationValve"
                filter=".*\.gif;.*\.js;.*\.jpg;.*\.png;.*\.htm;.*\.html;.*\.css;.*\.txt;" />
  
           <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.ClusterSessionListener" />
        </Cluster>

到此Apache+tomcat集群配置完成!写个增删改查测试下吧!会得到预期效果的。

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1365861795031.html
Apache Tomcat 应用服务器