| Beide Seiten der vorigen Revision
Vorhergehende Überarbeitung
Nächste Überarbeitung
|
Vorhergehende Überarbeitung
|
haproxy [2025/10/27 18:41] jango [Global] |
haproxy [2025/10/29 09:24] (aktuell) jango [ACL] |
| |
| =====Installation===== | =====Installation===== |
| | |
| | * Service Ubuntu: /lib/systemd/system/haproxy.service |
| | * Service RHEL: /etc/systemd/system/haproxy.service |
| |
| <box red>In den meissten Distributionen installiert der Paketmanager eine veraltete Version (1.8)</box> | <box red>In den meissten Distributionen installiert der Paketmanager eine veraltete Version (1.8)</box> |
| sudo cp haproxy /usr/sbin/haproxy | sudo cp haproxy /usr/sbin/haproxy |
| sudo mkdir -p /etc/haproxy | sudo mkdir -p /etc/haproxy |
| cp examples/basic-config-edge.cfg /etc/haproxy/haproxy.cfg | |
| | # Wahrscheinlich nicht funktional, besser from scratch erstellen |
| | # cp examples/basic-config-edge.cfg /etc/haproxy/haproxy.cfg |
| </code> | </code> |
| |
| Cretae a service file /etc/systemd/system/haproxy.service | Create a service file /etc/systemd/system/haproxy.service |
| |
| <code> | <code> |
| sudo systemctl enable haproxy | sudo systemctl enable haproxy |
| sudo systemctl start haproxy | sudo systemctl start haproxy |
| | </code> |
| | |
| | <code> |
| | # Fix not needed |
| | setcap 'cap_net_bind_service=+ep' /usr/sbin/haproxy |
| | </code> |
| | ====Manueller Start==== |
| | |
| | <code> |
| | haproxy -f /etc/haproxy/haproxy.cfg [-Ws] |
| | haproxy -db -f /etc/haproxy/haproxy.cfg |
| </code> | </code> |
| =====Konfiguration===== | =====Konfiguration===== |
| ====Global==== | ====Global==== |
| |
| [[https://www.haproxy.com/documentation/haproxy-configuration-manual/latest/#3|Keywords in global section]] | * [[https://www.haproxy.com/documentation/haproxy-configuration-tutorials/proxying-essentials/configuration-basics/global/|HAProxy Globals]] |
| | * [[https://www.haproxy.com/documentation/haproxy-configuration-manual/latest/#3|Keywords in global section]] |
| |
| Der globale Abschnitt ([[https://www.haproxy.com/documentation/haproxy-configuration-tutorials/proxying-essentials/configuration-basics/global/|HAProxy Globals]]) befindet sich oben in Ihrer Konfigurationsdatei. Er definiert Anweisungen auf Prozessebene, beispielsweise die maximale Anzahl zulässiger Verbindungen, den Speicherort der Protokolle und den Benutzer und die Gruppe, unter der der Prozess ausgeführt werden soll. Das folgende Beispiel zeigt nur einige der verfügbaren Optionen: | Der globale Abschnitt befindet sich oben in Ihrer Konfigurationsdatei. Er definiert Anweisungen auf Prozessebene, beispielsweise die maximale Anzahl zulässiger Verbindungen, den Speicherort der Protokolle und den Benutzer und die Gruppe, unter der der Prozess ausgeführt werden soll. Das folgende Beispiel zeigt nur einige der verfügbaren Optionen: |
| |
| <code> | <code> |
| ====Defaults==== | ====Defaults==== |
| |
| In einem Abschnitt "defaults" ([[https://www.haproxy.com/documentation/haproxy-configuration-tutorials/proxying-essentials/configuration-basics/defaults/|HAProxy Defaults]]) werden allgemeine Einstellungen gespeichert, die von den nachfolgenden Frontend- und Backend-Abschnitten übernommen werden. Er kann auch lange Konfigurationen durch Reduzierung doppelter Zeilen verkürzen. Beispiel für eine Standardkonfiguration: Durch Hinzufügen von Standardeinstellungen zur Konfiguration können Sie Einstellungen definieren, die gegebenenfalls von allen darunter liegenden Abschnitten übernommen werden. Beispielsweise ist "mode" sowohl auf ein Frontend als auch auf ein Backend anwendbar, "balance" hingegen nur auf Backends. Nicht alle Anweisungen können in "defaults" aufgenommen werden, z.B. die Zeilen "bind" und "server". | * [[https://www.haproxy.com/documentation/haproxy-configuration-tutorials/proxying-essentials/configuration-basics/defaults/|HAProxy Defaults]] |
| | |
| | In einem Abschnitt "defaults" werden allgemeine Einstellungen gespeichert, die von den nachfolgenden Frontend- und Backend-Abschnitten übernommen werden. Er kann auch lange Konfigurationen durch Reduzierung doppelter Zeilen verkürzen. Beispiel für eine Standardkonfiguration: Durch Hinzufügen von Standardeinstellungen zur Konfiguration können Sie Einstellungen definieren, die gegebenenfalls von allen darunter liegenden Abschnitten übernommen werden. Beispielsweise ist "mode" sowohl auf ein Frontend als auch auf ein Backend anwendbar, "balance" hingegen nur auf Backends. Nicht alle Anweisungen können in "defaults" aufgenommen werden, z.B. die Zeilen "bind" und "server". |
| |
| <code> | <code> |
| |
| Siehe [[https://serverfault.com/questions/1193486/how-to-configure-health-check-for-postfix-behind-haproxy-when-using-the-proxy-pr]] | Siehe [[https://serverfault.com/questions/1193486/how-to-configure-health-check-for-postfix-behind-haproxy-when-using-the-proxy-pr]] |
| | =====ACL===== |
| | |
| | ACL geben true oder false zurück. Die ACL kann dann in jeder Zeile angewendet werden die ein conditional if or unless statement abfragt. Siehe [[https://www.haproxy.com/documentation/haproxy-configuration-tutorials/proxying-essentials/custom-rules/acls/|ACL Dokumentation]] |
| | |
| | <code> |
| | frontend www |
| | bind :80 |
| | acl images_url path_beg -i /images/ |
| | use_backend static_assets if images_url |
| | </code> |
| | |
| | =====Fetches===== |
| | |
| | [[https://www.haproxy.com/documentation/haproxy-configuration-tutorials/proxying-essentials/custom-rules/fetches/|Fetch Dokumentation]] |
| | |
| | Eine Funktion, die Informationen über die aktuelle Anfrage, die aktuelle Antwort, die Verbindung oder den internen Zustand des Load Balancers zurückgibt. |
| | |
| | <code> |
| | frontend www |
| | bind :80 |
| | http-request deny if { path /api/bad/ } |
| | </code> |
| | |
| | <code> |
| | frontend www |
| | bind :80 |
| | http-request set-var(txn.http_version) req.ver |
| | http-response add-header Via "%[var(txn.http_version)] %[hostname]" |
| | </code> |
| | =====Persistence===== |
| | |
| | ====Stick Table==== |
| | |
| | Siehe [[https://www.haproxy.com/documentation/haproxy-configuration-tutorials/proxying-essentials/custom-rules/stick-tables/|Stick Table Dokumentation]] |
| | |
| | <code> |
| | # Track src IP, max 1Mill entries expire after 30m |
| | backend app_servers |
| | stick-table type ip size 1m expire 30m |
| | stick on src |
| | server app1 192.168.1.10:80 check |
| | server app2 192.168.1.11:80 check |
| | </code> |
| | |
| =====Links===== | =====Links===== |
| |