Step1) Linux server has a development environment set up
yum
update
yum
-y groupinstall 'Development Tools'
Step 2) Download and uncompress haproxy
from source code.
tar
xzf haproxy-1.4.23.tar.gz
cd haproxy-1.4.23
make TARGET=linux26
step3) copy the configuration
files
mkdir
/etc/haproxy
cp haproxy /usr/sbin/haproxy
step 4) configure haproxy.cfg
file according to your need.
vi
/etc/haproxy.cfg
*********************
global
maxconn 4096
pidfile /var/run/haproxy.pid
daemon
defaults
log global
option dontlognull
balance leastconn
clitimeout 60000
srvtimeout 60000
contimeout 5000
retries 3
option redispatch
listen
exchange-http 10.10.3.156:80
mode http
stats enable
stats uri /haproxy-stats
balance source
option forwardfor
server cas1 10.10.3.145:80 check port 80
inter 20 rise 1 fall 1
server cas2 10.10.3.146:80 check port 80
inter 20 rise 1 fall 1 backup
listen
exchange-https-tr 10.10.3.156:444
mode tcp
balance source
maxconn 10000
server webserver1 10.10.3.145:444 check
port 444 inter 20 rise 1 fall 1
server webserver2 10.10.3.146:444 check
port 444 inter 20 rise 1 fall 1 backup
listen
exchange-https 10.10.3.156:443
mode tcp
balance source
maxconn 10000
server webserver1 10.10.3.145:443 check
port 443 inter 20 rise 1 fall 1
server webserver2 10.10.3.146:443 check
port 443 inter 20 rise 1 fall 1 backup
listen exchange-https 10.10.3.156:25
mode tcp
balance source
maxconn 10000
server webserver1
10.10.3.145:25 check port 25 inter 20 rise 1 fall 1
server webserver2
10.10.3.146:25 check port 25 inter 20 rise 1 fall 1 backup
Step 5)
Start HAproxy as daemon
/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg –d
Step 6) If
all goes well the create a init script for HAproxy
Vi /etc/init.d/haproxy
****************
#!/bin/sh
#
# chkconfig: - 85 15
# description: HA-Proxy is a TCP/HTTP
reverse proxy which is particularly suited \
# for high availability
environments.
# processname: haproxy
# config: /etc/haproxy/haproxy.cfg
# 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
}
reload() {
/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
/usr/sbin/$BASENAME -D -f /etc/$BASENAME/$BASENAME.cfg -p
/var/run/$BASENAME.pid -sf $(cat /var/run/$BASENAME.pid)
}
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)
reload
;;
condrestart)
condrestart
;;
status)
rhstatus
;;
check)
check
;;
*)
echo $"Usage: $BASENAME
{start|stop|restart|reload|condrestart|status|check}"
exit 1
esac
exit
$?
chmod 755 /etc/init.d/haproxy
service haproxy restart
chkconfig haproxy on
No comments:
Post a Comment