Skip to content

Instantly share code, notes, and snippets.

@jrouleau
Forked from ChrisMcKee/InstallHaProxy.sh
Last active February 1, 2022 00:34
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
  • Save jrouleau/e92da5d36304397302b6c5aedd8468c5 to your computer and use it in GitHub Desktop.
Save jrouleau/e92da5d36304397302b6c5aedd8468c5 to your computer and use it in GitHub Desktop.
Amazon Linux AMI Install HAProxy From Source (1.7.0 release pre configured). chmod +x InstallHaProxy.sh then ./InstallHaProxy.sh
#!/bin/bash
### VARIABLES ###
PRE_PACK="openssl-devel pcre-devel make gcc"
VER="1.7.0"
# Setup Colours
black='\E[30;40m'
red='\E[31;40m'
green='\E[32;40m'
yellow='\E[33;40m'
blue='\E[34;40m'
magenta='\E[35;40m'
cyan='\E[36;40m'
white='\E[37;40m'
boldblack='\E[1;30;40m'
boldred='\E[1;31;40m'
boldgreen='\E[1;32;40m'
boldyellow='\E[1;33;40m'
boldblue='\E[1;34;40m'
boldmagenta='\E[1;35;40m'
boldcyan='\E[1;36;40m'
boldwhite='\E[1;37;40m'
Reset="tput sgr0" # Reset text attributes to normal
#+ without clearing screen.
cecho () # Coloured-echo.
# Argument $1 = message
# Argument $2 = color
{
message=$1
color=$2
echo -e "$color$message" ; $Reset
return
}
cecho "Installing/upgrading your web server..." $boldgreen
yum -y -q install $PRE_PACK > /dev/null
mkdir -p /src
cd /src
wget -q http://www.haproxy.org/download/${VER%.*}/src/haproxy-$VER.tar.gz
tar xzf haproxy-$VER.tar.gz && rm -f haproxy*.tar.gz;
cd haproxy-$VER
cecho "Configuring and Making HAPROXY" $boldgreen
make TARGET=linux2628 USE_OPENSSL=1 USE_ZLIB=1 USE_PCRE=1 # compiles it with compression and ssl support
cecho "Installing HAPROXY" $boldgreen
make install
cecho "Adding HAProxy User" $boldyellow
id -u haproxy &>/dev/null || useradd -s /usr/sbin/nologin -r haproxy
cecho "Creating config and Adding Daemon" $boldgreen
cp /usr/local/sbin/haproxy* /usr/sbin/ # copy binaries to /usr/sbin
cp /src/haproxy-$VER/examples/haproxy.init /etc/init.d/haproxy # copy init script in /etc/init.d
chmod +x /etc/init.d/haproxy # setting permission on init script
mkdir -p /etc/haproxy # creating directory where the config file must reside
#cp -n /src/haproxy-$VER/examples/content-sw-sample.cfg /etc/haproxy/haproxy.cfg # copy example config file
cecho "checking config and starting service" $boldyellow
service haproxy check # checking configuration file is valid
service haproxy start # starting haproxy to verify it is working
chkconfig haproxy on # setting haproxy to start with VM
exit 0
@yaxhpal
Copy link

yaxhpal commented Jan 18, 2018

Thank you! It is very helpful

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