Apache2.4+Tomcat6.0版本集群

来源:互联网 发布:七牛php base64上传 编辑:程序博客网 时间:2024/05/19 16:38
上周四应要求做了一次Tomcat6的负载均衡和集群.虽说是超简单的一件事情,但是里面的一些东西的设置是非常值得大家注意的!不知道大家有谁对于这个有更好的见解!希望大家放上来啊!我会在最快的时间把文档整理好!(这个题目里面的内容会根据我整理的东西进行不断变化!)

      不好意思啊!最近有一点点事情!今天我继续把这个方案写完!

Apache2.4+Tomcat6.0版本集群配置过程:

  1. 环境说明
       
Windows XP
wamp5_1.7.3.exe  http://www.wampserver.com
mod_jk-apache-2.2.4.so http://tomcat.apache.org/download-connectors.cgi
apache-tomcat-6.0.14.zip http://tomcat.apache.org/download-55.cgi


我的程序分别安装到:
1.C:/wamp  这个是apache要用的!
2.一个机器装D:/apps/tomcat1
3.另一个机器装D:/apps/tomcat2

2.负载均衡:
        1. 修改文件C:/wamp/Apache2/conf/httpd.conf,在最后一行增加:include "c:/wamp/apache2/conf/mod_jk.conf"
       2.在C:/wamp/Apache2/conf下新建文件mod_jk.conf ,里面内容写成:

CODE:

#加载mod_jk Module
LoadModule jk_module modules/mod_jk-apache-2.2.4.so
#指定 workers.properties文件路径
JkWorkersFile conf/workers.properties
#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器
JkMount /*.jsp controller
JkMount /* controller

      3.把mod_jk-apache-2.2.4.so 拷贝到C:/wamp/Apache2/modules里
      4.然后在C:/wamp/Apache2/conf下新建文件workers.properties   里面内容修改成:

CODE:

worker.list = controller #,tomcat1,tomcat2 #server 列表
#========tomcat1========
worker.tomcat1.port=8009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=localhost #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
#========tomcat2========
worker.tomcat2.port=8009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=172.10.10.11 #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1 #server的加权比重,值越高,分得的请求越多

#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2 #指定分担请求的tomcat
worker.controller.sticky_session=true #这个是session复制用


3.tomcat设置:
      1.修改文件D:/apps/tomcat-6.0.14/conf/server.xml  ,把里面的

CODE:


<Server port="8005" shutdown="SHUTDOWN">

的端口都改成所有的tomcat都不一样就可以了!
     2.在D:/apps/tomcat-6.0.14/conf/server.xml  文件中找到:

CODE:


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

在这个上面增加:

CODE:


<Engine name="Standalone" defaultHost="localhost" jvmRoute="tomcat1">      
  </Engine>

    3.在D:/apps/tomcat-6.0.14/conf/server.xml  文件中找到:

CODE:


<!--
      <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
      -->

然后在后面增加:

CODE:


<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"
           channelSendOptions="6">
       <!--
        <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.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>   
     

然后另外一个tomcat也要设置啊!设置方式跟这个差不多!

最后先启动tomcat,然后启动apache  ,这样就可以了!

所需要的文件:

Tomcat集群所需要文件.rar
(2007-10-24 13:10:28, Size: 86 KB, Downloads: 18)

转贴于:http://www.itshaik.com/html/91/t-291.html 
原创粉丝点击