Configure Apache with mod_cluster load balancer on Ubuntu

[Part 1 of a 3 part series]

Apache 2.4.7 with Load Balancer on Ubuntu 14.04

Introduction

This post is the first of a series on how to set up and configure a clustered environment. In this post, we’ll walk through the basic steps required to set up and configure mod_cluster load balancer with Apache 2.4.7 on Ubuntu 14.04. One of the biggest reasons we would like to setup a load balancer in a clustered environment is because the load balancer provides us with a communication channel to forward request from Apache (httpd) to one of a set of Application Server nodes; such as Wildfly.

Note: this guide is by no means the absolute way of doing what we’re setting out to accomplish.

Apache (httpd) will be run on its own dedicated host, where we will enable the mod_cluster module for load balancing. What we will end up with will look something like this:

For this guide, we are mainly concerned with the host network domain, where the host with Apache will reside.

What we need

We’ll need a machine with Ubuntu 14.04 installed. The other tools required for this guide will be covered in the next section.

Tip: although not mandatory, a static IP for this host will prevent a lot of future frustrations.

Before we start,

We want to make sure our package lists from the repositories are updated to get information on the newest versions of packages and their dependencies. To do this, just run:

Update

apt-get update

Apache

For Apache we run the following command.

Apache

apt-get install -y apache2

Autoconf

Autoconf is mainly used for configuring source code and Makefiles. We’re not going to do any of this, we just need the tool for building the mod_cluster sources. For Autoconf we run the following command.

Autoconf

apt-get install -y autoconf

Libtool

Libtool is mainly used to create portable libraries. This is required because the mod_cluster sources are built into .so (Shared Object), which in essence is a shared or dynamically linked library. For Libtool we run the following command.

Libtool

apt-get install -y libtool

Git

Git is going to be used to clone the latest mod_cluster repo. At writing it was 1.3.1 (beta). The 1.2.x sources is (from what I could gather) only compatible with Apache version 2.2.x. For Git we run the following command.

Git

apt-get install -y git

Apache2 Dev

When compiling the mod_cluster sources, there is a dependency on axps, which is a tool for building and installing extension modules for the Apache HyperText Transfer Protocol (HTTP) server. For axps, we need to install the apache2-dev package, by:

Apache2 Dev

apt-get install -y apache2-dev

Quickest Way

Alternatively, you can just do all of the above in one go,

Install all

apt-get install -y apache2 autoconf libtool git apache2-dev

That is all we need for now. In the next section we’ll build the mod_cluster sources.

Compiling mod_cluster sourcesapache2-dev

Checkout on Github

Most of the insight gained for this part was found from a french wiki[2]. To compile the sources, we first need to checkout the mod_cluster project on GitHub.

Symbolic link

Sym link proxy_cluster.load

You can double check the mods-enabled directory to see of it contains a proxy_cluster.load file.

Enable proxy and proxy_ajp

We also need to enable two additional modules which the load balancer will need to work properly, they are proxy and proxy_ajp. We’ll use the provided a2enmod tool from Apache to enable them. See the command below. The tool automatically resolves the dependency for proxy_ajp and enables the proxy module as well.

Enable proxy and proxy_ajp

Virtual host directive for the mod_cluster load balancer

Next, we need to configure a virtual host directive for the mod_cluster load balancer. In the mods-available directory inside /etc/apache2/ we create a file called proxy_cluster.conf. The conf file will look like this:

Note: the line “MemManagerFile /var/cache/mod_cluster” is mandatory because the default location Apache will use to store configuration, generate keys for shared memory or lock files is $server_root/logs/, which does not exist.

Tip: ensure the host machine’s IP and port number you’re using for mod_cluster are acessible.

EnableMCPMReceive

EnableMCPMReceive (Mod-Cluster Management Protocol (MCMP)) is very important, because this connection is used to transmit server-side load balance factors and lifecycle events back to Apache via a custom set of HTTP methods.

We also need to add this proxy_cluster.conf file to the mods-enabled directory. To do this we’ll ad a symbolic link as shown below.

Sym link proxy_cluster.conf

Now, we need to reload the server, start/stop or restart, which ever takes your preference to ensure Apache pulls in our extensions.

Reload the Apache

/etc/init.d/apache2 reload
or
service apache2 reload
or
service apache2 restart

Is it working?

Right, now it’s time to see if our efforts were not in vain. To see if the mod_cluster is running, we have to do two backflips, while spinning a hula hoop around our waist and balancing a glass of water on our nose – at the same time!

Just kidding…

Open a browser window and navigate to :6666/mod_cluster_manager.
You should see a screen similar to the following:

If you see this, congratulations!

You’re a step closer to load balance magic

Stay tuned for the next post in this series. We will be looking at setting up a Wildfly cluster, and how to register the nodes with the load balancer so we can access our application from a single address and let the load balancer balance requests to nodes in the Wildfly cluster.