One single balancer-manager page for multiple virtual hosts

apache-2.4load balancingPROXY

We're using currently an Apache 2.4 as load-balancer for a multi-master-cluster of three Tomcats-Servers. We can access the internal IP-Address of this load-balancer with an web-browser and change the settings on the fly (e.g. http://xx.xx.xx.xx/balancer-manager). This works and we're pretty fine with this.

Enabled modules:

  • proxy.load (proxy.conf used to configure)
  • proxy_ajp.load
  • proxy_balancer.load (proxy_balancer.conf used to configure)

But now we will host several (three in this setup) virtual hosts on this Apache, each representing a cluster of three Tomcats itself. Each is accessiable via an URL like http://customer.company.tld/app/ui). So the path is the same for each cluster! Now we're facing two problems:

  • The page balancer-manager is only reachable via it's virtual host. Therefore we have to access the balancer-manager via random choosen internal hostname (added to ServerAlias) and add this hostname also into the /etc/hosts off our internal computers to be be able to use it.
  • Furthermore we have to do this for each virtual-host (~cluster). But we want a single page balancer-manager which presents all virtual-hosts and the cluster behind.

Here some sample configuration:
/etc/apache2/site-enabled/foo # we have actually three of them: foo, bar, baz

<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    ServerName customer-foo.company.tld
    ServerAlias customer-foo-balancer customer-foo.company.tld www.customer-foo.company.tld

    DocumentRoot /var/www

        <Directory />
                Options FollowSymLinks
                AllowOverride None
                Order allow,deny
                deny from all
        </Directory>
        <Directory /var/app/app_static>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>
        <Directory /var/www/app_static_res>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride All
                Order allow,deny
                allow from all
        </Directory>

    # load balancer
        <Location /balancer-manager>
                 SetHandler balancer-manager
                 Order deny,allow
                 Deny from all
                 # allows for internal access
                 Allow from 127.0.0.1 ::1 10.1.21.81 10.1.4.9
                 Satisfy all
        </Location>

        ProxyRequests Off
        ProxyVia Off
        ProxyPreserveHost On

        <Proxy balancer://htg>
                ProxySet failonstatus=503
                BalancerMember ajp://10.171.23.120:8010/app lbset=0 route=foo001 loadfactor=40
                BalancerMember ajp://10.171.23.121:8010/app lbset=0 route=foo002 loadfactor=40
                BalancerMember ajp://10.171.23.122:8010/app lbset=0 route=foo003 loadfactor=20
        </Proxy>

        <Proxy balancer://htgservice>
                ProxySet failonstatus=503
                BalancerMember ajp://10.171.23.120:8011/wcs_service route=foo001 loadfactor=40
                BalancerMember ajp://10.171.23.121:8011/wcs_service route=foo002 loadfactor=40
                BalancerMember ajp://10.171.23.122:8011/wcs_service route=foo003 loadfactor=20
        </Proxy>


        ProxyPass        /app balancer://foo stickysession=JSESSIONID|jsessionid nofailover=Off scolonpathdelim=On
        ProxyPassReverse /app balancer://foo

        ProxyPass        /app_service  balancer://fooservice stickysession=JSESSIONID|jsessionid nofailover=Off scolonpathdelim=On
        ProxyPassReverse /app_service  balancer://fooservice

        LogLevel warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

In the past we configured the balancing inside the distinct files proxy.conf and proxy_balancer.conf, which should allow for accessing via the internal IP and show up all clusters and cluster-members on a single page.
But this won't work anymore, the configuration for proxies seem to accept only paths (e.g. app and app_service) not URLs or hostnames. We can't and won't change the paths. Therefore we moved the proxy-configuration inside the virtual hosts.

Thanks for your help!

Best Answer

What about splitting your config. Put your balancer definition outside any virtual host and remove the context:

     <Proxy balancer://htg>
            ProxySet failonstatus=503
            BalancerMember ajp://10.171.23.120:8010 lbset=0 route=foo001 loadfactor=40
            BalancerMember ajp://10.171.23.121:8010 lbset=0 route=foo002 loadfactor=40
            BalancerMember ajp://10.171.23.122:8010 lbset=0 route=foo003 loadfactor=20
    </Proxy>

    <Proxy balancer://htgservice>
            ProxySet failonstatus=503
            BalancerMember ajp://10.171.23.120:8011 route=foo001 loadfactor=40
            BalancerMember ajp://10.171.23.121:8011 route=foo002 loadfactor=40
            BalancerMember ajp://10.171.23.122:8011 route=foo003 loadfactor=20
    </Proxy>

In your vhosts reference these balancers:

ProxyPass        /app balancer://htg/app stickysession=JSESSIONID|jsessionid nofailover=Off scolonpathdelim=On
ProxyPassReverse /app balancer://htg/app

ProxyPass        /app_service  balancer://htgservice/wtg_service stickysession=JSESSIONID|jsessionid nofailover=Off scolonpathdelim=On
ProxyPassReverse /app_service  balancer://htgservice/wtg_service

To access your balancer-manager, create an extra management vhost with <Location /balancer-manager> in it.

This way, you have one place where all your balancers are defined and one vhost to access the balancer-manager which shows you all your balncers.

Related Topic