gpt4 book ai didi

java - Apache 网络服务器无法连接到 Tomcat 服务器

转载 作者:行者123 更新时间:2023-11-28 23:59:53 27 4
gpt4 key购买 nike

我已经在我的本地系统上配置了 Apache Httpd 和 Tomcat,引用这个教程:http://www.tutorialspoint.com/white-papers/load-balancing-and-scalability-via-tomcat-clusters.htm .我试图实现负载平衡,但网络服务器和 Tomcat 服务器之间的连接不起作用:

workers.properties文件

workers.tomcat_home=D:/Installed/apache-tomcat-7.0.62
workers.java_home=C:/Program Files/Java/jdk1.6.0_45
worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.worker1.lbfactor=1

httpd.conf文件

# Path to workers.properties
JkWorkersFile D:/Installed/Apache24/conf/workers.properties
# Path to jk logs
JkLogFile D:/Installed/Apache24/logs/mod_jk.log
# Jk log level [debug/error/info]
JkLogLevel info
# Jk log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions for forwarding
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
JkMount /BalServers worker1
JkMount /BalServers/* worker1

我已经放置了mod_jk.so模块文件夹中的文件。

我的网络服务器已启动并正在运行(已尝试使用 <a href="http://localhost" rel="noreferrer noopener nofollow">http://localhost</a> URL,它显示了 Apache 主页)。 Tomcat 服务器也可以工作并能够获取 <a href="http://localhost:8080/BalServers/" rel="noreferrer noopener nofollow">http://localhost:8080/BalServers/</a>网址。但是当我尝试 <a href="http://localhost/BalServers/" rel="noreferrer noopener nofollow">http://localhost/BalServers/</a> URL,没有显示任何内容,甚至没有 404 状态页面。

请让我知道是否需要任何其他配置?

这是我的 server.xml

<?xml version="1.0" encoding="UTF-8"?>
<Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener"/>
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
<Listener className="org.apache.catalina.core.JasperListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<GlobalNamingResources>
<Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

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

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

<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host appBase="webapps" autoDeploy="true" name="localhost" unpackWARs="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" pattern="%h %l %u %t &quot;%r&quot; %s %b" prefix="localhost_access_log." suffix=".txt"/>
</Host>
</Engine>
</Service>
</Server>

最佳答案

编辑 - 您尚未在 httpd.conf 中加载 workers.properties 文件。此外,如果您打开日志记录并监视 modjk 日志以查看错误被抛出的位置,那将会更好。

这是您可以遵循的成功基于 mod_jk 的负载平衡的模板。

httpd.conf

LoadModule    jk_module  modules/mod_jk.so

# This is missing in your httpd.conf
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"

#Use multiple context roots if necessary. But I follow the below.
JkMount /* balancer

如果你想配置一个 VirtualHost,将其包装在一个 <VirtualHost *:80> 中左右

然后是下面的workers.properties

worker.list=balancer

worker.worker1.type=ajp13
worker.worker1.port=8009
worker.worker1.host=172.16.2.31

worker.worker2.type=ajp13
worker.worker2.port=8009
worker.worker2.host=172.16.2.42


worker.balancer.type=lb
worker.balancer.method=B
worker.worker2.lbfactor=1
worker.balancer.balance_workers=worker1,worker2
#If sticky session is required
worker.loadbalancer.sticky_session=True

看看这些链接

Tomcat Server Configuration Doc

Mulesoft Tutorial

Apache Documentation

关于java - Apache 网络服务器无法连接到 Tomcat 服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31064598/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com