Pessoal, nesse post irei demonstrar com instalar o HAProxy – TCP/HTTP Load Balance.

Source Download

[lmascarenhas@myserver ~]# cd /usr/local/myapps/programs<br /> [lmascarenhas@myserver ~]# wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.26.tar.gz

Instalação

[lmascarenhas@myserver ~]# tar -vzxf haproxy-1.3.26.tar.gz<br /> [lmascarenhas@myserver ~]# cd haproxy-1.3.26<br /> [lmascarenhas@myserver ~]# make TARGET=linux26 ARCH=i386<br /> [lmascarenhas@myserver ~]# mkdir -p /usr/local/myapps/haproxy-1.3.26/sbin<br /> [lmascarenhas@myserver ~]# cd /opt/<br /> [lmascarenhas@myserver ~]# ln -s /usr/local/myapps/haproxy-1.3.26 haproxy<br /> [lmascarenhas@myserver ~]# cd /usr/sbin/<br /> [lmascarenhas@myserver ~]# ln -s /opt/haproxy/sbin/haproxy haproxy

Configuração

[lmascarenhas@myserver ~]# vim /etc/haproxy/haproxy.cfg

global<br /> maxconn 20000<br /> uid 0<br /> gid 0<br /> daemon<br /> nopoll<br /> noepoll<br /> pidfile /var/run/haproxy.pid<br /> quiet

defaults

mode http

option httplog

option dontlognull

retries 3

stats enable

redispatch

maxconn 20000

timeout client 300000

timeout connect 10000

timeout server 300000

#LOAD HTTP

listen MyLOAD :80

mode http

balance roundrobin

log local1

option httplog

option dontlognull

option httpclose

option forwardfor

option httpchk HEAD /index_myload.html HTTP/1.0

server server01MyLoad :80 check inter 5000 weight 1

server server01MyLoad :80 check inter 5000 weight 1

stats uri /_stats

stats realm Statistics\ for\ My\ LOAD\ HTTP

stats auth admin:admin

stats scope .

stats scope MyLOAD

Script de inicialização

[lmascarenhas@myserver ~]# vim /etc/init.d/haproxy<br /> #!/bin/sh<br /> #<br /> # chkconfig: - 85 15<br /> # description: HA-Proxy is a TCP/HTTP reverse proxy which is particularly suited \<br /> # for high availability environments.<br /> # processname: haproxy<br /> # config: /etc/haproxy/haproxy.cfg<br /> # pidfile: /var/run/haproxy.pid

# Script Author: Simon Matter simon.matter@invoca.ch

# Version: 2004060600

# Source function library.

if [ -f /etc/init.d/functions ]; then

. /etc/init.d/functions

elif [ -f /etc/rc.d/init.d/functions ] ; then

. /etc/rc.d/init.d/functions

else

exit 0

fi

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ ${NETWORKING} = “no” ] && exit 0

# This is our service name

BASENAME=`basename $0`

if [ -L $0 ]; then

BASENAME=`find $0 -name $BASENAME -printf %l`

BASENAME=`basename $BASENAME`

fi

[ -f /etc/$BASENAME/$BASENAME.cfg ]   exit 1

RETVAL=0

start() {

/usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg

if [ $? -ne 0 ]; then

echo “Errors found in configuration file, check it with ‘$BASENAME check’.”

return 1

fi

echo -n “Starting $BASENAME: ”

daemon /usr/sbin/$BASENAME -D -f /etc/$BASENAME/$BASENAME.cfg -p /var/run/$BASENAME.pid

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASENAME

return $RETVAL

}

stop() {

echo -n “Shutting down $BASENAME: ”

killproc $BASENAME -USR1

RETVAL=$?

echo

[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$BASENAME

[ $RETVAL -eq 0 ] && rm -f /var/run/$BASENAME.pid

return $RETVAL

}

restart() {

/usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg

if [ $? -ne 0 ]; then

echo “Errors found in configuration file, check it with ‘$BASENAME check’.”

return 1

fi

stop

start

}

check() {

/usr/sbin/$BASENAME -c -q -V -f /etc/$BASENAME/$BASENAME.cfg

}

rhstatus() {

status $BASENAME

}

condrestart() {

[ -e /var/lock/subsys/$BASENAME ] && restart   :

}

# See how we were called.

case “$1″ in

start)

start

;;

stop)

stop

;;

restart)

restart

;;

reload)

restart

;;

condrestart)

condrestart

;;

status)

rhstatus

;;

check)

check

;;

*)

echo $”Usage: $BASENAME {start stop restart reload condrestart status check}”

exit 1

esac

exit $?

Alterar permissão

[lmascarenhas@myserver ~]# chmod a+x /etc/init.d/haproxy

Fonte: http://haproxy.1wt.eu