开发者

Apache Load Balancer on Top of Tomcat 6 - Missing Something and it's Not Working

开发者 https://www.devze.com 2023-01-25 19:15 出处:网络
I\'m trying to get a basic Apache 2.2 load balancer running on top of two Tomcat 6 installations.I\'m reading through all the documentation and I\'m 开发者_Go百科having trouble getting it working corr

I'm trying to get a basic Apache 2.2 load balancer running on top of two Tomcat 6 installations. I'm reading through all the documentation and I'm 开发者_Go百科having trouble getting it working correctly. I'm fairly certain I have the Apache configuration correct, but I think I'm missing something in my Tomcat settings that's preventing a connection. The Tomcat Connector documentation is good for how to modify Apache, but doesn't mention what needs to change in the Tomcat settings.

Here's my basic set up. All 3 installs are on the same machine (this is just a test setup). So, Apache 2.2 installed in C:\apache directory. Listens on port 80. 2 Tomcat 6 installs, one listens on port 81, one on port 82. The Apache will simply route everything to the Tomcat servers, acting as a 100% load balancer.

Here's the errors I'm getting in my mod_jk.log file when I try to get a connection at http://localhost:80/index.jsp . It's a 502 Bad Gateway error.

[Mon Nov 15 13:05:04.681 2010] [3596:1496] [error] ajp_connection_tcp_get_message::jk_ajp_common.c (1245): wrong message format 0x4854 from 127.0.0.1:81
[Mon Nov 15 13:05:04.681 2010] [3596:1496] [error] ajp_get_reply::jk_ajp_common.c (2058): (tomcat1) Tomcat is down or refused connection. No response has been sent to the client (yet)
[Mon Nov 15 13:05:04.681 2010] [3596:1496] [info] ajp_service::jk_ajp_common.c (2543): (tomcat1) sending request to tomcat failed (recoverable), because of protocol error (attempt=1)

Here is the settings I have in my Apache's httpd.conf file...

LoadModule jk_module modules/mod_jk.so
<IfModule jk_module>
    JkWorkersFile conf/workers.properties
    JkLogFile logs/mod_jk.log
    JkLogLevel info
    JkMountFile conf/uriworkermap.properties
</IfModule>

Here is the workers.properties file I have...

#
# This file provides minimal jk configuration properties needed to
# connect to Tomcat.
#
# The workers that jk should create and work with
#
worker.list=loadbalancer,jkstatus

#
# Define the servers in our cluster
#
worker.tomcat1.type=ajp13
worker.tomcat1.host=localhost
worker.tomcat1.port=81
worker.tomcat1.lbfactor=2

worker.tomcat2.type=ajp13
worker.tomcat2.host=localhost
worker.tomcat2.port=82
worker.tomcat2.lbfactor=1

#
# Defining a load balancer
#
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat1,tomcat2
worker.loadbalancer.sticky_session=false

#
# Define status worker
#
worker.jkstatus.type=status

Here is the uriworkermap.properties I have

#
# This file provides sample mappings for example wlb
# worker defined in workermap.properties.minimal
# The general syntax for this file is:
# [URL]=[Worker name]

/*.*=loadbalancer

Finally, here's the Tomcat's Engine tag in its server.xml file

<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">

      <Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase" />

      <Host name="localhost" appBase="webapps" deployOnStartup="true">
        <Valve className="org.apache.catalina.valves.AccessLogValve"
                 directory="logs"  prefix="localhost_access_log." suffix=".txt"
                 pattern="common" resolveHosts="false"/>
      </Host>

    </Engine>


Found the correct answer after some additional digging. I needed to create an AJP connector in each Tomcat's server.xml file. The Apache's mod_jk connects to this port, and then Tomcat relays that port to the HTTP Connector port.

<Connector port="8009" protocol="AJP/1.3" redirectPort="81" />
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号