码迷,mamicode.com
首页 > Web开发 > 详细

apache server和tomcat集群配置二:垂直负载

时间:2017-01-19 12:12:33      阅读:220      评论:0      收藏:0      [点我收藏+]

标签:with   proc   机器   1.3   ajp   class   webapps   auto   request   

垂直负载就是同一个机器中的不同服务器之间的负载。跟水平负载(ip不一样的服务器之间的负载)的最大区别就是要修改tomcat的端口号,避免引起冲突。

还要注意apache中workers.properties的配置(worker.controller.sticky_session=false),这个一定要取消session的粘性,不然会一直发到同一个服务器中。

主要的修改点为

1.修改Tomcat 的ajp端口号,避免引起冲突

2.workers.properties的配置,worker.controller.sticky_session=false,取消粘性session

3.打开tomcat的cluster标签,使其支持集群,在打开一个Tomcat之后,打开另一个tomcat下,如果出现以下的输出,则表示集群加入成功:

信息: Replication member added:org.apache.catalina.tribes.membership.MemberImpl[tcp://{169, 254, 81, 38}:4001,{169, 254, 81, 38},4001, alive=1029, securePort=-1, UDP Port=-1, id={44 -83 62 97 -76 55 65 79 -85 47 35 -124 127 75 26 26 }, payload={}, command={}, domain={}, ]

4.打开apache,测试集群,不同的tomcat节点下sessionId是一样的表示集群成功:

   技术分享

技术分享

 

 

以下为worker.properties配置文件:

#下面是Tomcat实例列表,一个apache带一个或多个tomcat
worker.list=controller,tomcat1,tomcat2

#Tomcatbbs实例配置
worker.tomcat1.host=127.0.0.1
worker.tomcat1.port=8009     
#ajp13 端口号,在tomcat下server.xml配置,默认8009 
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 100   

#server的加权比重,值越高,分得的请求越多


#Tomcatwap实例配置
worker.tomcat2.host=127.0.0.1
worker.tomcat2.port=9009
worker.tomcat2.type=ajp13
#server的加权比重,值越高,分得的请求越多
worker.tomcat2.lbfactor = 100   

#========controller,负载均衡控制器========
worker.controller.type=lb
#指定分担请求的tomcat
worker.controller.balanced_workers=tomcat1,tomcat2   
#设置用于负载均衡的server的session可否共享  1:共享
worker.controller.sticky_session=false

 

 tomcat的server.xml的主要配置:

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

      <!--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"/>
      -->
      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- 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"/>
      </Realm>

      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

        <!-- 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
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log" suffix=".txt"
               pattern="%h %l %u %t &quot;%r&quot; %s %b" />

      </Host>
    </Engine>

 

 另外一个tomcat的配置:

<!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="9009" protocol="AJP/1.3" redirectPort="8443"/>


    <!-- An Engine represents the entry point (within Catalina) that processes
         every request.  The Engine implementation for Tomcat stand alone
         analyzes the HTTP headers included with the request, and passes them
         on to the appropriate Host (virtual host).
         Documentation at /docs/config/engine.html -->

    <!-- You should set jvmRoute to support load-balancing via AJP ie :
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="jvm1">
    -->
    <Engine defaultHost="localhost" name="Catalina" jvmRoute="tomcat2">

      <!--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"/>

      <!-- Use the LockOutRealm to prevent attempts to guess user passwords
           via a brute-force attack -->
      <Realm className="org.apache.catalina.realm.LockOutRealm">
        <!-- 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"/>
      </Realm>

      <Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">

        <!-- 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
             Note: The pattern used is equivalent to using pattern="common" -->
        <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>

      <Context docBase="TestCluster" path="/TestCluster" reloadable="true" source="org.eclipse.jst.jee.server:TestCluster"/></Host>
    </Engine>

 

 

 

    

 

apache server和tomcat集群配置二:垂直负载

标签:with   proc   机器   1.3   ajp   class   webapps   auto   request   

原文地址:http://www.cnblogs.com/toSeeMyDream/p/6305945.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!