`
wooyung
  • 浏览: 27083 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Apache+Tomcat集群配置

 
阅读更多

 

准备环境

下载

Apache HTTP Server http://labs.mop.com/apache-mirror/httpd/binaries/win32/ 下载httpd-2.2.22-win32-x86-no_ssl.msi

 

JK http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/windows/ 下载tomcat-connectors-1.2.37-windows-i386-httpd-2.2.x.zip

 

Tomcat http://tomcat.apache.org/download-70.cgi

 

安装
安装Apache HTTP Server,如果没有其他的http服务器(如iis)则应该可以成功安装,端口即为80,能够访问http://localhost/ 说明安装成功。



安装Tomcat7,下载tomcat7解压缩为4个tomcat文件,分别命名tomcat1、tomcat2、tomcat3、tomcat4.

tomcat6.X与tomcat7.X集群通用。

配置

Apache配置
1、修改httpd.conf
在Apache安装目录下找到conf目录下的httpd.conf,在文件的最后一行添加
include conf/mod_jk.conf

2、新建mod_jk.conf文件,内容如下:

LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
#指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器名
JkMount /* controller

3、将下载的JK插件解压拷贝mod_jk.so,复制到Apache安装目录的modules目录下。

4、在apache的安装目录conf下新建并编辑workers.properties文件,内容如下:

#server
worker.list = controller

#========tomcat1========
worker.tomcat1.port=8719
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1
worker.tomcat1.redirect=tomcat2

#========tomcat2========
worker.tomcat2.port=8729
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1
worker.tomcat2.redirect=tomcat1
#worker.tomcat2.activation=disabled

#========tomcat3========
worker.tomcat3.port=8739
worker.tomcat3.host=localhost
worker.tomcat3.type=ajp13
worker.tomcat3.lbfactor = 1
worker.tomcat3.redirect=tomcat4

#========tomcat4========
worker.tomcat4.port=8749
worker.tomcat4.host=localhost
worker.tomcat4.type=ajp13
worker.tomcat4.lbfactor = 1
worker.tomcat4.redirect=tomcat3
#worker.tomcat4.activation=disabled 

#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2,tomcat3,tomcat4
worker.controller.sticky_session=false
#worker.controller.sticky_session_force=1
#worker.controller.sticky_session=1

 

 

PS:#worker.tomcat4.activation=disabled  表示tomcat是否激活

tomcat配置
Tomcat1中server.xml配置:
<Connector port="8781" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8719" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
<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="4001" 
                      autoBind="100" 
                      selectorTimeout="5000" 
                      maxThreads="6"/>  
            <!-- timeout="60000"-->  
            <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=""/>  
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>  
 
          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>  
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>  
        </Cluster>

....

 <Host name="localhost"  appBase="C:\tomcat7-ex\webapps"
            unpackWARs="true" autoDeploy="true">


Tomcat2中server.xml配置:
<Connector port="8782" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8729" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
<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="4001" 
                      autoBind="100" 
                      selectorTimeout="5000" 
                      maxThreads="6"/>  
            <!-- timeout="60000"-->  
            <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=""/>  
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>  
 
          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>  
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>  
        </Cluster>

....

 <Host name="localhost"  appBase="C:\tomcat7-ex\webapps"
            unpackWARs="true" autoDeploy="true">
Tomcat3中server.xml配置:
<Connector port="8783" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8739" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat3">
<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.5
                        port="45564" 
                        frequency="500" 
                        dropTime="3000"/>  
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
                        address="auto"
                      port="4001" 
                      autoBind="100" 
                      selectorTimeout="5000" 
                      maxThreads="6"/>  
            <!-- timeout="60000"-->  
            <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=""/>  
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>  
 
          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>  
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>  
        </Cluster>

...

 <Host name="localhost"  appBase="C:\tomcat7-ex\webapps"
            unpackWARs="true" autoDeploy="true">

Tomcat4中server.xml配置:
<Connector port="8784" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
<Connector port="8749" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat4">
<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.5
                        port="45564" 
                        frequency="500" 
                        dropTime="3000"/>  
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver" 
                        address="auto"
                      port="4001" 
                      autoBind="100" 
                      selectorTimeout="5000" 
                      maxThreads="6"/>  
            <!-- timeout="60000"-->  
            <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=""/>  
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>  
 
          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>  
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>  
        </Cluster>

...

     <Host name="localhost"  appBase="C:\tomcat7-ex\webapps"
            unpackWARs="true" autoDeploy="true">
注意AJP13的connector的poat和jvmRoute名称和workers.properties中配置对应。228.0.0.4和228.0.0.5表示tomcat的群组

基于windows环境搭建完毕,参考文档如下
1、Apache+Tomcat集群配置 http://charyle.iteye.com/blog/1017961
2、对tomcat cluster集群配置中session复制用法的一个误解 http://618119.com/archives/2007/11/13/26.html

分享到:
评论

相关推荐

    apache+tomcat集群配置

    Apache + Tomcat 集群配置 Apache + Tomcat 集群配置是指将 Apache 服务器与 Tomcat 服务器集成,以提高服务器的性能和可扩展性。本文将详细介绍如何配置 Apache + Tomcat 集群,包括安装 Apache 和 Tomcat 服务器...

    Apache+Tomcat服务器集群配置详细步骤

    #### 三、Apache+Tomcat集群配置步骤 **步骤1:环境准备** - 安装Apache。 - 安装两个Tomcat实例,并在各自的`webapps`目录下部署测试项目。 **步骤2:JK插件配置** - 将`mod_jk.so`复制到`&lt;apache_home&gt;/...

    Apache+Tomcat集群配置续

    Apache+Tomcat集群配置续Apache+Tomcat集群配置续Apache+Tomcat集群配置续Apache+Tomcat集群配置续

    apache+tomcat集群配置文件和文档

    这份"apache+tomcat集群配置文件和文档"将涵盖以上所有要点,指导你逐步配置和测试Apache+Tomcat集群。按照文档操作,你将能够构建出一个高效且稳定的Web服务环境。在实际操作中,务必根据你的硬件资源和具体需求...

    apache+tomcat集群配置文件和文档说明

    总结,"apache+tomcat集群配置文件和文档说明"涵盖了Apache和Tomcat的集群配置,涉及Apache的负载均衡配置、Tomcat的session复制和集群通信设置,以及Java环境的准备。通过这些配置,可以构建一个高可用的Web服务...

    apache+tomcat集群文档

    - 本文档针对Apache Tomcat集群配置进行了详尽的说明,特别适合新手入门学习,通过本文档能够快速掌握Apache Tomcat集群的基本概念、搭建步骤及注意事项。 #### 知识点详解: ##### 一、集群基础知识 1. **学习...

    apache+tomcat集群

    apache+tomcat集群 配置使用方法

Global site tag (gtag.js) - Google Analytics