1、tar zxvf
2、cd haproxy
3、make TARGET=linux26 ARCH=x86_64 PREFIX=/usr/local/app/haproxy/
4、make install PREFIX=/usr/local/app/haproxy
5、cp /tmp/haproxy-1.5.4/examples/haproxy.cfg /usr/local/app/haproxy/
6、vim /usr/local/app/haproxy.cfg
内容详见隔壁文本文件haproxy配置。
如果报错:/haproxy.main()] Cannot chroot(/usr/share/haproxy)
手动新建:mkdir /usr/share/haproxy
##错误文件复制:mv /tmp/haproxy-1.5.14/examples/errorfiles/* /usr/share/haproxy/
日志配置:
log 127.0.0.1 local0 info
vim /etc/rsyslog.conf
local0.* /mnt/app/haproxy/logs/haproxy.log
7、启动 /usr/local/app/haproxy/sbin/haproxy -f /usr/local/app/haproxy/haproxy.cfg
8、停止服务:killall haproxy
9、开机自启动
haproxy启动脚本
vim /etc/init.d/haproxy
#!/bin/bash
BASE_DIR=”/usr/local/app/haproxy”
ARGV=”$@”
start()
{
echo “START HAPoxy SERVERS”
$BASE_DIR/sbin/haproxy -f $BASE_DIR/haproxy.cfg
}
stop()
{
echo “STOP HAPoxy Listen”
kill -TTOU $(cat $BASE_DIR/haproxy.pid)
echo “STOP HAPoxy process”
kill -USR1 $(cat $BASE_DIR/haproxy.pid)
}
case $ARGV in
start)
start
ERROR=$?
;;
stop)
stop
ERROR=$?
;;
restart)
stop
start
ERROR=$?
;;
*)
echo “hactl.sh [start|restart|stop]”
esac
exit $ERROR
chmod +x /etc/init.d/haproxy