How to
setup haproxy on oracle linux
Setting up HAProxy on Oracle Linux is straightforward. Here's a
step-by-step guide to help you get started:
Step 1: Install HAProxy
- Update your system:
sudo yum update -y
- Install HAProxy:
sudo yum install haproxy -y
Step 2: Configure HAProxy
- Open the HAProxy
configuration file:
sudo vi /etc/haproxy/haproxy.cfg
- Basic
Configuration: Here's a simple example of a
configuration that balances traffic between two web servers:
global
log /dev/log local0
log /dev/log local1 notice
maxconn 2000
user haproxy
group haproxy
daemon
defaults
log global
mode http
option httplog
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms
frontend http_front
bind *:80
default_backend http_back
backend http_back
balance roundrobin
server web1
192.168.1.101:80 check
server web2
192.168.1.102:80 check
- frontend: Defines where HAProxy listens for incoming connections.
- backend: Specifies the servers to which traffic should be forwarded.
Adjust the server entries with the actual IP addresses of your
backend servers.
Step 3: Start and Enable HAProxy
- Start the HAProxy
service:
sudo systemctl start haproxy
- Enable HAProxy to
start on boot:
sudo systemctl enable haproxy
- Check the status:
sudo systemctl status haproxy
Step 4: Configure Firewall (if applicable)
If you have a firewall running (like firewalld), allow traffic on
port 80:
sudo firewall-cmd --permanent --add-port=80/tcp
sudo firewall-cmd --reload
Step 5: Test the Setup
- Open a web browser
and navigate to the IP address of your HAProxy server.
- Monitor the logs or
use tools like curl to check the response.
Step 6: Advanced Configuration (Optional)
You can further customize your HAProxy configuration with features
like SSL termination, sticky sessions, or health checks depending on your
requirements.
Troubleshooting
If you encounter issues:
- Check the HAProxy
logs:
bash
Copy code
sudo tail -f /var/log/haproxy.log
- Ensure that backend
servers are reachable from the HAProxy server.
That's it! You now have a basic HAProxy setup running on Oracle
Linux. Let me know if you need any more help!

0 Comments