代码之家  ›  专栏  ›  技术社区  ›  mumshad

Apache mod_jk负载平衡不起作用,但故障切换起作用

  •  1
  • mumshad  · 技术社区  · 12 年前

    我正在尝试使用mod_jk配置Apache负载平衡解决方案。集群可以工作,但不能进行负载平衡。

    我的笔记本电脑上运行着Apache httpd 2.2服务器。我有两个VMWare虚拟机来宾操作系统。这三个都是窗户。VMware机器承载为web应用程序提供服务的Apache Tomcat服务器。我已经用mod_jk配置了httpd.conf文件,并用worker信息配置了worker属性文件。我可以使用以下URL访问我的web应用程序: http://localhost/Web-application 。如果我停止一个服务器,那么应用程序将从另一个服务器提供服务。但并非两者同时发生。部分摘录如下:

    httpd.conf文件:

    LoadModule jk_module modules/mod_jk.so 
    JkWorkersFile conf/workers.properties
    JkLogFile "logs/mod_jk.log" 
    JkLogLevel info
    JkMount /MovieBooking loadbalancer
    JkMount /MovieBooking/* loadbalancer
    

    workers.properties文件

    workers.tomcat_home=/worker1
    workers.java_home=$JAVA_HOME
    worker.list=loadbalancer,jkstatus,worker1,worker2
    
     #Declare Tomcat server workers 1 through n
    
    worker.loadbalancer.type=lb
    worker.loadbalancer.balance_workers=worker1,worker2
    worker.loadbalancer.sticky_session=1
    
    worker.worker1.type=ajp13
    worker.worker1.host=192.168.200.244
    worker.worker1.port=8109
    worker.worker1.lbfactor=1
    
    worker.worker2.type=ajp13
    worker.worker2.port=8109
    worker.worker2.host=192.168.200.243
    worker.worker2.lbfactor=1
    
    worker.jkstatus.type=status
    

    我还在这些服务器上的server.xml文件中设置了jvm路由:

    服务器.xml

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">         
         <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
    

    如果需要更多的摘录,我可以上传

    2 回复  |  直到 12 年前
        1
  •  1
  •   f_puras    12 年前

    您使用粘性会话配置负载平衡的方式(对我来说还可以)意味着,一旦创建了会话,随后的请求将定向到同一Tomcat实例。您可以通过查看应附加的会话cookie值来识别这一点 .worker1 .worker2 。此后缀由Apache HTTPD用来决定将传入请求发送到哪个Tomcat实例。

    如果没有会话cookie,则应以循环方式在可用的Tomcats之间分发请求。因此,为了测试负载平衡,您通常需要几个持有不同会话cookie的浏览器实例。或者尝试设置 sticky_session=false 去看 全部的 请求以循环方式转发。

        2
  •  1
  •   oak    11 年前

    来自apache 以下为:

    • 所有会话属性都必须实现java.io.Serializable
    • 取消注释server.xml中的Cluster元素
    • 如果您已经定义了自定义集群阀,请确保在server.xml中的cluster元素下也定义了ReplicationValve
    • 如果Tomcat实例在同一台计算机上运行,请确保tcpListenPort属性对每个实例都是唯一的,在大多数情况下,Tomcat足够聪明,可以通过自动检测4000-4100范围内的可用端口自行解决此问题 确保你的web.xml包含元素
    • 如果您使用的是mod_jk,请确保在引擎中设置了jvm路由属性,并且jvm路由属性值与workers.properties中的worker名称匹配
    • 确保所有节点具有相同的时间并与NTP服务同步! 请确保您的负载平衡器已配置为粘性会话模式。

    我先试试 确保jvm路由正常

    Session stickyness is not implemented using a tracking table for sessions. Instead each Tomcat instance gets an individual name and adds its name at the end of the session id. When the load balancer sees a session id, it finds the name of the Tomcat instance and sends the request via the correct member worker. For this to work you must set the name of the Tomcat instances as the value of the jvmRoute attribute in the Engine element of each Tomcat's server.xml. The name of the Tomcat needs to be equal to the name of the corresponding load balancer member. In the above example, Tomcat on host "myhost1" needs jvmRoute="worker1", Tomcat on host "myhost2" needs jvmRoute="worker2".

    tomcat 2 jvm路由应该是“worker2”