HAProxy verteilt den Verkehr auf mehrere Server, mit Health-Checks und zentral terminiertem TLS. Schrittweise, produktionsreife Einrichtung.
1. Installation
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. Algorithmen + 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. Statistikseite
# pagina de statistici (protejata cu user/parola)
listen stats
bind *:8404
stats enable
stats uri /
stats auth admin:parolaAici
5. Pruefen
sudo haproxy -c -f /etc/haproxy/haproxy.cfg # verifica sintaxa
sudo systemctl reload haproxy
curl -I http://LB_IP/ # trebuie sa raspunda un backend
Fazit
Sie haben nun Load Balancing mit Health-Checks und TLS, ohne Single Point of Failure bei der App. Wir entwerfen und konfigurieren es fuer Sie.