How to Configure Load Balancing with HAProxy

How to Configure Load Balancing with HAProxy

HAProxy is an open source software that functions as a load balancing and proxy for TCP and HTTP. Load balancing is a method for distributing traffic to multiple servers.

Topologi Load Balancing
Load Balancing Topology

0.Equipment used

Equipment used in this tutorial:

  • OS Ubuntu 18.04 LTS
  • HAProxy
  • Nginx web server
  • PHP-FPM 7.2
  • Node1: 10.130.127.167
  • Node2: 10.130.128.35
  • LoadBalancer: 128.199.187.215
  • Domain: defnex.com

Node1 and Node2 have already installed Nginx web server and PHP-FPM 7.2. Each node is made index.php file containing the text node1 and node2 as a test page to find out which pages are read from which node.

1.Install HAProxy

Update and install HAProxy.

2.Configure HAProxy

Open configuration file of HAProxy.

Default file configuration haproxy.cfg.

Add a configuration for the HAProxy listener.

Add configuration for web server backend.

Additional configuration for HAProxy statistics.

The final result is HAProxy configuration.

Verify the configuration and restart HAProxy.

3.Testing

Browse the domain, refresh the page repeatedly until it displays the index.php file of Node1 and Node2.

Halaman index.php dari Node1
index.php page from Node1
Halaman index.php dari Node2
index.php page from Node2

4.Statistics

Browse http://domain.com:1234/stats to read HAProxy statistics.

Statistik HAProxy
HAProxy statistics page

Good luck 🙂

Leave a Reply