informatica:linux:haproxy
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
informatica:linux:haproxy [2012/10/05 12:07] – javi | informatica:linux:haproxy [2015/04/13 20:19] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 4: | Line 4: | ||
http:// | http:// | ||
+ | |||
===== Instalacion ===== | ===== Instalacion ===== | ||
+ | |||
+ | ==== Paquete debian ==== | ||
sudo aptitude update; sudo aptitude install haproxy | sudo aptitude update; sudo aptitude install haproxy | ||
+ | |||
+ | ==== Fuentes ==== | ||
+ | |||
+ | Importante para obtener soporte SSL | ||
+ | |||
+ | 1. (Opcional) Instalar dependencias: | ||
+ | |||
+ | sudo aptitude update; sudo aptitude install build-essential libpcre3-dev libssl-dev | ||
+ | |||
+ | 2. Descargar: | ||
+ | |||
+ | cd /usr/local; sudo wget -c --tries=0 http:// | ||
+ | |||
+ | 3. Descomprimir | ||
+ | |||
+ | sudo tar xvfz haproxy-1.5-dev15.tar.gz; | ||
+ | |||
+ | 4. Compilar: | ||
+ | |||
+ | cd / | ||
+ | sudo make install | ||
===== Config ===== | ===== Config ===== | ||
+ | |||
+ | http:// | ||
En este ejemplo: | En este ejemplo: | ||
Line 55: | Line 81: | ||
server webA 10.0.0.5:80 cookie B check | server webA 10.0.0.5:80 cookie B check | ||
+ | listen mysql balancer.dev.jj.com: | ||
+ | mode tcp | ||
+ | balance roundrobin | ||
+ | timeout connect 50000ms | ||
+ | timeout client 500000ms | ||
+ | timeout server 500000ms | ||
+ | # Requires ' | ||
+ | option mysql-check usuario | ||
+ | log global | ||
+ | server mysql-1.dev.jj.com mysql-2.dev.jj.com: | ||
+ | server mysql-2.dev.jj.com mysql-3.dev.jj.com: | ||
listen test 10.0.0.15: | listen test 10.0.0.15: | ||
Line 64: | Line 101: | ||
Ejemplo TCP (da un warning si mantenemos | Ejemplo TCP (da un warning si mantenemos | ||
+ | |||
===== Servicio ===== | ===== Servicio ===== | ||
Line 72: | Line 110: | ||
wget -O - http:// | wget -O - http:// | ||
+ | |||
+ | |||
+ | ===== Logging ===== | ||
+ | |||
+ | http:// | ||
+ | |||
+ | 1. Crear una entrada en rsyslog para haproxy | ||
+ | |||
+ | sudo vim / | ||
+ | |||
+ | Con el siguiente contenido: | ||
+ | |||
+ | < | ||
+ | $ModLoad imudp | ||
+ | $UDPServerRun 514 | ||
+ | $UDPServerAddress 127.0.0.1 | ||
+ | |||
+ | # ..and in any case, put these two in / | ||
+ | local1.* -/ | ||
+ | |||
+ | & ~ | ||
+ | # & ~ means not to put what matched in the above line anywhere else for the rest of the rules | ||
+ | # http:// | ||
+ | </ | ||
+ | |||
+ | 2. Reiniciar rsyslogd: | ||
+ | |||
+ | sudo / | ||
+ | |||
+ | 3. Editar: | ||
+ | |||
+ | sudo vim / | ||
+ | |||
+ | Y dejar la siguiente linea dentro de la seccion ' | ||
+ | |||
+ | < | ||
+ | global | ||
+ | log | ||
+ | </ | ||
+ | |||
+ | 4. Reiniciar haproxy y ver el log: | ||
+ | |||
+ | < | ||
+ | sudo / | ||
+ | sudo tail -F / | ||
+ | </ | ||
+ | |||
+ | 5. (Opcional) rotar logs: | ||
+ | |||
+ | < | ||
+ | / | ||
+ | |||
+ | / | ||
+ | { | ||
+ | rotate 4 | ||
+ | weekly | ||
+ | missingok | ||
+ | notifempty | ||
+ | compress | ||
+ | delaycompress | ||
+ | sharedscripts | ||
+ | postrotate | ||
+ | reload rsyslog >/ | ||
+ | endscript | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ===== HTTP + Apache logging IP cliente ===== | ||
+ | |||
+ | 1. En el balanceador de carga (haproxy) anyadir la directiva ' | ||
+ | |||
+ | < | ||
+ | |||
+ | / | ||
+ | |||
+ | ... | ||
+ | listen www balancer.dev.jj.com: | ||
+ | mode http | ||
+ | balance roundrobin | ||
+ | server www-1.dev.jj.com www-1.dev.jj.com: | ||
+ | server www-2.dev.jj.com www-2.dev.jj.com: | ||
+ | option httplog | ||
+ | option logasap | ||
+ | option forwardfor | ||
+ | log global | ||
+ | ... | ||
+ | </ | ||
+ | |||
+ | 2. En el backend (www-1.dev.jj.com, | ||
+ | |||
+ | < | ||
+ | / | ||
+ | |||
+ | ... | ||
+ | LogFormat " | ||
+ | ... | ||
+ | |||
+ | </ | ||
+ | |||
+ | |||
+ | ===== Estadisticas ===== | ||
+ | |||
+ | 1. Habilitar estadisticas. TODO: revisar config y hacer lo mismo a traves de peticiones HTTP en lugar de socket | ||
+ | |||
+ | sudo vim / | ||
+ | |||
+ | Y anyadir/ | ||
+ | |||
+ | < | ||
+ | global | ||
+ | stats socket / | ||
+ | </ | ||
+ | |||
+ | 2. Reiniciar haproxy | ||
+ | |||
+ | sudo / | ||
+ | |||
+ | 3. Instalar socat | ||
+ | |||
+ | sudo aptitude update; sudo aptitude install socat | ||
+ | |||
+ | 4. Convertirse en root y probar comandos: | ||
+ | |||
+ | clear;echo "show stat" | socat unix-connect:/ | ||
+ | |||
+ | Listado completo de comandos en la seccion '9.2. Unix Socket commands' | ||
+ | |||
+ | ==== Deshabilitar/ | ||
+ | |||
+ | Requiere tener las estadisticas habilitadas y ser root. | ||
+ | |||
+ | **Deshabilitar**: | ||
+ | |||
+ | clear;echo " | ||
+ | |||
+ | **Habilitar**: | ||
+ | |||
+ | clear;echo " | ||
+ |
informatica/linux/haproxy.txt · Last modified: 2015/04/13 20:19 by 127.0.0.1