Skip to content

Instantly share code, notes, and snippets.

@ChrisMcKee
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChrisMcKee/9616818 to your computer and use it in GitHub Desktop.
Save ChrisMcKee/9616818 to your computer and use it in GitHub Desktop.
Install HA Proxy 1.5 Dev on CentOS ; Source for installs/versions http://haproxy.1wt.eu/download/1.5/src/devel/
#!/bin/bash
### VARIABLES ###
PRE_PACK="openssl-devel pcre-devel make gcc"
VER="1.5-dev22"
# 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
}
clear
cecho "Installing/upgrading your web server..." $boldgreen
yum -y -q install $PRE_PACK > /dev/null
mkdir -p /src
cd /src
wget -q http://haproxy.1wt.eu/download/1.5/src/devel/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 CPU=x86_64 USE_OPENSSL=1 USE_ZLIB=1 USE_PCRE=1 # compiles it with compression and ssl support; use CPU=x86_64 for CentOS x64 or i686 where approriate
cecho "Installing HAPROXY" $boldgreen
make install
cecho "Adding HAProxy User" $boldyellow
id -u haproxy &>/dev/null || useradd -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 /src/haproxy-$VER/examples/examples.cfg /etc/haproxy/haproxy.cfg # copy example config file
mkdir -p /var/lib/haproxy # create directory for stats file
touch /var/lib/haproxy/stats # creating stats 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment