Skip to content

Instantly share code, notes, and snippets.

@meanevo
Forked from ryzy/a.sh
Last active October 25, 2022 07:42
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 17 You must be signed in to fork a gist
  • Save meanevo/742b61031fdf9ce01e50d4b196a3f31e to your computer and use it in GitHub Desktop.
Save meanevo/742b61031fdf9ce01e50d4b196a3f31e to your computer and use it in GitHub Desktop.
Compile HAProxy from source on CentOS 7
# Make sure you have these installed
yum install -y make gcc perl pcre-devel zlib-devel
# Download/Extract source
wget -O /tmp/haproxy.tgz http://www.haproxy.org/download/1.7/src/haproxy-1.7.2.tar.gz
tar -zxvf /tmp/haproxy.tgz -C /tmp
cd /tmp/haproxy-*
# Compile HAProxy
# https://github.com/haproxy/haproxy/blob/master/README
make \
TARGET=linux2628 USE_LINUX_TPROXY=1 USE_ZLIB=1 USE_REGPARM=1 USE_PCRE=1 USE_PCRE_JIT=1 \
USE_OPENSSL=1 SSL_INC=/usr/include SSL_LIB=/usr/lib ADDLIB=-ldl \
CFLAGS="-O2 -g -fno-strict-aliasing -DTCP_USER_TIMEOUT=18"
make install
# Check your sbin path at /usr/local/sbin, consider copying these two to it
cp haproxy /usr/local/sbin/haproxy
cp haproxy-systemd-wrapper /usr/local/sbin/haproxy-systemd-wrapper
# File located at /etc/systemd/system/haproxy.service for CentOS 7
# Reference https://github.com/horms/haproxy/blob/master/contrib/systemd/haproxy.service.in
[Unit]
Description=HAProxy Load Balancer
After=network.target
[Service]
ExecStartPre=/usr/local/sbin/haproxy -f /etc/haproxy/haproxy.cfg -c -q
ExecStart=/usr/local/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
[Install]
WantedBy=multi-user.target
@rafi
Copy link

rafi commented Jun 21, 2018

You will also need openssl-devel before compiling.

@shoaibjdev
Copy link

For HAProxy 1.9

[Unit]
Description=HAProxy Load Balancer
After=network.target

[Service]
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid"
ExecStartPre=/usr/local/sbin//haproxy -f $CONFIG -c -q
ExecStart=/usr/local/sbin//haproxy -Ws -f $CONFIG -p $PIDFILE
ExecReload=/usr/local/sbin//haproxy -f $CONFIG -c -q
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
SuccessExitStatus=143
Type=notify

[Install]
WantedBy=multi-user.target

@michaelsstuff
Copy link

Target 'linux2628' was removed from HAProxy 2.0 due to being irrelevant and
often wrong. Please use 'linux-glibc' instead

@gummiost
Copy link

gummiost commented Aug 6, 2020

Works on HAproxy 2.2

File located at /etc/systemd/system/haproxy.service for CentOS 7

[Unit]
Description=HAProxy Load Balancer
After=network.target

[Service]
Environment="CONFIG=/etc/haproxy/haproxy.cfg" "PIDFILE=/run/haproxy.pid"
ExecStartPre=/usr/local/sbin/haproxy -f $CONFIG -c -q
ExecStart=/usr/local/sbin/haproxy -Ws -f $CONFIG -p $PIDFILE
ExecReload=/usr/local/sbin/haproxy -f $CONFIG -c -q
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed
Restart=always
SuccessExitStatus=143
Type=notify

[Install]
WantedBy=multi-user.target

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment