tomcat+apache集羣

環境說明:
         系統: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集羣配置完成!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章