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


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

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

    主要的修改点为

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

    2.workers.properties的配置,worker.controller.sticky_session=false,取消粘性session。要说明的是worker.controller.sticky_session=1,等同于worker.controller.sticky_session=true.此处指定集群是否需要会话复制,如果设为true,则表明为会话粘性,不进行会话复制,当某用户的请求第一次分发到哪台Tomcat后,后继的请求会一直分发到此Tomcat服务器上处理;如果设为false,则表明会按照负载配置分发到相应的服务器中去。

    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>

        

  • 相关阅读:
    实用的 jquery 弹出窗口 插件winbox
    软考大纲
    那些年踩过三轮车的程序员
    今天是周几?
    本故事荣获2011年度最佳故事情节奖.
    命令行修改linux时间
    [置顶] 自考,认证相关资料
    金山软件面试题
    del
    【转】数据结构:位图法
  • 原文地址:https://www.cnblogs.com/toSeeMyDream/p/6305945.html
Copyright © 2020-2023  润新知