简体   繁体   中英

Load balancer not forwarding request to second tomcat instance

I am running 2 instance of tomcat on my machine with following entries in server.xml in both tomcat :

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

Both tomcat instances are running parallel.

Now i introduced load balancer with following entries in /etc/httpd/httpd.conf file at last

 #
    # 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

And with workers.properties file as::

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

Now on restarting the httpd services and then restaring the tomcat and performing testing , i found that load balancer is only forwarding re quest to tomcat1 and not to tomcat2. I increased the request rate to 1000 request per second , still no forwarding to tomcat2.

In worker.properties , i disabled jvm1 and then restarted httpd and tomcat2. I am getting following error::

    ==> 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)

I think its "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.

Try to set it to "N" for round-robin, and ie use two different browsers, to test.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM