apache - 负载均衡器不将请求转发到第二个 tomcat 实例

标签 apache rest tomcat load-balancing mod-jk

我在我的机器上运行 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: 服务器.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

并将 workers.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)

最佳答案

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

If set to B[usyness] the balancer will pick the worker with the lowest current load, based on how many requests the worker is currently serving. This number is divided by the workers lbfactor, and the lowest value (least busy) worker is picked. This method is especially interesting, if your request take a long time to process, like for a download application.

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

关于apache - 负载均衡器不将请求转发到第二个 tomcat 实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24568195/

相关文章:

php - 升级Wamp服务器

rest - Dialogflow 未检测上下文意图

node.js - Rest API Kafka 流

tomcat - pmap 中巨大的匿名 block

security - Tomcat 7 安全 - 尝试登录?

mysql - 配置mySQL继承操作系统的时区

git - 如何使用 Apache 反向代理设置 SSH 端口转发

php - 解析 REST API : Having the channel name, 我可以在实际发送到 Push 之前获取设备类型吗?

tomcat - 为什么 "Spring MVC Project"中的模板 "SpringSource Tool Suite"不适用于 Tomcat?

git - 使用 git post-receive hook 的边带解复用器出错