Install and Configure HAProxy on CentOS 10 for efficient load balancing and uptime. Our HAProxy Support team is ready to assist you.
Install and Configure HAProxy on CentOS 10
Applications must have load balancing in order to function properly, stay accessible, and manage traffic effectively. One of the most often used technologies for this is HAProxy, which provides a reliable and flexible method of dividing up requests among several servers. By lowering the danger of overload and downtime, it helps ensure constant performance and a better user experience for both modest installations and large-scale infrastructures.
What is HAProxy?
HAProxy (High Availability Proxy) is a free, open-source load balancer and reverse proxy for TCP and HTTP applications, designed to improve performance, reliability, and uptime. It serves as a reverse proxy by sending client requests to the appropriate backend and distributing incoming traffic across several servers to avoid overload. By ensuring high availability, HAProxy can minimize downtime and maintain application accessibility by automatically redirecting traffic to servers that are in excellent state in the event that one fails.
How to Configure HAProxy
- Install HAProxy
- Ubuntu/Debian
sudo apt-get update
sudo apt-get install haproxy
- RHEL/CentOS
sudo yum install haproxy # or: sudo dnf install haproxy
- Open the configuration file
- Back up the default file:
sudo cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
- Edit it with your editor:
sudo nano /etc/haproxy/haproxy.cfg
- Define a frontend (what HAProxy listens on)
- Add a simple HTTP frontend:
frontend http_in
bind *:80
mode http
default_backend app_pool
(Optional) Add HTTPS with a PEM certificate:
frontend https_in
bind 0.0.0.0:443 ssl crt /etc/ssl/private/site.pem
mode http
default_backend app_pool
- Define a backend (where traffic goes)
- Add your app servers, load-balancing method, and health checks:
backend app_pool
mode http
balance roundrobin
option httpchk GET /health
server app1 192.168.1.10:80 check
server app2 192.168.1.11:80 check
- Add useful options (optional but recommended)
- Timeouts (reduce hung connections):
defaults
mode http
timeout connect 5s
timeout client 50s
timeout server 50s
- Stats page (local only example):
listen stats
bind 127.0.0.1:8404
stats enable
stats uri /haproxy?stats
stats auth admin:strongpass
- Basic ACL routing (example: send /api to a different pool):
frontend http_in
bind *:80
acl is_api path_beg /api
use_backend api_pool if is_api
default_backend app_pool
backend api_pool
mode http
balance roundrobin
server api1 192.168.1.20:80 check
- Validate and apply
- Check the config:
sudo haproxy -c -f /etc/haproxy/haproxy.cfg
- Restart and enable on boot:
sudo systemctl restart haproxy
sudo systemctl enable haproxy
You may find our expert guide on How to Setup HAProxy on RHEL useful for deeper insights.
Installing HAProxy on CentOS 10
To install and configure HAProxy on CentOS 10, start by updating your system packages to ensure security and compatibility. Before making any modifications, install HAProxy from the CentOS repositories and make a backup of the default configuration file. To provide global, defaults, frontend, and backend parameters in accordance with your traffic routing requirements, edit /etc/haproxy/haproxy.cfg. Start the HAProxy service when it has been configured, allow it to begin at system startup, and check its status to make sure it operates properly.
Step 1: Keep your system secure and up-to-date
sudo dnf update -y
Step 2: Install from the CentOS repositories
sudo dnf install haproxy -y
Step 3: Backup and Edit Configuration
sudo cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak
Step 4: Open the file for editing
sudo vim /etc/haproxy/haproxy.cfg
Step 5: Run the service immediately and enable it at boot
sudo systemctl enable --now haproxy
Step 6: Check if HAProxy is running correctly
sudo systemctl status haproxy
If you’re working with Docker and HAProxy on CentOS, this setup guide is worth reading.
[Need assistance with a different issue? Our team is available 24/7.]
Conclusion
To sum up, HAProxy is a reliable reverse proxy and load balancer that ensures high availability and effective traffic control. The steps to Install and Configure HAProxy on CentOS 10 will help you build a solid configuration with frontends, backends, and health checks to optimize performance and ensure uptime.
In brief, our Support Experts demonstrated how to fix the “554 5.7.1 : Relay access denied” error.
0 Comments