Tomcat,Apache:即使在配置后,故障转移也无法正常工作

时间:2015-12-09 14:16:13

标签: java apache tomcat load-balancing failover

我正在使用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>

我在配置中犯了什么错误,一起实现负载平衡和故障转移。非常感谢。

1 个答案:

答案 0 :(得分:1)

首先,您使用的是两个不同的代理模块,不要这样做。

一个是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中的loadbalancer的worker:

worker.loadbalancer.sticky_session_force = false

根据我将更新答案

,检查事情是否有效