haproxy安装和配置
从官方网站:http://www.haproxy.org 下载最新版本。
然后,解压文件并进行安装:
安装完毕后,进入安装目录创建配置文件
配置如下:
启动服务:
重启服务:
停止服务:
当然,为了方便系统在开机时加载,还可以创建启动脚本:
# vim /etc/rc.d/init.d/haproxy 内容如下:
#! /bin/sh
set -e
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/haproxy/sbin
PROGDIR=/usr/local/haproxy
PROGNAME=haproxy
DAEMON=$PROGDIR/sbin/$PROGNAME
CONFIG=$PROGDIR/conf/$PROGNAME.conf
PIDFILE=$PROGDIR/run/$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 $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
保存,给予可执行权限
就可以使用 service haproxy start|stop|restart 来控制服务的启动停止跟重启。
并通过以下命令加载到开机服务启动列表
配置日志:
# vim /etc/syslog.conf
在最下边增加
重启核心日志服务使配置起效
然后就可查看日志了
# tail –f /var/log/harpoxy.log
Aug 22 15:32:06 localhost haproxy[64136]: Proxy www started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy cherokee started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy wap started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy pic started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy img started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy public started.
Aug 22 15:32:06 localhost haproxy[64136]: Proxy public started.
Aug 22 15:32:59 localhost haproxy[64137]: 219.142.128.30:6416 [22/Aug/2009:15:32:59.754] public stats/ 0/-1/-1/-1/0 200 17329 – - PR– 0/0/0/0/0 0/0 “GET /?stats HTTP/1.1″
Aug 22 15:32:59 localhost haproxy[64137]: 219.142.128.30:6416 [22/Aug/2009:15:32:59.754] public stats/ 0/-1/-1/-1/0 200 17329 – - PR– 0/0/0/0/0 0/0 “GET /?stats HTTP/1.1″