安装
wget
tar xzvf haproxy-1.3.20.tar.gz
mv haproxy-1.3.20 /usr/local/haproxy
cd /usr/local/haproxy/
make TARGET=linux26
make install
./haproxy -v
HA-Proxy version 1.3.20 2009/08/09
Copyright 2000-2009 Willy Tarreau
vim haproxy.cfg
global
log 127.0.0.1 local0
maxconn 4096
chroot /usr/local/haproxy
uid 99
gid 99
daemon
nbproc 10
pidfile /usr/local/haproxy/haproxy.pid
#debug
#quiet
defaults
log 127.0.0.1 local3
mode http
#mode tcp
option httplog
option httpclose
option dontlognull
option forwardfor
option redispatch
option originalto
option abortonclose
retries 2
maxconn 2000
balance roundrobin
#balance source
#balance leastconn
stats uri /haproxy-stats
stats auth admin:admin
stats refresh 5s
#stats hide-version
contimeout 5000
clitimeout 50000
srvtimeout 50000
#timeout check 2000
#set haproxy servers ip adress and port;
listen web_proxy 0.0.0.0:80
#set mode of balance
#balance source
#set haproxy servers check web servers status;
#option httpchk GET /check.php
#option httpchk HEAD /index.php
#set sticky sessions
cookie SERVERID insert indirect nocache
#cookie SERVERID rewrite
#set web servers ip address and port
server web1 192.168.1.77:80 cookie appinst1 check weight 1
server web2 192.168.1.78:80 cookie appinst2 check weight 1
#server web1 192.168.1.77:80 cookie app1inst1 check inter 2000 rise 2 fall 5
#server web2 192.168.1.78:80 cookie app1inst2 check inter 2000 rise 2 fall 5
#server web1 192.168.1.77:80 cookie web1 check
#server web2 192.168.1.78:80 cookie web2 check
/etc/init.d/
vim haproxy
#! /bin/sh
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/haproxy/sbin
PROGDIR=/usr/local/haproxy
PROGNAME=haproxy
DAEMON=$PROGDIR/$PROGNAME
CONFIG=$PROGDIR/$PROGNAME.cfg
PIDFILE=$PROGDIR/logs/$PROGNAME.pid
DESC="HAProxy daemon"
SCRIPTNAME=/etc/init.d/$PROGNAME
# Gracefully exit if the package has been removed.
test -x $DAEMON || exit 0
start()
{
echo -n "Starting $DESC: $PROGNAME"
$DAEMON -f $CONFIG
echo "."
}
stop()
{
echo -n "Stopping $DESC: $PROGNAME"
haproxy_pid=$(cat $PIDFILE)
kill -15 $haproxy_pid
echo "."
}
restart()
{
echo -n "Restarting $DESC: $PROGNAME"
$DAEMON -f $CONFIG -p $PIDFILE -sf $(cat $PIDFILE)
echo "."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart}" >&2
exit 1
;;
esac
exit 0
阅读(1553) | 评论(0) | 转发(1) |