Guía para la instalación de haproxy

19 01 2012

Pasos para instalar haproxy desde código fuente en un servidor Debian:

Instalar pcre

Instalar gcc y g++

Bajar y compilar haproxy con las siguientes opciones:

# make TARGET=linux26 USE_PCRE=1

Crear un script de init.d:

#!/bin/sh
### BEGIN INIT INFO
# Provides: haproxy
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop haproxy
### END INIT INFO
HA_BIN=/usr/local/sbin/haproxy
HA_CONF=/etc/haproxy/haproxy.conf
HA_PID=/var/run/haproxy.pid
case "$1" in
start)
echo "Iniciando Haproxy..."
$HA_BIN -f $HA_CONF -D
;;
stop)
echo "Parando Haproxy..."
start-stop-daemon --stop --exec $HA_BIN
;;
restart)
$0 stop
sleep 10
$0 start
;;
reload)
$HA_BIN -D -f $HA_CONF -p $HA_PID -st $(cat $HA_PID)
;;
status)
if pidof -o %PPID haproxy > /dev/null; then
echo "Haproxy iniciado."
exit 0
else
echo "Haproxy Parado."
exit 1
fi
;;
test)
$HA_BIN -f $HA_CONF -c
;;
*)
echo "Usage: $0 {start|stop|restart|reload|status|test}"
exit 1
esac
# Para instalar
# update-rc.d haproxy defaults

Crear el directorio /etc/haproxy y copiar la conf básica en el archivo “/etc/haproxy/haproxy.conf”:

global
maxconn 10000
log 127.0.0.1 local5 info err
stats socket /var/run/haproxy.sock mode 0600 level admin
pidfile /var/run/haproxy.pid
defaults
mode http
log global
retries 3
option redispatch
timeout contimeout 100
timeout client 10000
timeout srvtimeout 100
timeout http-keep-alive 10000
# option abortonclose
listen proxy-http *:80
mode http
option httplog
stats enable
# Limitar conexiones:
# maxconn 50000
# acl too_fast fe_sess_rate ge 100
# tcp-request inspect-delay 100ms
# tcp-request content accept if ! too_fast
# tcp-request content accept if WAIT_END
#
# Bloquear request con Content-Length negativa:
acl invalid-cl hdr_val(content-length) le 0
block if invalid-cl
balance roundrobin
option http-server-close
acl rule1 url_dir fotos
use_backend back-http-fotos if rule1
default_backend back-http
listen proxy-stats *:8080
mode http
option httplog
stats enable
stats show-legends
stats uri /admin?stats
stats realm Haproxy\ Statistics
stats auth user:pass
stats refresh 5s
backend back-http
option httpchk GET /live.php
http-check expect string OK
cookie WEBSERVERID insert
srvtimeout 30000
server web1.system 192.168.1.5:80 cookie A check inter 5000 fastinter 1000 downinter 1000 rise 2 fall 2
server web2.system 192.168.1.6:80 cookie B check inter 5000 fastinter 1000 downinter 1000 rise 2 fall 2
backend back-http-fotos
server web3.system 192.168.1.7:80/fotos

Instalr syslog-ng y configurar el loggin para que reciba los que le envía haproxy.

Dentro de /etc/syslog-ng/syslog-ng.conf se encuentran las líneas:
source s_src { unix-dgram("/dev/log"); internal();
file("/proc/kmsg" program_override("kernel"));
};
Añadir “udp(ip(“0.0.0.0″) port(514));” y dejarlo así:
source s_src { unix-dgram("/dev/log"); internal();
file("/proc/kmsg" program_override("kernel"));
udp(ip("0.0.0.0") port(514));
};

Reiniciar syslog y haproxy, comprobando después que se encuentra escuchando en el puerto 80y 8080:
# netstat -tanp

About these ads

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Follow

Get every new post delivered to your Inbox.

%d bloggers like this: