`
phoebird
  • 浏览: 117681 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

Apache 2.2.x+Tomcat6配置集群

    博客分类:
  • web
阅读更多
在我们部署Web应用时,不可避免大多都会涉及到集群问题,此文作为Apache 2.2.x+Tomcat6配置集群的备忘。

配置Tomcat6 的conf\server.xml文件,启用集群设置,如果在本地同时运行多个Tomcat进行测试的话,需要修改部分端口号,以避免冲突
打开AJP:<Connector port="9009" protocol="AJP/1.3" redirectPort="9443" />
打开集群:
Xml代码
   <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm2">   
 
     <!--For clustering, please take a look at documentation at:  
         /docs/cluster-howto.html  (simple how to)  
         /docs/config/cluster.html (reference documentation) --> 
       
      
<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="5001"      
    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> 
 
 
         
 
     <!-- The request dumper valve dumps useful debugging information about  
          the request and response data received and sent by Tomcat.  
          Documentation at: /docs/config/valve.html --> 
     <!-- 
     <Valve className="org.apache.catalina.valves.RequestDumperValve"/> 
     --> 
 
     <!-- This Realm uses the UserDatabase configured in the global JNDI  
          resources under the key "UserDatabase".  Any edits  
          that are performed against this UserDatabase are immediately  
          available for use by the Realm.  --> 
     <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
            resourceName="UserDatabase"/> 
 
     <!-- Define the default virtual host  
          Note: XML Schema validation will not work with Xerces 2.2.  
      --> 
     <Host name="localhost"  appBase="webapps" 
           unpackWARs="true" autoDeploy="true" 
           xmlValidation="false" xmlNamespaceAware="false"> 
 
       <!-- SingleSignOn valve, share authentication between web applications  
            Documentation at: /docs/config/valve.html --> 
       <!-- 
       <Valve className="org.apache.catalina.authenticator.SingleSignOn" /> 
       --> 
 
       <!-- Access log processes all example.  
            Documentation at: /docs/config/valve.html --> 
       <!--  
       <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"    
              prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/> 
       --> 
 
     </Host> 
   </Engine> 

    <Engine name="Standalone" defaultHost="localhost" jvmRoute="jvm2">

      <!--For clustering, please take a look at documentation at:
          /docs/cluster-howto.html  (simple how to)
          /docs/config/cluster.html (reference documentation) -->
     
    
<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="5001"   
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>


       

      <!-- The request dumper valve dumps useful debugging information about
           the request and response data received and sent by Tomcat.
           Documentation at: /docs/config/valve.html -->
      <!--
      <Valve className="org.apache.catalina.valves.RequestDumperValve"/>
      -->

      <!-- This Realm uses the UserDatabase configured in the global JNDI
           resources under the key "UserDatabase".  Any edits
           that are performed against this UserDatabase are immediately
           available for use by the Realm.  -->
      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
             resourceName="UserDatabase"/>

      <!-- Define the default virtual host
           Note: XML Schema validation will not work with Xerces 2.2.
       -->
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true"
            xmlValidation="false" xmlNamespaceAware="false">

        <!-- SingleSignOn valve, share authentication between web applications
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
        -->

        <!-- Access log processes all example.
             Documentation at: /docs/config/valve.html -->
        <!--
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" 
               prefix="localhost_access_log." suffix=".txt" pattern="common" resolveHosts="false"/>
        -->

      </Host>
    </Engine>2.打开Apache下的conf\httpd.conf文件,打开注释:

Html代码
LoadModule proxy_module modules/mod_proxy.so  
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so  
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so  
LoadModule proxy_connect_module modules/mod_proxy_connect.so  
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so  
LoadModule proxy_http_module modules/mod_proxy_http.so 

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule proxy_http_module modules/mod_proxy_http.so

在文件末尾添加:

Html代码
ProxyRequests Off     
<Proxy balancer://cluster>      
    BalancerMember ajp://localhost:8009 loadfactor=1 route=jvm1 
    BalancerMember ajp://localhost:9009 loadfactor=1 route=jvm2 
</Proxy>  

ProxyRequests Off  
<Proxy balancer://cluster>   
BalancerMember ajp://localhost:8009 loadfactor=1 route=jvm1
BalancerMember ajp://localhost:9009 loadfactor=1 route=jvm2
</Proxy> 配置VirtualHost:

Xml代码
<VirtualHost *:80>     
         ServerAdmin test@126.com     
         ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On     
         ProxyPassReverse / balancer://cluster/   
         ServerName www.mytest.com  
         ServerAlias mytest.com    
</VirtualHost>  

<VirtualHost *:80>  
         ServerAdmin test@126.com  
         ProxyPass / balancer://cluster/ stickysession=jsessionid nofailover=On  
         ProxyPassReverse / balancer://cluster/
         ServerName www.mytest.com
         ServerAlias mytest.com 
</VirtualHost> 

在应用程序的web.xml结尾加入:

Html代码
<distributable/> 

<distributable/>

运行http://www.mytest.com,从tomcat日志可看出均衡和集群都起了作用,以上配置在WinXP +  Apache 2.2.8 + tomcat6上测试通过!

分享到:
评论

相关推荐

    Apache2.2.x+Tomcat6.x+jk2.x做集群配置

    Apache2.2.x + Tomcat6.x + jk2.x 集群配置教程 在互联网服务中,为了提供高可用性和负载均衡,通常会采用集群技术。Apache HTTP Server(通常简称为Apache)与Tomcat的结合是常见的Web服务器与应用服务器组合。...

    apache 2.X+tomcat 6.X/7.X集群配置

    Apache 2.X 和 Tomcat 6.X/7.X 集群配置是一个常见的技术实践,用于提高Web应用程序的性能和可扩展性。Apache HTTP Server(通常称为Apache)是一款开源的HTTP服务器,而Tomcat则是一个开源的Java Servlet容器,主要...

    apache2.2+tomcat6集群配置

    Apache2.2与Tomcat6集群配置是一种常见的Web服务架构,用于提高网站的可用性和可扩展性。在Windows环境下,这种配置可以实现负载均衡,确保即使单个服务器出现故障,整个系统仍然能继续运行,同时分散请求以降低单一...

    mod_jk(包含apache2.4.x和apache2.2.x的两种版本)

    **Apache mod_jk模块详解与Tomcat集群配置** Apache mod_jk是Apache HTTP服务器的一个模块,主要用于连接Apache和Tomcat,实现两者之间的通信。在Java应用服务器领域,Tomcat广泛用作Servlet和JSP容器,而Apache则...

    Windows下Apache2.2+Tomcat6配置集群、负载均衡、session共享

    在Windows环境下,Apache2.2和Tomcat6的组合是一个常见的Web服务器架构,用于搭建集群、实现负载均衡和处理session共享。Apache作为前端反向代理服务器,负责分发请求到后端的多个Tomcat实例,以提高应用的可用性和...

    apache+tomcat集群配置

    下载 mod_jk 模块安装包,例如 tomcat-connectors-1.2.39-windows-i386-httpd-2.2.x.zip,然后解压到 Apache 服务器的安装目录下的 modules 目录下,例如 E:\Apache2.2\modules。 四、配置 Apache 服务器 配置 ...

    Apache2.2.25 + Tomcat6.0.45 + mod_jk + 测试页面 + 集群

    本资源包含了文章Apache2.2.x + Tomcat6.x + JK 集群配置,http://blog.csdn.net/qq396229783/article/details/74295797里面所用到的软件配置

    Apache2.2.19 + Tomcat-6026+ mod_jk-apache-2.2.xx.so 配置集群

    首先,了解Apache和Tomcat集群的基础概念。集群是一种将多台服务器连接在一起,以提供更高可用性和性能的技术。在这个配置中,Apache作为前端服务器,负责接收客户端请求并分发到后端的Tomcat服务器,Tomcat则处理...

    Apache2.2 tomcat-6.0.18负载均衡与集群

    在Apache2.2+Tomcat集群中,可以实现会话复制,确保用户在集群中的任何一台服务器上都能继续其之前的会话。Tomcat的集群功能依赖于org.apache.catalina.ha.session.JvmRouteBinderValve,它添加了JVM路由信息到...

    Apache2.2+tomcat7+jk+jdk1.6

    本配置"Apache2.2+tomcat7+jk+jdk1.6"旨在实现一个稳定且可靠的环境,特别关注于session的共享与管理,以解决多服务器间的session一致性问题。 Apache2.2是Apache HTTP Server的第2.2版本,提供了强大的静态内容...

    Apache动态域名+JK+Tomcat添加Tomcat系统服务 集群

    DocumentRoot "E:/Program Files/Apache2.2/htdocs" ServerName yangyu2012.gnway.net ErrorLog logs/dummy-host.example.com-error_log CustomLog logs/dummy-host.example.com-access_log common ``` 保存...

    Apache2.2+Tomcat集群

    Apache2.2+Tomcat集群 只是一个简单的集群例子,所用到的Apache,Tomcat压缩文件里都有

    Apache和Tomcat集群配置步骤(Apache2.2,Tomcat6.0).

    ### Apache和Tomcat集群配置详解 #### 一、软件准备 在进行Apache和Tomcat集群配置之前,首先需要准备所需的软件资源。 - **Apache 2.2**: - Windows平台: 从官方网站 [http://httpd.apache.org/download.cgi]...

    Linux+tomcat6+apache2.2集群部署

    在本文中,我们将深入探讨如何在Linux环境下部署一个基于Tomcat 6和Apache 2.2的集群。首先,我们需要准备相应的软件包,包括JDK、Apache HTTP服务器、Tomcat以及JK模块,这些是构建集群的基础组件。 1. **JDK安装*...

    apache2.2+mod_JK+Tomcat7+Terracotta3.7 集群(重要)

    通过合理配置tc-config.xml,你可以实现高效的Tomcat集群和会话共享,从而为大型Web应用提供稳定且高性能的服务。在实际操作中,需要注意监控集群的性能,适时调整配置参数,以适应不断变化的业务需求。同时,确保...

Global site tag (gtag.js) - Google Analytics