informatica:linux:haproxy
This is an old revision of the document!
Table of Contents
haproxy
balancer load balancer high availability reverse proxy
Instalacion
sudo aptitude update; sudo aptitude install haproxy
Config
En este ejemplo:
| 10.0.0.15 | Balanceador de carga (haproxy) | | | 10.0.0.4 | Servidor web 1 | Escucha en TCP 666 | | 10.0.0.5 | Servidor web 2 | Escucha en TCP 666 |
sudo mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.old sudo vim /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local0
log 127.0.0.1 local1 notice
#log loghost local0 info
maxconn 4096
#chroot /usr/share/haproxy
user haproxy
group haproxy
daemon
#debug
#quiet
defaults
log global
mode http
option dontlognull
retries 3
option redispatch
maxconn 2000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen webfarm 10.0.0.15:80
mode http
balance roundrobin
cookie SERVERID insert indirect
option httpchk HEAD /index.html HTTP/1.0
option httplog
server webA 10.0.0.4:80 cookie A check
server webA 10.0.0.5:80 cookie B check
listen test 10.0.0.15:666
mode tcp
balance roundrobin
server testA 10.0.0.4:666
server testB 10.0.0.5:666
Ejemplo TCP (da un warning si mantenemos
Servicio
sudo /etc/init.d/haproxy restart
Probar:
wget -O - http://10.0.0.15
Logging
http://kevin.vanzonneveld.net/techblog/article/haproxy_logging/
1. Crear una entrada en rsyslog para haproxy
sudo vim /etc/rsyslog.d/haproxy.conf
Con el siguiente contenido:
$ModLoad imudp $UDPServerRun 514 $UDPServerAddress 127.0.0.1 # ..and in any case, put these two in /etc/rsyslog.d/haproxy.conf: local1.* -/var/log/haproxy_1.log & ~ # & ~ means not to put what matched in the above line anywhere else for the rest of the rules # http://serverfault.com/questions/214312/how-to-keep-haproxy-log-messages-out-of-var-log-syslog
2. Reiniciar rsyslogd:
sudo /etc/init.d/rsyslog restart
3. Editar:
sudo vim /etc/haproxy/haproxy.conf
Y dejar la siguiente linea dentro de la seccion 'global':
global
log 127.0.0.1 local1 debug
4. Reiniciar haproxy y ver el log:
sudo /etc/init.d/haproxy restart sudo tail -F /var/log/haproxy_1.log
5. (Opcional) rotar logs:
/etc/logrotate.d/haproxy
/var/log/haproxy*.log
{
rotate 4
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
reload rsyslog >/dev/null 2>&1 || true
endscript
}
informatica/linux/haproxy.1349680487.txt.gz · Last modified: (external edit)
