gpt4 book ai didi

java - Tomcat、 Apache : Failover not working even after configuration

转载 作者:行者123 更新时间:2023-11-28 22:53:09 26 4
gpt4 key购买 nike

我正在使用 Apache 和 tomcat 来设置负载平衡和故障转移。最初我以为 load-balancing 会包括 fail-over,但我错了。我认为如果一个实例不活动,那么使用其他实例也会成为负载管理的一部分。术语够多了,我设置了故障转移,但具有讽刺意味的是 fail-over 本身失败了。

一旦我关闭了一个 tomcat 实例,整个设置就死了​​,我得到了 503。有人可以帮助我了解问题所在吗?

在 apache2.conf 中添加:

JkWorkersFile /etc/apache2/workers.properties

JkMount /* loadbalancer

worker .属性:

GNU nano 2.2.6 文件:workers.properties

 worker.list=loadbalancer
worker.server1.port=8010
worker.server1.host=localhost
worker.server1.type=ajp13

worker.server2.port=8011
worker.server2.host=localhost
worker.server2.type=ajp13

worker.server1.lbfactor=1
worker.server2.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=server1,server2
worker.loadbalancer.method=B
worker.balancer.sticky_session=True

000-启用站点的默认值:

JkMountCopy On
<Proxy balancer://mycluster>
BalancerMember ajp://localhost:8010 route=server1 connectiontimeout=10
BalancerMember ajp://localhost:8011 route=server2 connectiontimeout=10

ProxySet stickysession=JSESSIONID|jsessionid
Order Deny,Allow
Deny from none
Allow from all

</Proxy>

<VirtualHost *:80>
ProxyRequests off

ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
</VirtualHost>

<Location /balancer-manager>
SetHandler balancer-manager

Order Deny,Allow
Deny from none
Allow from all
</Location>

首先是tomcat的server.xml:

<Connector port="8080" proxyPort="80" protocol="HTTP/1.1" compression="force" compressionMinSize="1024" 
connectionTimeout="20000"
redirectPort="443" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"/>


<Connector port="443" enableLookups="false" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="200" compression="force"
compressionMinSize="1024" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS"
keystoreFile="keystore_file" keystorePass="PASSWORD" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
<Connector port="8010" protocol="AJP/1.3" redirectPort="443" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
<Engine name="Catalina" defaultHost="localhost" jvmRoute="server1">
// No modifications inside
</Engine>

第二个 Tomcat 的 server.xml :

<Connector port="8081" proxyPort="80" protocol="HTTP/1.1" compression="force" compressionMinSize="1024" 
connectionTimeout="20000"
redirectPort="443" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"/>


<Connector port="443" enableLookups="false" protocol="HTTP/1.1" SSLEnabled="true" maxThreads="200" compression="force"
compressionMinSize="1024" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS"
keystoreFile="keystore_file" keystorePass="PASSWORD" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
<Connector port="8011" protocol="AJP/1.3" redirectPort="8443" URIEncoding="utf-8"
compressableMimeType="text/html,text/xml,text/plain,text/css,text/ javascript,application/x-javascript,application/javascript"
/>
<Engine name="Catalina" defaultHost="localhost" jvmRoute="server2">
// No modifications here
</Engine>

我在同时实现负载平衡和故障转移的配置中犯了什么错误。多谢。

最佳答案

首先,您正在使用两个不同的代理模块,不要那样做。

一个是mod_jk,配置文件是workers.properties、uriworkermap.properties和apache.conf中这部分:

JkMount /* loadbalancer

默认为 000

JkMountCopy On

另一个是mod_proxy和000-default中的相关配置:

<Proxy balancer://mycluster>
BalancerMember ajp://localhost:8010 route=server1 connectiontimeout=10
BalancerMember ajp://localhost:8011 route=server2 connectiontimeout=10

ProxySet stickysession=JSESSIONID|jsessionid
Order Deny,Allow
Deny from none
Allow from all

</Proxy>

<VirtualHost *:80>

ProxyRequests off

ProxyPass /balancer-manager !
ProxyPass / balancer://mycluster/
ProxyPassReverse / balancer://mycluster/
</VirtualHost>

<Location /balancer-manager>
SetHandler balancer-manager

Order Deny,Allow
Deny from none
Allow from all
</Location>

至于评论,让我们走 mod_jk 路线吧。首先删除 mod_proxy 配置部分,基本上所有在 000-default 中的部分只留下:

JkMountCopy On

然后禁用此模块的加载(不是必需的但更好):

mod_proxy_*

然后在 workers.properties 中将此添加到你是负载均衡器的工作人员:

worker.loadbalancer.sticky_session_force = false

然后检查是否一切正常,我会根据此更新答案

关于java - Tomcat、 Apache : Failover not working even after configuration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34181013/

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