HAProxy – build from scrach on CentOS

Es ist simpler als man denkt, denn HAProxy auf CentOS zum laufen zukriegen.
Zu erst benötigen wir nur die richtigen Pakete

yum install gcc make openssl-devel zlib-devel pcre-devel

Dann läd man sich die neuste Version des HAProxy von http://www.haproxy.org/#down herunter und entpackt sie.

wget "http://www.haproxy.org/download/1.6/src/haproxy-1.6.3.tar.gz"
tar xzf haproxy-1.6.3.tar.gz

und dann muss er nur noch gebaut werden.

cd haproxy-1.6.3
make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_CRYPT_H=1 USE_LIBCRYPT=1 ARCH=native

Und natürlich noch das init-scipt:

#!/bin/sh
#
# haproxy
#
# chkconfig: - 85 15
# description: HAProxy is a free, very fast and reliable solution \
# offering high availability, load balancing, and \
# proxying for TCP and HTTP-based applications
# processname: haproxy
# config: /etc/haproxy/haproxy.cfg
# pidfile: /var/run/haproxy.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0

exec="/opt/haproxy-1.6.3/haproxy"
prog=$(basename $exec)

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/haproxy

check() {
$exec -c -V -f /etc/$prog/$prog.cfg
}

start() {
$exec -c -q -f /etc/$prog/$prog.cfg
if [ $? -ne 0 ]; then
echo "Errors in configuration file, check with $prog check."
return 1
fi
echo -n $"Starting $prog: "
# start it up here, usually something like "daemon $exec"
daemon $exec -D -f /etc/$prog/$prog.cfg -p /var/run/$prog.pid
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

stop() {
echo -n $"Stopping $prog: "
# stop it here, often "killproc $prog"
killproc $prog
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}

restart() {
$exec -c -q -f /etc/$prog/$prog.cfg
if [ $? -ne 0 ]; then
echo "Errors in configuration file, check with $prog check."
return 1
fi
stop
start
}

reload() {
$exec -c -q -f /etc/$prog/$prog.cfg
if [ $? -ne 0 ]; then
echo "Errors in configuration file, check with $prog check."
return 1
fi
echo -n $"Reloading $prog: "
$exec -D -f /etc/$prog/$prog.cfg -p /var/run/$prog.pid -sf $(cat /var/run/$prog.pid)
retval=$?
echo
return $retval
}
force_reload() {
restart
}

fdr_status() {
status $prog
}

case "$1" in
 start|stop|restart|reload)
 $1
 ;;
 force-reload)
 force_reload
 ;;
 check)
 check
 ;;
 status)
 fdr_status
 ;;
 condrestart|try-restart)
 [ ! -f $lockfile ] || restart
 ;;
 *)
 echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
 exit 2
esac

für systemd muss die haproxy.service nach /usr/lib/systemd/system gelegt werden

[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target

[Service]
EnvironmentFile=/etc/sysconfig/haproxy
ExecStart=/opt/haproxy/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS
ExecReload=/bin/kill -USR2 $MAINPID

[Install]
WantedBy=multi-user.target

und um flexibel zu sein /etc/sysconfig/haproxy

# Add extra options to the haproxy daemon here. This can be useful for
# specifying multiple configuration files with multiple -f options.
# See haproxy(1) for a complete list of options.
OPTIONS=""

Pfade anpassen nicht vergessen