Problemy ? Co to jest HAProxy? Zabawę czas zacząć...

Post on 28-Jul-2018

220 views 0 download

Transcript of Problemy ? Co to jest HAProxy? Zabawę czas zacząć...

-czyli jak pozwolić adminowi spać w nocy

● Problemy ?● Co to jest HAProxy?● Zabawę czas zacząć● Podsumowanie

Maciej Milaszewski

maciejm@hicon.pl

Problem:

● Wzrost zainteresowania serwisu● Klient maruda● KLIENT MARUDA ;)● Optymalizacja● KOSZTA KOSZTA

„Miałem raczej na myśli układ w którym Ty odwalasz czarną robotę, a Ja się na to patrzę i siem niecierpliwie „

The Reliable, High Performance TCP/HTTP Load Balancer

„Szacuneczek, pradawni bogowie.”

„Dobra a teraz się skup bo wcielam się w robota i to jest wstrząsający performance!”

● LoadBalancer TCP / http● Wydajny● Szybki● HA(High Availability)● Niezawodny ● Wielosystemowy● DOKUMENTACJA

http://haproxy.1wt.eu/

16 kB per session, ~60000 sessions per GB RAM

108000 HTTP requests per second

40000 forwarded HTTP requests per second

Dual Core 1.8 25000 sessions/s (hit/s)

„Chodź, robimy performance.”

Konfiguracja:

global log 127.0.0.1 local1 notice #log loghost:514 local0 info maxconn 4096 user haproxy group haproxy defaults mode http timeout connect 5000ms timeout client 50000ms timeout server 50000ms frontend http-in bind 192.168.1.1:80 default_backend servers

backend servers server server1 192.168.1.100:80 maxconn 500 check inter 2000 fall 2 listen http-in2 bind 192.168.1.2:80 server server1 192.168.1.1001:80 maxconn 500 check inter 2000 fall 2

„Zawsze jest jakaś opcja.”

● Haproxy● 2 x nod www● 1 x backup

listen KLIENT 192.168.1.1:80

mode httpbalance roundrobinoption httpchkoption httpclose server websvr1 192.168.1.100:80 max con 500 check inter 1000 fall 5 server websvr2 192.168.1.101:80 max con 500 check inter 1000 fail 5 server websvr-backup 192.168.1.200:80 check backup

„Będzie piękny, genialny, ale co najważniejsze skromny.”

Konfiguracja A:

listen KLIENT 192.168.1.1:80

mode httpbalance roundrobinoption httpchkoption httpclose server websvr1 192.168.1.100:80 max con 500 check inter 1000 fall 5 weigh 20 server websvr2 192.168.1.101:80 max con 500 check inter 1000 fail 5 weigh 80 server websvr-backup 192.168.1.200:80 check backup

„Będzie piękny, genialny, ale co najważniejsze skromny.”

Konfiguracja A:

● Haproxy● 2 x nod www:

- static Nginx

- dynamic apache2● 1 x backup

frontend KLIENTbind 192.168.1.1:80

acl acl_static_nginx url reg .\*.(gif|jpg|jpeg|png|js|pdf|swf|css)$acl acl_dynamic_apache path_end .php .html

use_backend nginx if acl_static_nginxuse_backend apache if acl_dynamic_apachedefault_backend apache

backend nginxmode httpbalance roundrobinoption httpchkoption httpclose server websvr1 192.168.1.100:80 max con 500 check inter 1000 fall 5 server websvr-backup 192.168.1.200:81 check backup

backend apachemode httpbalance roundrobinoption httpchkoption httpclose server websvr2 192.168.1.101:80 max con 500 check inter 1000 fall 5 server websvr-backup 192.168.1.200:80 check backup

listen stats bind 127.0.0.1:1212 stats enable stats hide-version stats uri / stats realm stats

„Mam moc, mam moc!” Konfiguracja B - ACL:

frontend KLIENTbind 192.168.1.1:80

acl acl_static_nginx url_reg .\*.(gif|jpg|jpeg|png|js|pdf|swf|css)$acl acl_dynamic_apache path_end .php .html

acl missing_slash path_reg ^/article/[^/]*$redirect code 301 prefix / drop-query append-slash if missing_slash

acl mysite_www hdr_reg(host) ^mydomain.comredirect code 301 location http://www.mydomain.com if mysite_www

use_backend nginx if acl_static_nginxuse_backend apache if acl_dynamic_apachedefault_backend apache

„Mam moc, mam moc!” Konfiguracja B - ACL:

acl acl_static_nginx url reg .\*.(gif|jpg|jpeg|png|js|pdf|swf|css)$acl acl_dynamic_apache path_end .php .html

use_backend nginx if acl_static_nginxuse_backend apache if acl_dynamic_apachedefault_backend apache

backend nginxmode httpbalance roundrobinoption httpchk server websvr1 192.168.1.100:80 max con 500 check inter 1000 fall 5 weigh 20 server websvr1a 192.168.1.101:80 max con 500 check inter 1000 fall 5 weigh20 server websvr-backup1 192.168.1.200:80 check backup

backend apachemode httpbalance roundrobinoption httpchk server websvr2 192.168.1.60:80 max con 500 check inter 1000 fall 5 weigh 20 server websvr2a 192.168.1.61:80 max con 500 check inter 1000 fall 5 weigh 20 server websvr-backup2 192.168.1.201:80 check backup

„Albowiem łi ar wy czempions! ”

Konfiguracja B - ACL:

„Nie.. a nawet tak! ” A co z SSL ?

„Nie.. a nawet tak! Hańba Ci! ”A co z SSL ?

Powered by STUNNEL:

cert = /etc/stunnel/cert/foo.crtkey = /etc/stunnel/cert/foo.keyaccept = 443connect = IP:PORT (HAProxy np. 4343)xforwardedfor = yes

HAProxy:

Frontend IP:PORT (HAProxy np. 4343)IP:PORTreqadd HTTPS:\ ondefault_backend websvr2

„ .. nom, som takie sytuacje ”SMTP

listen stats :80mode httpstats enablestats auth hadmin:alamakotastats refresh 50s

listen smtp 194.176.X.X:25mode tcpmaxconn 1000option tcplogbalance roundrobin

server mail133 194.X.X.133:25 check inter 10000server mail132 194.X.X.132:25 check inter 10000

„Szacuneczek, pradawni bogowie.”

listen stats bind 192.168.1.10:1212 stats enable stats hide-version stats uri / stats realm stats

„Szacuneczek, pradawni bogowie.”

globalstats socket /var/run/haproxy.stats

„ .. nom, som takie sytuacje ”

„ .. nom, som takie sytuacje ” IN PROGRESS:1 x HAProxy

„ .. nom, som takie sytuacje ” IN PROGRESS:1 x HAProxy1 x embadded web server

„ .. nom, som takie sytuacje ” IN PROGRESS:1 x HAProxy1 x embadded web server1 x kofimaszin ;)

„ .. nom, som takie sytuacje ” IN PROGRESS:1 x HAProxy1 x embadded web server1 x kofimaszin ;)

„ .. nom, som takie sytuacje ”

„....Która to opowieść mnie znudziła, bo nie była o mnie. Kumasz zależność.„

„Cięcie! Po reżysersku to znaczy morda. „

KONIEC