Apache load balancer doesn't work for heartbeat lbmethod

725 views Asked by At

I'm investigating load balancing algorithms implemented in Apache server. For bybusyness, bytraffic and byrequests methods the Apache server works properly. The problem occurs when load balancing method is set to heartbeat. When I try to access a load balancer server from a browser I'm getting 503 Service Unavailable and there is a following error in logs file:

AH01170: balancer://mycluster: All workers are in error state

I've got the following configuration in httpd.conf file:

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule slotmem_shm_module modules/mod_slotmem_shm.so
LoadModule status_module modules/mod_status.so
LoadModule watchdog_module modules/mod_watchdog.so
LoadModule heartbeat_module modules/mod_heartbeat.so
LoadModule heartmonitor_module modules/mod_heartmonitor.so
LoadModule lbmethod_bytraffic_module modules/mod_lbmethod_bytraffic.so
LoadModule lbmethod_byrequests_module modules/mod_lbmethod_byrequests.so
LoadModule lbmethod_bybusyness_module modules/mod_lbmethod_bybusyness.so
LoadModule lbmethod_heartbeat_module modules/mod_lbmethod_heartbeat.so

Listen *:8888
ServerName http://localhost:8888

HeartbeatListen localhost:8888
HeartbeatAddress localhost:8888
HeartbeatMaxServers 20

<VirtualHost *:8888>

<Proxy balancer://mycluster>
    BalancerMember http://localhost:8081 route=1
    BalancerMember http://localhost:8082 route=2
    ProxySet lbmethod=heartbeat
</Proxy>

<Location "/balancer-manager">
    SetHandler balancer-manager
</Location>

ProxyPass        /test balancer://mycluster
ProxyPassReverse /test balancer://mycluster

</VirtualHost>

According to documentation all necessary modules for heartbeat method are loaded. Also the slotmem module is set correctly which is confirmed by a log:

AH02283: Using slotmem from mod_heartmonitor

As I mentioned this configuration works properly for other algorithms (bybusyness, bytraffic, byrequests). I haven't found any examples showing proper configuration for balancer with heartbeat method and the official documentation says that this method has status "Experimental": https://httpd.apache.org/docs/trunk/mod/mod_heartbeat.html. If anyone have an experience in Apache load balancing topic I will be grateful for any tips.

1

There are 1 answers

0
tomaxo14 On

I found the solution. Firstly you need to specify the same address for HeartbeatAddress (in balancer members configuration) and for HeartbeatListen (in load balancer server configuration). Secondly it has to be multicast-address so it cannot be localhost as in my previous configuration. Example of proper heartbeat directives:

#load-balancer server configuration file    
HeartbeatListen 239.0.0.1:27999

and

#all balancer members configuration file    
HeartbeatAddress 239.0.0.1:27999

With such configuration, load balancer heartbeat method works properly. More details here: https://www.apachelounge.com/viewtopic.php?p=41271#41271