HAProxy Umsetzung: Unterschied zwischen den Versionen

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen
(Die Seite wurde neu angelegt: „=Installation= <syntaxhighlight lang="bash"> apt install haproxy </syntaxhighlight> =Zertifikat vorbereiten= HAProxy benötigt Zertifikat und Key in einer ein…“)
 
 
(16 dazwischenliegende Versionen desselben Benutzers werden nicht angezeigt)
Zeile 1: Zeile 1:
 
=Installation=
 
=Installation=
<syntaxhighlight lang="bash">
+
*apt install haproxy
apt install haproxy
+
 
</syntaxhighlight>
+
=Zertifikate=
 +
;Wir gehen davon aus das Zertifikate erstellt sind
 +
;Im Kurs hier reicht ein
 +
*sudo -i
 +
*get-cert.sh
  
 
=Zertifikat vorbereiten=
 
=Zertifikat vorbereiten=
 
HAProxy benötigt Zertifikat und Key in einer einzigen PEM-Datei.
 
HAProxy benötigt Zertifikat und Key in einer einzigen PEM-Datei.
<syntaxhighlight lang="bash">
+
*mkdir -p /etc/haproxy/ssl
mkdir -p /etc/haproxy/ssl
+
*cat /etc/ssl/own.crt /etc/ssl/own.key > /etc/haproxy/ssl/revproxy.pem
cat /etc/ssl/own.crt /etc/ssl/own.key > /etc/haproxy/ssl/reproxy.pem
+
*chmod 600 /etc/haproxy/ssl/revproxy.pem
chmod 600 /etc/haproxy/ssl/reproxy.pem
 
</syntaxhighlight>
 
  
 
=Konfiguration=
 
=Konfiguration=
 
Die Konfiguration befindet sich in <code>/etc/haproxy/haproxy.cfg</code>.
 
Die Konfiguration befindet sich in <code>/etc/haproxy/haproxy.cfg</code>.
<syntaxhighlight lang="bash">
+
*nano /etc/haproxy/haproxy.cfg
nano /etc/haproxy/haproxy.cfg
 
</syntaxhighlight>
 
  
 
<pre>
 
<pre>
Zeile 50: Zeile 50:
 
# Frontend: HTTPS
 
# Frontend: HTTPS
 
frontend ft_https
 
frontend ft_https
     bind 10.88.2XX.41:443 ssl crt /etc/haproxy/ssl/reproxy.pem
+
     bind 10.88.2XX.41:443 ssl crt /etc/haproxy/ssl/revproxy.pem
 
     mode http
 
     mode http
 
     option http-keep-alive
 
     option http-keep-alive
 
     option forwardfor
 
     option forwardfor
 
     timeout client 30s
 
     timeout client 30s
     acl acl_reproxy hdr_beg(host) -i reproxy
+
     acl acl_revproxy hdr_beg(host) -i revproxy
     use_backend backend_www if acl_reproxy
+
     use_backend backend_www if acl_revproxy
  
 
# Frontend: HTTP → HTTPS Redirect
 
# Frontend: HTTP → HTTPS Redirect
Zeile 69: Zeile 69:
 
# Backend: www.it2XX.int
 
# Backend: www.it2XX.int
 
backend backend_www
 
backend backend_www
     server www 10.88.2XX.YY:443 ssl verify none check
+
     server www 10.88.2XX.11:443 ssl verify none check
 +
 
 
</pre>
 
</pre>
 +
 +
=Haproxy Erläuterungen=
 +
*[[HAProxy Erläuterungen]]
  
 
=Konfiguration testen=
 
=Konfiguration testen=
<syntaxhighlight lang="bash">
+
*haproxy -c -f /etc/haproxy/haproxy.cfg
haproxy -c -f /etc/haproxy/haproxy.cfg
+
Wenn keine Ausgabe kommt ist es ok
</syntaxhighlight>
 
Die Ausgabe sollte lauten:
 
Configuration file is valid
 
  
 
=HAProxy starten / neu laden=
 
=HAProxy starten / neu laden=
<syntaxhighlight lang="bash">
+
*systemctl enable haproxy
systemctl enable haproxy
+
*systemctl restart haproxy
systemctl restart haproxy
 
</syntaxhighlight>
 
 
 
 
Bei laufendem Betrieb reicht ein Reload, damit bestehende Verbindungen nicht unterbrochen werden:
 
Bei laufendem Betrieb reicht ein Reload, damit bestehende Verbindungen nicht unterbrochen werden:
<syntaxhighlight lang="bash">
+
*systemctl reload haproxy
systemctl reload haproxy
+
Logs wir immer über
</syntaxhighlight>
+
*journalctl -fu haproxy
 +
Ist der Port offen?
 +
*ss -lntp
  
 
=Test=
 
=Test=
 
Vom Client aus:
 
Vom Client aus:
<syntaxhighlight lang="bash">
+
*curl -k http://revproxy.it2XX.int
curl -k http://reproxy.it2XX.int
+
*curl -vk https://revproxy.it2XX.int
curl -vk https://reproxy.it2XX.int
 
</syntaxhighlight>
 
  
 
Der erste Aufruf sollte einen <code>301 Redirect</code> auf HTTPS liefern, der zweite die Seite von <code>www.it2XX.int</code>.
 
Der erste Aufruf sollte einen <code>301 Redirect</code> auf HTTPS liefern, der zweite die Seite von <code>www.it2XX.int</code>.

Aktuelle Version vom 23. Mai 2026, 14:13 Uhr

Installation

  • apt install haproxy

Zertifikate

Wir gehen davon aus das Zertifikate erstellt sind
Im Kurs hier reicht ein
  • sudo -i
  • get-cert.sh

Zertifikat vorbereiten

HAProxy benötigt Zertifikat und Key in einer einzigen PEM-Datei.

  • mkdir -p /etc/haproxy/ssl
  • cat /etc/ssl/own.crt /etc/ssl/own.key > /etc/haproxy/ssl/revproxy.pem
  • chmod 600 /etc/haproxy/ssl/revproxy.pem

Konfiguration

Die Konfiguration befindet sich in /etc/haproxy/haproxy.cfg.

  • nano /etc/haproxy/haproxy.cfg
global
    log /dev/log    local0
    log /dev/log    local1 notice
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin expose-fd listeners
    stats timeout 30s
    user haproxy
    group haproxy
    daemon
    ssl-default-bind-ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384
    ssl-default-bind-ciphersuites TLS_AES_128_GCM_SHA256:TLS_AES_256_GCM_SHA384:TLS_CHACHA20_POLY1305_SHA256
    ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    timeout connect 5000
    timeout client  50000
    timeout server  50000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http

# Frontend: HTTPS
frontend ft_https
    bind 10.88.2XX.41:443 ssl crt /etc/haproxy/ssl/revproxy.pem
    mode http
    option http-keep-alive
    option forwardfor
    timeout client 30s
    acl acl_revproxy hdr_beg(host) -i revproxy
    use_backend backend_www if acl_revproxy

# Frontend: HTTP → HTTPS Redirect
frontend ft_http
    bind 10.88.2XX.41:80
    mode http
    option http-keep-alive
    timeout client 30s
    acl acl_http req.proto_http
    http-request redirect code 301 scheme https if acl_http

# Backend: www.it2XX.int
backend backend_www
    server www 10.88.2XX.11:443 ssl verify none check

Haproxy Erläuterungen

Konfiguration testen

  • haproxy -c -f /etc/haproxy/haproxy.cfg

Wenn keine Ausgabe kommt ist es ok

HAProxy starten / neu laden

  • systemctl enable haproxy
  • systemctl restart haproxy

Bei laufendem Betrieb reicht ein Reload, damit bestehende Verbindungen nicht unterbrochen werden:

  • systemctl reload haproxy

Logs wir immer über

  • journalctl -fu haproxy

Ist der Port offen?

  • ss -lntp

Test

Vom Client aus:

Der erste Aufruf sollte einen 301 Redirect auf HTTPS liefern, der zweite die Seite von www.it2XX.int.