Editing
HAProxy
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== HAProxy pe Ubuntu 2X.04 LTS == [[File:HAProxy.png|782x616px|none|HAProxy]] === Instalare HAProxy === La instalare HAProxy activează serviciul systemd. <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> # apt -y install haproxy </code> === Structura fișierului de configurare === Fișierul principal: <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> # nano /etc/haproxy/haproxy.cfg </code> Configurația este împărțită în: * global – setări pentru procesul HAProxy * defaults – setări implicite pentru toate secțiunile * frontend – puncte de intrare pentru trafic * backend – serverele către care se trimite traficul ==== Secțiunea global ==== <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> global     log /dev/log local0     log /dev/log local1 notice     maxconn 4096     user haproxy     group haproxy     daemon </code> * log /dev/log local0 – trimite logurile către syslog. * log /dev/log local1 notice – al doilea canal de log, nivel minim notice. * maxconn 4096 – număr maxim de conexiuni simultane. * user/group haproxy – rulează cu userul de sistem haproxy. * daemon – rulează în background. ==== Secțiunea defaults ==== <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> defaults     log global     mode http     option httplog     option dontlognull     timeout connect 5s     timeout client 30s     timeout server 30s </code> * log global – folosește setările din secțiunea global. * mode http – modul implicit pentru frontend/backend.* * option httplog – loguri detaliate HTTP. * option dontlognull – nu loghează conexiuni goale. * timeout connect/client/server – limite de timp pentru conexiuni.  * Dacă un frontend sau backend are propriul mode (ex: mode tcp), acesta suprascrie automat valoarea din defaults ==== Frontend HTTP (port 80) ==== <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> frontend http_in     bind *:80     mode http     option forwardfor     default_backend http_webserver </code> * *bind :80 – ascultă pe portul 80. * mode http – procesează header-ele HTTP. * option forwardfor – adaugă X‑Forwarded‑For cu IP-ul real al clientului. * default_backend http_webserver – trimite traficul către backend-ul HTTP. ==== Backend HTTP ==== <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> backend http_webserver     mode http     balance leastconn     option httpchk GET /     server vm01 192.168.14.11:80 check     server vm02 192.168.14.22:80 check     server vm03 192.168.14.33:80 check </code> * mode http – backend-ul procesează HTTP. * balance leastconn – trimite traficul către serverul cu cele mai puține conexiuni active. * option httpchk GET / – health-check HTTP. * server vm01/vm02/vm03 – cele trei VM. === HTTPS (port 443) cu SSL Termination în HAProxy === În această situaţie HAProxy gestionează certificatul. ==== Generare certificat Let’s Encrypt ==== Necesită port 80 public și domeniu valid.<br> Certbot, în modul <span style=" font-family: Courier New;">--standalone</span>, pornește un mini‑webserver intern pe portul 80 pentru a răspunde la challenge-ul HTTP‑01 de la Let’s Encrypt.<br> Dacă HAProxy este pornit, acesta ocupă portul 80 și Certbot nu poate porni serverul de validare, ceea ce duce la eșecul generării certificatului. '''Instalare certbot''' <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> apt -y install certbot </code> '''Oprire temporară HAProxy''' <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> systemctl stop haproxy </code> '''Generare certificat''' <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> certbot certonly --standalone -d wiki.stradivart.ro </code> '''Creare fișier PEM pentru HAProxy''' <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> # mkdir -p /etc/haproxy/certs  # cat /etc/letsencrypt/live/wiki.stradivart.ro/fullchain.pem \    /etc/letsencrypt/live/wiki.stradivart.ro/privkey.pem \    > /etc/haproxy/certs/wiki.stradivart.ro.pem  # chmod 600 /etc/haproxy/certs/wiki.stradivart.ro.pem </code> ==== Frontend HTTPS (SSL termination) ==== <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> frontend https_in     bind *:443 ssl crt /etc/haproxy/certs/wiki.stradivart.ro.pem     mode http     option forwardfor     default_backend http_webserver </code> * *bind :443 ssl crt ... – HAProxy decriptează SSL. * mode http – traficul devine HTTP după terminarea SSL. * default_backend http_webserver – backend-ul HTTP unic. ==== Backend HTTPS (SSL termination) ==== În cazul SSL termination, backend-ul nu procesează trafic HTTPS.<br> HAProxy decriptează SSL în frontend, iar backend-ul primește trafic HTTP normal (non‑SSL).<br> De aceea backend-ul este identic cu backend-ul HTTP. <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> backend http_webserver     mode http     balance leastconn     option httpchk GET /     server vm01 192.168.14.11:80 check     server vm02 192.168.14.22:80 check     server vm03 192.168.14.33:80 check </code> * mode http – backend-ul procesează HTTP. * balance leastconn – trimite traficul către serverul cu cele mai puține conexiuni active. * option httpchk GET / – health-check HTTP. * server vm01/vm02/vm03 – cele trei VM. === HTTPS (port 443) cu SSL Passthrough === Webserver-ul gestionează certificatul. HAProxy doar forward-ează pachetele SSL. ==== Frontend HTTPS (SSL passthrough) ==== <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> frontend https_in     bind *:443     mode tcp     default_backend httpS_webserver </code> * *bind :443 – ascultă pe portul 443. * mode tcp – HAProxy nu decriptează SSL. * default_backend httpS_webserver – backend separat în modul TCP. ==== Backend HTTPS (SSL passthrough) ==== <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> backend httpS_webserver     mode tcp     balance leastconn     server vm01 192.168.14.11:443 check     server vm02 192.168.14.22:443 check     server vm03 192.168.14.33:443 check </code> * mode tcp – forward transparent al pachetelor SSL. * balance leastconn – distribuție inteligentă. * server vm01/vm02/vm03 – VM-urile ISPConfig. === Pagina de statistici HAProxy === <code class="mw-code mw-highlight plainlinks" style="display:block"><!-- --> listen stats     bind *:9000     mode http     stats enable     stats uri /stats     stats refresh 5s     stats auth admin:pass123 </code> * *bind :9000 – port dedicat pentru statistici. * stats uri /stats – URL-ul paginii. * stats auth – autentificare basic HTTP. ==== Accesare pagina de statistici ==== http://192.168.14.123:9000/stats [[File:HAProxy stats.png|782x616px|none|HAProxy_stats]] {| style="width:100%" |- | style="width:33%; vertical-align:middle; text-align:center; padding:15px;" | FILE | style="width:33%; vertical-align:middle; text-align:center; padding:15px;" | FILE | style="width:33%; vertical-align:middle; text-align:center; padding:15px;" | FILE |}
Summary:
Please note that all contributions to Linux Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
Linux Wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
Edit source
View history
More
Navigation
Main page
Aplicatii Linux
UrBackup
rSyslog
KeepAlived
HAProxy
USB over IP
Pi-hole
DHCP
BIND DNS
Hardware Linux
Adaugare Disk
Extindere Disk
Docker
Instalare Docker CE
Portainer
Container UrBackup
Container PiHole
Raspberry Pi
NTP Server
Snippets
History Command
Access Control List
Tools
What links here
Related changes
Special pages
Page information