Reputation: 5313
I am working on Apache and tomcat to setup Load-balancing and fail-over. Initially I thought that load-balancing
would include fail-over
, but I was wrong. I thought that if one instance is not active, then consuming other instance also becomes a part of load-management. Enough with the terminologies, I setup fail-over, but the ironical part is fail-over
itself is failing.
As soon as I shut down one instance of tomcat, the entire setup is dead and I am getting 503. Can someone help me understand what is the problem.
Added this in apache2.conf :
JkWorkersFile /etc/apache2/workers.properties
JkMount /* loadbalancer
workers.properties :
GNU nano 2.2.6 File: 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-default in sites-enabled :
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>
First tomcat's 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>
Second Tomcat's 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>
What mistake I am making in the config for implementing load-balancing and fail-over together. Thanks a lot.
Upvotes: 0
Views: 940
Reputation: 216
First, you are using two different proxy modules, dont do that.
One is mod_jk, and the configuration files are workers.properties, uriworkermap.properties and in apache.conf this part:
JkMount /* loadbalancer
And in 000-default
JkMountCopy On
The other is mod_proxy and the relative configuration in 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>
As for comments, let's go the mod_jk route. First remove the mod_proxy configuration part, essentially all that is in 000-default leaving only:
JkMountCopy On
Then disable loading of this modules (not neccessary but better):
mod_proxy_*
Then add this to you'r loadbalancer's worker in workers.properties:
worker.loadbalancer.sticky_session_force = false
And check if things work, based on that i'll update the answer
Upvotes: 1