Tomcat6 集群配置

来源:互联网 发布:飞鸽网络打印机不能用 编辑:程序博客网 时间:2024/06/11 07:45

   Tomcat 6.0.20 集群配置
1 准备工具:
(1) Apache Httped 前置服务器
版本:apache_2.2.14
文件名:apache_2.2.14-win32-x86-openssl-0.9.8k.msi
下载地址:http://httpd.apache.org/download.cgi
(2) Apache Tomcat Connectors
版本:Apache Tomcat Connectors 1.2.28 for WIN32
文件名:mod_jk-1.2.28-httpd-2.2.3.so
下载地址:http://apache.deathculture.net/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/
(3) Apache Tomcat 6.0.20
版本:Tomcat 6.0.20
2 配置前置服务器(Apache 2.2)
(1) 安装apache_2.2.14-win32-x86-openssl-0.9.8k.msi,其中有选择服务端口的配置,默认为80
(2) 将mod_jk-1.2.28-httpd-2.2.3.so拷贝到已经安装的Apache 2.2 目录下的modules 目录,并重命名为:mod_jk.so
(3) 在Apache 2.2 目录下的 conf 目录下,新建workers.properties文件,用于配置集群点的IP、监听端口……
一般配置如下:
worker.list=loadBalancer
#定义一个集群节点 ,分发名为tomcat1,IP地址为18.0.0.170
worker.tomcat1.port=8009
worker.tomcat1.host=18.0.0.170
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1 #加权比重,值越高,分得的请求越多
#定义一个集群节点,分发名为tomcat2,IP地址为18.0.0.110
worker.tomcat2.port=9009
worker.tomcat2.host=18.0.0.110
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1 #加权比重,值越高,分得的请求越多
#指定分担请求的tomcat,及session复制
worker.loadBalancer.type=lb
worker.loadBalancer.balance_workers=tomcat1,tomcat2
worker.loadBalancer.sticky_session=true
worker.loadBalancer.sticky_session_force=true
其他常见配置,可选:
 # worker "worker2" uses connections, which will
 #stay no more than 10mn in the connection pool
   worker.worker2.connection_pool_timeout=600
 # worker "worker2" ask operating system to send #KEEP-ALIVE signal #on the connection
   worker.worker2.socket_keepalive=1
worker.worker2.connection_pool_size=10
(4) 打开安装Apache 2.2 目录下的 conf 目录,打开httpd.conf文件,将下面内容拷贝到文件里面:
    # 加载 mod_jk 模块
LoadModule jk_module modules/mod_jk.so
# 引入workers.peroperties文件配置
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
#指定那些请求交给tomcat处理," loadBalancer "为在workers.propertise里指定#的负载分配控制器
JkMount /*.jsp loadBalancer
JkMount /* loadBalancer
注意:(3) 和(4) 的文件配置中的属性有版本限制,具体可以参考:
http://tomcat.apache.org/connectors-doc/reference/workers.html
http://tomcat.apache.org/connectors-doc/generic_howto/workers.html
(5)  配置集群节点tomcat server.xml文件
.找到<Engine />节点,加入属性 jvmRoute:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
其中tomcat1,就是前面workers.properties 配置中的分发节点名称
.找到<Cluster /> 节点,用下面内容替换:
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
          <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="4000"
                      autoBind="100"
                      selectorTimeout="5000"
                      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>
Apche 官方文档:http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html
介绍很清楚,当然只有这些配置还不够,官方文档里有这么一句:
 
在项目web.xml里面要有<distributable />属性,或是在context.xml 中的<Context />属性里加入 distributable=”true”, 这样才能分发!

 


先启动一个tomcat,完成后再启动另一个,依次启动完成后,再启动Apache2.2

原创粉丝点击