Jun 24

There are only a few command line options about haproxy:

    -f <configuration file>
    -n <high limit for the total number of simultaneous connections>
       = ‘maxconn’ in ‘global’ section
    -N <high limit for the per-listener number of simultaneous connections>
       = ‘maxconn’ in ‘listen’ or ‘default’ sections
    -d starts in foregreound with debugging mode enabled
    -D starts in daemon mode
    -q disable messages on output
    -V displays messages on output even when -q or ‘quiet’ are specified.
    -c only checks config file and exits with code 0 if no error was found, or
       exits with code 1 if a syntax error was found.
    -p <pidfile> asks the process to write down each of its children’s
       pids to this file in daemon mode.
    -sf specifies a list of pids to send a FINISH signal to after startup.
    -st specifies a list of pids to send a TERMINATE signal to after startup.
    -s shows statistics (only if compiled in)
    -l shows even more statistics (implies ‘-s’)
    -dk disables use of kqueue()
    -ds disables use of speculative epoll()
    -de disables use of epoll()
    -dp disables use of poll()
    -db disables background mode (stays in foreground, useful for debugging)
    -m <megs> enforces a memory usage limit to a maximum of <megs> megabytes.

The maximal number of connections per proxy instance is used as the default
parameter for each instance for which the ‘maxconn’ paramter is not set in the
‘listen’ section.

The maximal number of total connections limits the number of connections used by
the whole process if the ‘maxconn’ parameter is not set in the ‘global’ section.

The debugging mode has the same effect as the ‘debug’ option in the ‘global’
section. When the proxy runs in this mode, it dumps every connections,
disconnections, timestamps, and HTTP headers to stdout. This should NEVER
be used in an init script since it will prevent the system from starting up.

For debugging, the ‘-db’ option is very useful as it temporarily disables
daemon mode and multi-process mode. The service can then be stopped by simply
pressing Ctrl-C, without having to edit the config nor run full debug.

Statistics are only available if compiled in with the ‘STATTIME’ option. It’s
only used during code optimization phases, and will soon disappear.

The ‘-st’ and ‘-sf’ options are used for hot reconfiguration.

Tagged with:
Jun 24

HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications. It is particularly suited for web sites crawling under very high loads while needing persistence or Layer7 processing

Performance Parameters of Haproxy:

maxconn <number>
  Sets the maximum per-process number of concurrent connections to <number>. It
  is equivalent to the command-line argument "-n". Proxies will stop accepting
  connections when this limit is reached. The "ulimit-n" parameter is
  automatically adjusted according to this value. See also "ulimit-n".

maxpipes <number>
  Sets the maximum per-process number of pipes to <number>. Currently, pipes
  are only used by kernel-based tcp splicing. Since a pipe contains two file
  descriptors, the "ulimit-n" value will be increased accordingly. The default
  value is maxconn/4, which seems to be more than enough for most heavy usages.
  The splice code dynamically allocates and releases pipes, and can fall back
  to standard copy, so setting this value too low may only impact performance.

noepoll
  Disables the use of the "epoll" event polling system on Linux. It is
  equivalent to the command-line argument "-de". The next polling system
  used will generally be "poll". See also "nosepoll", and "nopoll".

nokqueue
  Disables the use of the "kqueue" event polling system on BSD. It is
  equivalent to the command-line argument "-dk". The next polling system
  used will generally be "poll". See also "nopoll".

nopoll
  Disables the use of the "poll" event polling system. It is equivalent to the
  command-line argument "-dp". The next polling system used will be "select".
  It should never be needed to disable "poll" since it’s available on all
  platforms supported by HAProxy. See also "nosepoll", and "nopoll" and
  "nokqueue".

nosepoll
  Disables the use of the "speculative epoll" event polling system on Linux. It
  is equivalent to the command-line argument "-ds". The next polling system
  used will generally be "epoll". See also "nosepoll", and "nopoll".

nosplice
  Disables the use of kernel tcp splicing between sockets on Linux. It is
  equivalent to the command line argument "-dS".  Data will then be copied
  using conventional and more portable recv/send calls. Kernel tcp splicing is
  limited to some very recent instances of kernel 2.6. Most verstions between
  2.6.25 and 2.6.28 are buggy and will forward corrupted data, so they must not
  be used. This option makes it easier to globally disable kernel splicing in
  case of doubt. See also "option splice-auto", "option splice-request" and
  "option splice-response".

spread-checks <0..50, in percent>
  Sometimes it is desirable to avoid sending health checks to servers at exact
  intervals, for instance when many logical servers are located on the same
  physical server. With the help of this parameter, it becomes possible to add
  some randomness in the check interval between 0 and +/- 50%. A value between
  2 and 5 seems to show good results. The default value remains at 0.

tune.maxaccept <number>
  Sets the maximum number of consecutive accepts that a process may perform on
  a single wake up. High values give higher priority to high connection rates,
  while lower values give higher priority to already established connections.
  This value is limited to 100 by default in single process mode. However, in
  multi-process mode (nbproc > 1), it defaults to 8 so that when one process
  wakes up, it does not take all incoming connections for itself and leaves a
  part of them to other processes. Setting this value to -1 completely disables
  the limitation. It should normally not be needed to tweak this value.

tune.maxpollevents <number>
  Sets the maximum amount of events that can be processed at once in a call to
  the polling system. The default value is adapted to the operating system. It
  has been noticed that reducing it below 200 tends to slightly decrease
  latency at the expense of network bandwidth, and increasing it above 200
  tends to trade latency for slightly increased bandwidth.

Tagged with:
May 14

HAProxy is a TCP/HTTP reverse proxy which is particularly suited for high availability environments. Indeed, it can : – route HTTP requests depending on statically assigned cookies ; – spread the load among several servers while assuring server persistence through the use of HTTP cookies ; – switch to backup servers in the event a main one fails ; – accept connections to special ports dedicated to service monitoring ; – stop accepting connections without breaking existing ones ; – add/modify/delete HTTP headers both ways ; – block requests matching a particular pattern ;

Install:
1.download haproxy.
wget http://haproxy.1wt.eu/download/1.3/src/haproxy-1.3.18.tar.gz
You can get the last version from the website

2.unzip haproxy
tar zxvf  haproxy-1.3.18.tar.gz

3.compile
make TARGET=linux26
More detail you can look for the file README of the soure files.
mv haproxy-1.3.18 /usr/local/haproxy

4.create config file
vi /usr/local/haproxy/proxy.cfg
global
        uid 99
        gid 99
        maxconn 48000
        chroot  /usr/local/haproxy
        daemon
        quiet
        nbproc  2
        #pidfile /var/run/haproxy-private.pid

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        log 127.0.0.1 local3
        retries 3
        option  redispatch
        maxconn 2000
        contimeout      5000
        clitimeout      50000
        srvtimeout      50000

listen http-proxy :80
        mode http
        stats uri /haproxy-stats
        stats realm Haproxy\ statistics
        stats auth monitor:StatusM5776
        balance roundrobin
        #balance source
        cookie PHPSESSID prefix
        option httpclose
        option forwardfor
        option httpchk HEAD /adima/logo.gif HTTP/1.0
        appsession PHPSESSID len 32 timeout 86400000
        server ht1 192.168.10.1:80 cookie ht1 check inter 3000 rise 2 fall 3
        server ht2 192.168.10.2:80 cookie ht2 check inter 3000 rise 2 fall 3
        server ht3 192.168.10.3:80 cookie ht3 check inter 3000 rise 2 fall 3

5.start haproxy shell

#!/bin/sh
# chkconfig: 2345 80 32
# description: haproxy is a Web Agent, which is the program \

ulimit -SHn 51200
MPRO="/usr/local/haproxy/haproxy"
DCFG="/usr/local/haproxy/proxy.cfg"

[ -x ${MPRO} ] || exit 0

RETVAL=0

start () {
        echo -n "Starting haproxy: "
        ${MPRO} -f $DCFG
        RETVAL=$?
       [ $RETVAL -eq 0 ] && touch /var/lock/subsys/haproxy
        echo
       return $RETVAL
}

stop() {
       # Stop daemons.
       echo -n "Shutting down haproxy: "
       killall haproxy
       RETVAL=$?
       [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/haproxy
       echo
       return $RETVAL
}

restart() {
        stop
        sleep 1
        start
}

case "$1" in
start)

       start
       ;;
stop)
       stop
       ;;
restart)
       restart
       ;;
*)
       echo "Usage: haproxy {start|stop|restart}"
       exit 1
esac

exit $?

Tagged with:
preload preload preload