环境设置
yum groupinstall -y "Development tools"
解压haproxy1.7.4
tar -zxf haproxy-1.7.4.tar.gz -C /usr/local/
编译安装haproxy
cdhaproxy-1.7.4
make TARGET=linux26 ARCH=X86_64 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
创建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
BIN=/usr/local/haproxy/sbin/haproxy
CFG=/usr/local/haproxy/haproxy.cfg
[ -f $CFG ] || exit 1
PIDFILE=/var/run/$BASENAME.pid
LOCKFILE=/var/lock/subsys/$BASENAME
RETVAL=0
start() {
quiet_check
if [ $? -ne 0 ]; then
echo "Errors found in configuration file,check it with '$BASENAME check'."
return 1
fi
echo -n "Starting $BASENAME: "
daemon $BIN -D -f $CFG -p $PIDFILE
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCKFILE
return $RETVAL
}
stop() {
echo -n "Shutting down $BASENAME: "
killproc $BASENAME -USR1
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LOCKFILE
[ $RETVAL -eq 0 ] && rm -f $PIDFILE
return $RETVAL
}
restart() {
quiet_check
if [ $? -ne 0 ]; then
echo "Errors found in configuration file,check it with '$BASENAME check'."
return 1
fi
5. 创建haproxy配置文件
vi /usr/local/haproxy/haproxy.cfg
#
# demo config for Proxy mode
#
global
log 127.0.0.1 local0 info #[err warning info debug]
maxconn 4096
daemon
nbproc 1
defaults
mode http
option httplog
retries 3
option redispatch
option abortonclose
maxconn 4096
contimeout 5000
clitimeout 30000
srvtimeout 30000
timeout check 2000
frontend httpfrontend
bind 0.0.0.0:80
option httplog
log 127.0.0.1 local2 info
chkconfig --add haproxy
chkconfig --level 2345 haproxy on
6. chmod 755 /etc/init.d/haproxy
systemctl start haproxy
7. 检查80,10050的端口是否打开
ss -tnl
原文链接:https://www.f2er.com/centos/377993.html