HAProxy distribuie traficul pe mai multe servere, cu health checks si TLS terminat central. Configurare pas cu pas, gata de productie.
1. Instalare
sudo apt -y install haproxy
haproxy -v
2. Frontend + backend
# /etc/haproxy/haproxy.cfg — frontend + backend
frontend web
bind *:80
bind *:443 ssl crt /etc/haproxy/certs/site.pem
redirect scheme https if !{ ssl_fc }
default_backend app_servers
backend app_servers
balance roundrobin
option httpchk GET /health
server app1 10.0.0.11:8080 check
server app2 10.0.0.12:8080 check
3. Algoritmi + sticky
# algoritmi uzuali:
# balance roundrobin -> pe rand
# balance leastconn -> cel mai putin incarcat (bun pt sesiuni lungi)
# balance source -> sticky pe IP client
# sticky pe cookie:
# cookie SRV insert indirect nocache
4. Pagina de statistici
# pagina de statistici (protejata cu user/parola)
listen stats
bind *:8404
stats enable
stats uri /
stats auth admin:parolaAici
5. Verificare
sudo haproxy -c -f /etc/haproxy/haproxy.cfg # verifica sintaxa
sudo systemctl reload haproxy
curl -I http://LB_IP/ # trebuie sa raspunda un backend
Concluzie
Ai load balancing cu health checks si TLS, fara single point of failure pe aplicatie. Il proiectam si il configuram pentru tine.