Keegan Turner
  • πŸ‘‹Hello World.
  • πŸ“šHow-To Guides
    • Integrating Git on your local host
    • βš–οΈLoad Balancing with HAProxy
    • πŸ‘¨β€πŸ’»Code Server - Self Hosted VSCode alternative
    • πŸ•ΈοΈWordPress + LAMP - Self Hosted CMS
    • ☁️Nextcloud - Self Hosted file sync & sharing solution
    • ⏳Grafana Cloud - Cloud Hosted Monitoring
    • βŒ›Prometheus + Grafana - Self Hosted monitoring stack solution
    • πŸ›³οΈPortainer + Docker - Self Hosted container management UI
    • 🐬MariaDB - Self Hosted database server
    • πŸ€–Let's Encrypt + Certbot - Secure your web services with SSL certificates
    • ◀️Nginx Proxy Manager - Self Hosted domain controller with LE SSL certificates
    • πŸ–₯️LXD - Linux OS containers
    • 🐧Linux basics: commands
    • 🐧Linux basics: file paths
    • 🐧Linux basics: SWAP file
  • 🚫Bytes of Caution
Powered by GitBook
On this page
  1. How-To Guides

Load Balancing with HAProxy

2024-06-17

HAProxy is an open-source software that provides high availability, load balancing, and proxying for TCP and HTTP-based applications. It distributes incoming traffic across multiple servers to ensure optimal resource utilization and reliability. HAProxy supports advanced features like SSL termination, health checks, and session persistence, making it widely used in modern application architectures to improve scalability and fault tolerance.

Step 1

Create an instance on your Cloud Provider to serve as the load balancer

I am using a Debian instance for my load balancer

Update the system

sudo apt update -y && sudo apt dist-upgrade -y

Install HAProxy

sudo apt install haproxy

Now add the IP addreses for the servers which need to be load balanced, to the haproxy config file:

sudo nano /etc/haproxy/haproxy.cfg

Add the following sections to the file:

frontend load_balancer
    bind *:80
    mode http
    default_backend backend_servers

backend backend_servers
    mode http
    balance roundrobin
    server server1 'serverip':80 check
    server server2 'serverip':80 check

Exit and save the file.

Reload HAProxy service:

sudo service haproxy reload

Test the load balancer by navigating to the IP address of the load balancer IP address - You will be presented with the server content for server1 in a round-robin rule.

I have two Debian instances with Apache load balanced. When tailing the access logs, you will see the load balancer IP address in the log files:

Should one of the debian servers go down, the requests to access the available server will continue to flow.

Should both servers go down, the following error will show on the load balancer instance:

Implementing a load balancer enhances your infrastructure's performance and reliability by distributing incoming traffic across multiple servers. It ensures efficient resource utilization, prevents server overload, and improves response times, resulting in a seamless user experience. Load balancers also facilitate scalability, enabling easy scaling of resources up or down based on traffic demands.

PreviousIntegrating Git on your local hostNextCode Server - Self Hosted VSCode alternative

Last updated 12 months ago

πŸ“š
βš–οΈ
Page cover image