Tomcat 6之上的Apache负载均衡器 - 缺少某些东西但它不起作用

时间:2010-11-15 19:21:07

标签: apache tomcat apache2 tomcat6

我正在尝试在两个Tomcat 6安装之上运行基本的Apache 2.2负载均衡器。我正在阅读所有文档,但我无法正常工作。我相当确定我的Apache配置是正确的,但我认为我在Tomcat设置中遗漏了一些阻止连接的东西。 Tomcat Connector文档适用于如何修改Apache,但没有提到需要在Tomcat设置中更改的内容。

这是我的基本设置。所有3个安装都在同一台机器上(这只是一个测试设置)。所以,Apache 2.2安装在C:\ apache目录下。侦听端口80. 2 Tomcat 6安装,一个侦听端口81,一个侦听端口82.Apache将简单地将所有内容路由到Tomcat服务器,充当100%负载均衡器。

当我尝试在http://localhost:80/index.jsp建立连接时,我在mod_jk.log文件中收到的错误。这是一个502 Bad Gateway错误。

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

以下是我在Apache的 httpd.conf 文件中的设置......

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>

以下是 workers.properties 文件...

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

这是 uriworkermap.properties 我有

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

最后,这是 server.xml 文件中的Tomcat引擎标记

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

1 个答案:

答案 0 :(得分:3)

经过一些额外的挖掘后找到了正确的答案。我需要在每个Tomcat的server.xml文件中创建一个AJP连接器。 Apache的mod_jk连接到此端口,然后Tomcat将该端口中继到HTTP连接器端口。

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