Setting up Apache Loadbalancer along with two spring boot apps in Linux.

Sanjaya De Silva
Nov 8 · 1 min read

First, create two spring boot apps using start.spring.io. Then install apache2 to your Linux machine (https://www.digitalocean.com/community/tutorials/how-to-install-the-apache-web-server-on-ubuntu-18-04-quickstart).

Now, in order to enable mod_proxy_balancer run following commands:

sudo a2enmod proxy
sudo a2enmod proxy_http
sudo a2enmod proxy_balancer
sudo a2enmod lbmethod_byrequests

Now open /etc/apache2/sites-available/000-default.conf file and add these lines.

<Proxy balancer://myclustername >
BalancerMember http://localhost:8085 loadfactor=1
BalancerMember http://localhost:8086 loadfactor=2
#ProxySet lbmethod=bytraffic
</Proxy>

ProxyPass /myapp balancer://myclustername/myapp
ProxyPassReverse /myapp balancer://myclustername/myapp

<Location /balancer-manager>
SetHandler balancer-manager
Order Deny,Allow
Deny from all
Allow from all
</Location>

Here 8085, 8086 are spring boot ports. At present, there are 2 load balancer scheduler algorithms available for use: Request Counting, Weighted Traffic Counting, and Pending Request Counting. These are controlled via the lbmethod value of the Balancer definition.

Now restart apache using

sudo /etc/init.d/apache2 restart

or

sudo service restart apache2

Now you will see the load balancer has started and you can change the configurations to see how it works.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade