HA Proxy Load Balancer
HAProxy (High Availability Proxy) is free, open-source software that provides a high-availability load balancer and proxy server for TCP and HTTP-based applications. It's used to improve the performance and reliability of web servers by distributing incoming traffic across multiple backend servers.
Key Features of HAProxy:
Load Balancing: Distributes client requests across multiple servers to balance the load and prevent any single server from becoming overwhelmed.
High Availability: Ensures continuous operation by redirecting traffic to healthy servers when one or more servers fail.
SSL Termination: Decrypts SSL/TLS traffic, offloading the task from backend servers and reducing their load.
TCP and HTTP Protocols: It supports both TCP and HTTP, making it versatile for various applications.
Health Checks: continuously monitors the health of backend servers and only forwards requests to healthy ones.
Session Persistence: Ensures that a user’s session is consistently routed to the same backend server.
Logging and Statistics: Provides detailed logs and statistics for monitoring and troubleshooting.
How HAProxy Works:
Client Request: A client sends a request to the server.
HAProxy Frontend: The request first hits the HAProxy frontend, which listens on a public IP address and port.
Load Balancing Algorithm: HAProxy uses a specified load balancing algorithm (like round-robin, least connections, or IP hash) to determine which backend server should handle the request.
Health Checks: Before forwarding the request, HAProxy performs health checks to ensure the selected backend server is up and running.
Forwarding Request: The request is forwarded to the chosen backend server.
Backend Server Response: The backend server processes the request and sends a response back to HAProxy.
HAProxy Response: HAProxy receives the response and forwards it to the client.
Example Configuration:
Here’s a basic example of an HAProxy configuration file (haproxy.cfg
):
global
log /dev/log local0
log /dev/log local1 notice
maxconn 4096
daemon
defaults
log global
mode http
option httplog
option dontlognull
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
frontend http_front
bind *:80
default_backend http_back
backend http_back
balance roundrobin
server server1 192.168.1.2:80 check
server server2 192.168.1.3:80 check
Explanation:
global: Contains global settings like logging and maximum connections.
defaults: Sets default settings for all frontend and backend sections.
frontend: Defines the frontend, where HAProxy listens for incoming connections (e.g., on port 80 for HTTP).
backend: defines the backend servers and the load balancing algorithm (e.g., round-robin).
HAProxy is highly configurable and can be tailored to fit a variety of use cases, making it a popular choice for load balancing and improving the reliability of web applications.
Subscribe to my newsletter
Read articles from Nahid directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Nahid
Nahid
I am Mozahidul Islam Nahid, an engineer driven by a passion for continuous learning and growth. With six years of diverse professional experience. Which includes one year as DevOps engineer and four and a half years as administration and procurement specialist. Now I am dedicated to advance my career in DevOps engineering and cloud engineering.I am particularly passionate about server management and ongoing maintenance of websites post-deployment and I aspire to be a crucial part of these essential tasks for any company . Thank you!