设为首页 收藏本站
查看: 531|回复: 0

[经验分享] Apache 2.2.x+Tomcat6配置集群

[复制链接]

尚未签到

发表于 2017-1-6 11:13:11 | 显示全部楼层 |阅读模式
在我们部署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上测试通过!

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-324655-1-1.html 上篇帖子: apache 二级域名映射 解决方案 下篇帖子: 使用Capistrano部署apache+mongrel cluster
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表