today I needed installing
haproxy on my
The first thing I did was just
brew install haproxy.
While there is already an
haproxy formula, this one doesn’t come with
lua support (you can check that with
If you want to have
lua, here’s a snippet that you can use.
To install HAProxy from source on a Mac, all we need to do is gather the source code from the official website, “untar” it and then start the compilation using a set of flags that will allow us to build with the proper Lua support.
Aiming at Lua 5.3, it’s required that you first install it (you can use brew for this:
brew install email@example.com).
Before performing the compilation, make sure you change the
Makefile at the root of the source code and remove the
diff --git a/Makefile b/Makefile index 2acf5028..e65fda39 100644 --- a/Makefile +++ b/Makefile @@ -630,7 +630,7 @@ check_lua_inc = $(shell if [ -d $(2)$(1) ]; then echo $(2)$(1); fi;) BUILD_OPTIONS += $(call ignore_implicit,USE_LUA) OPTIONS_CFLAGS += -DUSE_LUA $(if $(LUA_INC),-I$(LUA_INC)) -LUA_LD_FLAGS := -Wl,--export-dynamic $(if $(LUA_LIB),-L$(LUA_LIB)) +LUA_LD_FLAGS := -Wl, $(if $(LUA_LIB),-L$(LUA_LIB)) ifeq ($(LUA_LIB_NAME),) # Try to automatically detect the Lua library LUA_LIB_NAME := $(firstword $(foreach lib,lua5.3 lua53 lua,$(call check_lua_lib,$(lib),$(LUA_LD_FLAGS))))
With that flag set you’ll not be able to build it on a Mac.
Having that done, proceed:
# Set the version that we want to get the source VERSION=1.7.9 # Create a directory that will hold the source files for a given haproxy # version. mkdir -p haproxy # grab the haproxy source from their website wget http://www.haproxy.org/download/1.7/src/haproxy-$VERSION.tar.gz tar xzf haproxy-$VERSION.tar.gz cd haproxy-$VERSION # build the source code. # for doing this you must at least have a recent C compiler make -j6 \ TARGET=osx \ USE_KQUEUE=1 \ USE_POLL=1 \ USE_PCRE=1 \ USE_THREAD=1 \ USE_OPENSSL=1 \ USE_ZLIB=1 \ USE_LUA=1 \ LUA_LIB=/usr/local/lib/ \ LUA_INC=/usr/local/include \ SSL_LIB=/usr/local/opt/openssl/lib \ SSL_INC=/usr/local/opt/openssl/include \ ADDLIB=-lcrypto # Check if everything was correctly installed. ./haproxy -vvvv HA-Proxy version 1.7.9 2017/08/18 .. OPTIONS = USE_ZLIB=1 USE_POLL=1 USE_KQUEUE=1 USE_OPENSSL=1 USE_LUA=1 USE_PCRE=1 ... Built with Lua version : Lua 5.3.4 ... # link it to `/usr/local/bin/haproxy` (which is in my $PATH) so I # can access it directly from `cli` ln -s $(realpath haproxy) /usr/local/bin/haproxy
Now you should have the binary ready to be used.
If you want to know how to get TLS certificates with LetsEncrypt and HAProxy, make sure you check a blog post I wrote about the topic: Getting TLS certificates with Letsencrypt and HAProxy.
Have a good one!