【问题标题】:Load balancer not forwarding request to second tomcat instance负载均衡器未将请求转发到第二个 tomcat 实例
【发布时间】:2014-08-25 10:23:22
【问题描述】:

我在我的机器上运行 2 个 tomcat 实例,两个 tomcat 的 server.xml 中有以下条目:

Tomcat 1::

<Connector port="8081" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8444" />
    <!-- A "Connector" using the shared thread pool-->
    <!--
    <Connector executor="tomcatThreadPool"
               port="8080" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" />
    -->
    <!-- Define a SSL HTTP/1.1 Connector on port 8443
         This connector uses the BIO implementation that requires the JSSE
         style configuration. When using the APR/native implementation, the
         OpenSSL style configuration is required as described in the APR/native
         documentation -->
    <!--
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
               maxThrea="150" SSLEnabled="true" scheme="https" secure="true"
               clientAuth="false" sslProtocol="TLS" />
    -->

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

Tomcat2 : server.xml::

<Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
<!-- A "Connector" using the shared thread pool-->
<!--
<Connector executor="tomcatThreadPool"
           port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" />
-->
<!-- Define a SSL HTTP/1.1 Connector on port 8443
     This connector uses the BIO implementation that requires the JSSE
     style configuration. When using the APR/native implementation, the
     OpenSSL style configuration is required as described in the APR/native
     documentation -->
<!--
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol"
           maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
           clientAuth="false" sslProtocol="TLS" />
-->

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

两个 tomcat 实例并行运行。

现在我最后在 /etc/httpd/httpd.conf 文件中引入了负载均衡器和以下条目

 #
    # Load mod_jk
    #
    LoadModule jk_module modules/mod_jk.so
    JkWorkersFile conf/workers.properties
    JkLogFile logs/mod_jk.log
    JkLogLevel info
    JkLogLevel debug
    JkLogLevel warn
    JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
    JkMount / loadbalancer
    JkMount /* loadbalancer

而worker.properties 文件为::

worker.list=loadbalancer

worker.jvm1.port=8009
worker.jvm1.host=127.0.0.1
worker.jvm1.type=ajp13
worker.jvm1.lbfactor=1
worker.jvm1.max_packet_size=65536
#worker.jvm1.socket_timeout=60
#worker.jvm1.connection_pool_timeout=60

worker.jvm2.port=8010
worker.jvm2.host=127.0.0.1
worker.jvm2.type=ajp13
worker.jvm2.lbfactor=1
worker.jvm2.max_packet_size=65536
#worker.jvm2.socket_timeout=60
#worker.jvm2.connection_pool_timeout=60

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=jvm1,jvm2
worker.loadbalancer.sticky_session=0

worker.jvm1.socket_keepalive=1
worker.jvm2.socket_keepalive=1
worker.loadbalancer.method=B

现在重新启动 httpd 服务,然后重新启动 tomcat 并执行测试,我发现负载均衡器只是转发重新 追求 tomcat1 而不是 tomcat2。我将请求速率提高到每秒 1000 个请求,仍然没有转发到 tomcat2。

在 worker.properties 中,我禁用了 jvm1,然后重新启动了 httpd 和 tomcat2。我收到以下错误::

    ==> error_log <==
    [Fri Jul 04 15:44:52 2014] [error] (111)Connection refused: proxy: HTTP: attempt to connect to 127.0.0.1:8080 (paisa-tomcat) failed
    [Fri Jul 04 15:44:52 2014] [error] ap_proxy_connect_backend disabling worker for (paisa-tomcat)

==> error_log <==
[Fri Jul 04 15:44:52 2014] [error] proxy: HTTP: disabled connection for (paisa-tomcat)

==> error_log <==
[Fri Jul 04 15:44:52 2014] [error] proxy: AJP: disabled connection for (paisa-tomcat)

【问题讨论】:

    标签: apache rest tomcat load-balancing mod-jk


    【解决方案1】:

    我认为它的“worker.loadbalancer.method=B”:

    如果设置为B[usyness],平衡器将根据工作人员当前正在处理的请求数量选择当前负载最低的工作人员。这个数字除以工人 lbfactor,并选择最低值(最不忙)的工人。如果您的请求需要很长时间才能处理,例如下载应用程序,则此方法特别有趣。

    尝试将其设置为“N”以进行循环,即使用两个不同的浏览器进行测试。

    【讨论】:

    • 您是否在引擎元素中设置了“jvmRoute”属性?即:jvmRoute="jvm1"
    • 在您的帖子中找不到它。它应该看起来像这样:&lt;Engine defaultHost="localhost" jvmRoute="jvm1" name="Catalina"&gt;
    • 在一个 tomcat 中,在 server.xml 中我添加了 并在其他文件中添加了
    • 在 worker.properties 中,我禁用了 jvm1,然后重新启动了 httpd 和 tomcat2。我得到以下信息:[Fri Jul 04 15:44:52 2014] [error] (111)Connection denied: proxy: HTTP: 尝试连接到 127.0.0.1:8080 (paisa-tomcat) 失败 [Fri Jul 04 15: 2014 年 44:52] [错误] ap_proxy_connect_backend 禁用(tomcat)错误日志的工作人员:[2014 年 7 月 4 日星期五 15:44:52] [错误] 代理:HTTP:禁用连接(paisa-tomcat)==> error_log
    猜你喜欢
    • 1970-01-01
    • 2013-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-05
    • 1970-01-01
    相关资源
    最近更新 更多