Tomcat,Apache:即使在配置后故障转移也不起作用

Tomcat, Apache : Failover not working even after configuration

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

我一关闭 tomcat 的一个实例,整个设置就死了​​,我收到 503。谁能帮助我了解问题所在。

在 apache2.conf 中添加:

JkWorkersFile /etc/apache2/workers.properties

JkMount /* loadbalancer

workers.properties :

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

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

并检查是否一切正常,我将根据此更新答案