blob: d6d786b08894bfae21383fa6a3fcf3bd63c082b1 [file] [log] [blame]
Willy Tarreau7f332732018-12-16 22:27:15 +01001Installation instructions for HAProxy
2=====================================
3
Willy Tarreau4bc567c2019-06-15 19:07:54 +02004HAProxy 2.0 is a long-term supported stable version, which means that it will
5get fixes for bugs as they are discovered during several years and will not
6receive new features. Versions which include the suffix "-dev" are development
7versions and should be avoided in production. If you are not used to build from
8sources or if you are not used to follow updates then it is recommended that
9instead you use the packages provided by your software vendor or Linux
10distribution. Most of them are taking this task seriously and are doing a good
11job at backporting important fixes. If for any reason you'd prefer a different
12version than the one packaged for your system, you want to be certain to have
13all the fixes or to get some commercial support, other choices are available
14at http://www.haproxy.com/.
Willy Tarreau7f332732018-12-16 22:27:15 +010015
16
17Areas covered in this document
18==============================
19
201) Quick build & install
212) Basic principles
223) Build environment
234) Dependencies
245) Advanced build options
256) How to install HAProxy
26
27
281) Quick build & install
29========================
30
31If you've already built HAProxy and are just looking for a quick reminder, here
32are a few build examples :
33
34 - recent Linux system with all options, make and install :
35 $ make clean
Willy Tarreaud254aa82019-06-14 18:40:48 +020036 $ make -j $(nproc) TARGET=linux-glibc \
Willy Tarreau7f332732018-12-16 22:27:15 +010037 USE_OPENSSL=1 USE_ZLIB=1 USE_LUA=1 USE_PCRE=1 USE_SYSTEMD=1
38 $ sudo make install
39
40 - FreeBSD and OpenBSD, build with all options :
41 $ gmake -j 4 TARGET=freebsd USE_OPENSSL=1 USE_ZLIB=1 USE_LUA=1 USE_PCRE=1
42
43 - embedded Linux, build using a cross-compiler :
Willy Tarreaud254aa82019-06-14 18:40:48 +020044 $ make -j $(nproc) TARGET=linux-glibc USE_OPENSSL=1 USE_SLZ=1 USE_PCRE=1 \
45 CC=/opt/cross/gcc730-arm/bin/gcc ADDLIB=-latomic
Willy Tarreau7f332732018-12-16 22:27:15 +010046
47 - Build with static PCRE on Solaris / UltraSPARC :
48 $ make TARGET=solaris CPU=ultrasparc USE_STATIC_PCRE=1
49
50For more advanced build options or if a command above reports an error, please
51read the following sections.
52
53
542) Basic principles
55===================
56
57HAProxy uses a single GNU Makefile which supports options on the command line,
58so that there is no need to hack a "configure" file to work on your system. The
59makefile totally supports parallel build using "make -j <jobs>" where <jobs>
60matches the number of usable processors, which on some platforms is returned by
61the "nproc" utility. The explanations below may occasionally refer to some
62options, usually in the form "name=value", which have to be passed to the
63command line. This means that the option has to be passed after the "make"
64command. For example :
65
66 $ make -j $(nproc) TARGET=generic USE_GZIP=1
67
68One required option is TARGET, it must be set to a target platform name, which
69provides a number of presets. The list of known platforms is displayed when no
70target is specified. It is not strictly required to use the exact target, you
71can use a relatively similar one and adjust specific variables by hand.
72
73Most configuration variables are in fact booleans. Some options are detected and
74enabled by default if available on the target platform. This is the case for all
75those named "USE_<feature>". These booleans are enabled by "USE_<feature>=1"
76and are disabled by "USE_<feature>=" (with no value). The last occurrence on the
77command line overrides any previous one. Example :
78
79 $ make TARGET=generic USE_THREAD=
80
81In case of error or missing TARGET, a help screen is displayed. It is also
82possible to display a list of all known options using "make help".
83
84
853) Build environment
86====================
87
88HAProxy requires a working GCC or Clang toolchain and GNU make :
89
90 - GNU make >= 3.80. Note that neither Solaris nor OpenBSD's make work with
91 the GNU Makefile. If you get many syntax errors when running "make", you
92 may want to retry with "gmake" which is the name commonly used for GNU make
93 on BSD systems.
94
95 - GCC >= 3.4 (up to 8.1 tested). Older versions can be made to work with a
96 few minor adaptations if really needed. Newer versions may sometimes break
97 due to compiler regressions or behaviour changes. The version shipped with
98 your operating system is very likely to work with no trouble. Clang >= 3.0
99 is also known to work as an alternative solution. Recent versions may emit
100 a bit more warnings that are worth reporting.
101
102 - GNU ld (binutils package), with no particular version. Other linkers might
103 work but were not tested.
104
105On debian or Ubuntu systems and their derivatives, you may get all these tools
106at once by issuing the two following commands :
107
108 $ sudo apt-get update
109 $ sudo apt-get install build-essential
110
111On Fedora, CentOS, RHEL and derivatives, you may get the equivalent packages
112with the following command :
113
114 $ sudo yum groupinstall "Development Tools"
115
116Please refer to your operating system's documentation for other systems.
117
118It is also possible to build HAProxy for another system or platform using a
119cross-compiler but in this case you probably already have installed these
120tools.
121
122Building HAProxy may require between 10 and 40 MB of free space in the
123directory where the sources have been extracted, depending on the debugging
124options involved.
125
126
1274) Dependencies
128===============
129
130HAProxy in its basic form does not depend on anything beyond a working libc.
131However a number of options are enabled by default, or are highly recommended,
132and these options will typically involve some external components or libraries,
133depending on the targetted platform.
134
135Optional dependencies may be split into several categories :
136
137 - memory allocation
138 - regular expressions
139 - multi-threading
140 - password encryption
141 - cryptography
142 - compression
143 - lua
144 - device detection
145 - miscellaneous
146
147
1484.1) Memory allocation
149----------------------
150By default, HAProxy uses the standard malloc() call provided by the libc. It
Willy Tarreauc3643512019-03-27 14:20:43 +0100151may also be built to use jemalloc, which is fast and thread-safe. In order to
152use it, please add "-ljemalloc" to the ADDLIB variable. You may possibly also
153need to append "-lpthread" and/or "-ldl" depending on the operating system.
Willy Tarreau7f332732018-12-16 22:27:15 +0100154
155
1564.2) Regular expressions
157------------------------
158HAProxy may make use regular expressions (regex) to match certain patterns. The
159regex engine is provided by default in the libc. On some operating systems, it
160might happen that the original regex library provided by the libc is too slow,
161too limited or even bogus. For example, on older Solaris versions up to 8, the
162default regex used not to properly extract group references, without reporting
163compilation errors. Also, some early versions of the GNU libc used to include a
164regex engine which could be slow or even crash on certain patterns.
165
166If you plan on importing a particularly heavy configuration involving a lot of
167regex, you may benefit from using some alternative regex implementations sur as
168PCRE. HAProxy natively supports PCRE and PCRE2, both in standard and JIT
169flavors (Just In Time). The following options are available depending on the
170library version provided on your system :
171
172 - "USE_PCRE=1" : enable PCRE version 1, dynamic linking
173 - "USE_STATIC_PCRE=1" : enable PCRE version 1, static linking
174 - "USE_PCRE_JIT=1" : enable PCRE version 1 in JIT mode
175 - "USE_PCRE2=1" : enable PCRE version 2, dynamic linking
176 - "USE_STATIC_PCRE2=1" : enable PCRE version 2, static linking
177 - "USE_PCRE2_JIT=1" : enable PCRE version 2 in JIT mode
178
179Both of these libraries may be downloaded from https://www.pcre.org/.
180
181By default, the include and library paths are figured from the "pcre-config"
182and "pcre2-config" utilities. If these ones are not installed or inaccurate
183(for example when cross-compiling), it is possible to force the path to include
184files using "PCRE_INC" and "PCRE2_INC" respectively, and the path to library
185files using "PCRE_LIB" and "PCRE2_LIB" respectively. For example :
186
187 $ make TARGET=generic \
188 USE_PCRE2_JIT=1 PCRE2_INC=/opt/cross/include PCRE2_LIB=/opt/cross/lib
189
190
1914.3) Multi-threading
192--------------------
193On some systems for which positive feedback was reported, multi-threading will
194be enabled by default. When multi-threading is used, the libpthread library
195(POSIX threading) will be used. If the target system doesn't contain such a
196library, it is possible to forcefully disable multi-threading by adding
197"USE_THREAD=" on the command line.
198
199
2004.4) Password encryption
201------------------------
202Many systems provide password encryption functions used for authentication. On
203some systems these functions are part of the libc. On others, they're part of a
204separate library called "libcrypt". The default targets are pre-configured
205based on which system needs the library. It is possible to forcefully disable
206the linkage against libcrypt by adding "USE_LIBCRYPT=" on the command line, or
207to forcefully enable it using "USE_LIBCRYPT=1".
208
209
2104.5) Cryptography
211-----------------
212For SSL/TLS, it is necessary to use a cryptography library. HAProxy currently
213supports the OpenSSL library, and is known to build ant work with branches
2140.9.8, 1.0.0, 1.0.1, 1.0.2, 1.1.0 and 1.1.1. OpenSSL follows a long-term
215support cycle similar to HAProxy's, and each of the branches above receives its
216own fixes, without forcing you to upgrade to another branch. There is no excuse
217for staying vulnerable by not applying a fix available for your version. There
218is always a small risk of regression when jumping from one branch to another
219one, especially when it's very new, so it's preferable to observe for a while
220if you use a different version than your system's defaults.
221
222Two OpenSSL derivatives called LibreSSL and BoringSSL are reported to work as
223well. While there are some efforts from the community to ensure they work well,
224OpenSSL remains the primary target and this means that in case of conflicting
225choices, OpenSSL support will be favored over other options.
226
227In order to enable SSL/TLS support, simply pass "USE_OPENSSL=1" on the command
228line and the default library present on your system will be used :
229
230 $ make TARGET=generic USE_OPENSSL=1
231
232If you want to use a different version from the one provided by your system
233(which is not recommended due to the risk of missing security fixes), it is
234possible to indicate the path to the SSL include files using SSL_INC, and the
235SSL library files using SSL_LIB. Example :
236
237 $ make TARGET=generic \
238 USE_OPENSSL=1 SSL_INC=/opt/ssl-1.1.1/include SSL_LIB=/opt/ssl-1.1.1/lib
239
240In order to link OpenSSL statically against HAProxy, first download OpenSSL
241from https://www.openssl.org/ then build it with the "no-shared" keyword and
242install it to a local directory, so your system is not affected :
243
244 $ export STATICLIBSSL=/tmp/staticlibssl
245 $ ./config --prefix=$STATICLIBSSL no-shared
246 $ make && make install_sw
247
248Then when building haproxy, pass that path via SSL_INC and SSL_LIB :
249
250 $ make TARGET=generic \
251 USE_OPENSSL=1 SSL_INC=$STATICLIBSSL/include SSL_LIB=$STATICLIBSSL/lib
252
253When building with OpenSSL on some systems, you may also need to enable support
254for the "libz" library, which is visible if the linker complains about function
255"deflateInit()" not being found. In this case, simply append "ADDLIB=-lz" to
256the command line.
257
258It is worth mentioning that asynchronous cryptography engines are supported on
259OpenSSL 1.1.0 and above. Such engines are used to access hardware cryptography
260acceleration that might be present on your system.
261
262
2634.6) Compression
264----------------
265HAProxy can compress HTTP responses before delivering them to clients, in order
266to save network bandwidth. Two compression options are available. The first one
267involves the widely known zlib library, which is very likely installed on your
268system. In order to use zlib, simply pass "USE_ZLIB=1" to the command line. If
269the library is not installed in your default system's path, it is possible to
270specify the path to the include files using ZLIB_INC, and the path to the
271library files using ZLIB_LIB :
272
273 $ make TARGET=generic \
274 USE_ZLIB=1 ZLIB_INC=/opt/zlib-1.2.11/include ZLIB_LIB=/opt/zlib-1.2.11/lib
275
276However, zlib maintains an in-memory context for each compressed stream, which
277is not always welcome when dealing with large sites. An alternative solution is
278to use libslz instead, which doesn't consume memory, which is much faster, but
279compresses slightly less efficiently. For this, please use "USE_SLZ=1", and
280optionally make "SLZ_INC" and "SLZ_LIB" point to the library's include and
281library paths, respectively.
282
283Zlib is commonly found on most systems, otherwise updates can be retrieved from
284http://www.zlib.net/. It is easy and fast to build, and new versions sometimes
285provide better performance so it might be worth using an up-to-date one. Libslz
286can be downloaded http://libslz.org/ and is even easier to build.
287
288
2894.7) Lua
290--------
291Lua is an embedded programming langage supported by HAProxy to provide more
292advanced scripting capabilities. Only versions 5.3 and above are supported.
293In order to enable Lua support, please specify "USE_LUA=1" on the command line.
294Some systems provide this library under various names to avoid conflicts with
295previous versions. By default, HAProxy looks for "lua5.3", "lua53", "lua". If
296your system uses a different naming, you may need to set the library name in
297the "LUA_LIB_NAME" variable.
298
299If Lua is not provided on your system, it can be very simply built locally. It
300can be downloaded from https://www.lua.org/, extracted and built, for example :
301
302 $ cd /opt/lua-5.3.5
303 $ make linux
304
305The path to the include files and library files may be set using "LUA_INC" and
306"LUA_LIB" respectively. For example :
307
308 $ make TARGET=generic \
309 USE_LUA=1 LUA_INC=/opt/lua-5.3.5/src LUA_LIB=/opt/lua-5.3.5/src
310
311
3124.8) Device detection
313---------------------
314HAProxy supports several device detection modules relying on third party
315products. Some of them may provide free code, others free libs, others free
316evaluation licenses. Please read about their respective details in the
317following files :
318
319 doc/DeviceAtlas-device-detection.txt for DeviceAtlas
320 doc/51Degrees-device-detection.txt for 51Degrees
Willy Tarreaub3cc9f22019-04-19 16:03:32 +0200321 doc/WURFL-device-detection.txt for Scientiamobile WURFL
Willy Tarreau7f332732018-12-16 22:27:15 +0100322
323
3244.9) Miscellaneous
325------------------
326Some systems have specificities. Usually these specificities are known and/or
327detected and properly set for you. If you need to adjust the behaviour, here
328are the extra libraries that may be referenced at build time :
329
330 - USE_RT=1 build with librt, which is sometimes needed on some systems
331 when using threads. It is set by default on Linux platforms,
332 and may be disabled using "USE_RT=" if your system doesn't
Willy Tarreau4703fdd2019-06-16 19:39:44 +0200333 have one. You may have to set it as well if you face an error
334 indicating that clock_gettime() was not found.
Willy Tarreau7f332732018-12-16 22:27:15 +0100335
336 - USE_DL=1 build with libdl, which is usually needed for Lua and OpenSSL
337 on Linux. It is automatically detected and may be disabled
338 using "USE_DL=", though it should never harm.
339
340 - USE_SYSTEMD=1 enables support for the sdnotify features of systemd,
341 allowing better integration with systemd on Linux systems
342 which come with it. It is never enabled by default so there
343 is no need to disable it.
344
Willy Tarreau4703fdd2019-06-16 19:39:44 +02003454.10) Common errors
346-------------------
347Some build errors may happen depending on the options combinations or the
348selected target. When facing build errors, if you know that your system is a
349bit special or particularly old, start from TARGET=generic, it is easier to
350start from there and fix the remaining issues than trying to degrade another
351target. Common issues may include:
352
353 - clock_gettime() not found
354 => your system needs USE_RT=1
355
356 - __sync_sub_and_fetch undefined in cache.o
357 => your system needs either USE_PTHREAD_PSHARED=1 or USE_PRIVATE_CACHE=1
358
359 - many __sync_<something> errors in many files
360 => your gcc is too old, build without threads and with private cache.
361
362 - many openssl errors
363 => your OpenSSL version really is too old, do not enable OpenSSL
364
Willy Tarreau7f332732018-12-16 22:27:15 +0100365
3665) How to build HAProxy
367=======================
368
369This section assumes that you have already read section 2 (basic principles)
370and section 3 (build environment). It often refers to section 4 (dependencies).
371
372To build haproxy, you have to choose your target OS amongst the following ones
373and assign it to the TARGET variable :
374
Willy Tarreaud254aa82019-06-14 18:40:48 +0200375 - linux-glibc for Linux kernel 2.6.28 and above
Willy Tarreau7f332732018-12-16 22:27:15 +0100376 - solaris for Solaris 8 or 10 (others untested)
377 - freebsd for FreeBSD 5 to 12 (others untested)
378 - netbsd for NetBSD
379 - osx for Mac OS/X
380 - openbsd for OpenBSD 5.7 and above
381 - aix51 for AIX 5.1
382 - aix52 for AIX 5.2
383 - cygwin for Cygwin
384 - haiku for Haiku
385 - generic for any other OS or version.
386 - custom to manually adjust every setting
387
388You may also choose your CPU to benefit from some optimizations. This is
389particularly important on UltraSparc machines. For this, you can assign
390one of the following choices to the CPU variable :
391
392 - i686 for intel PentiumPro, Pentium 2 and above, AMD Athlon (32 bits)
393 - i586 for intel Pentium, AMD K6, VIA C3.
394 - ultrasparc : Sun UltraSparc I/II/III/IV processor
395 - native : use the build machine's specific processor optimizations. Use with
396 extreme care, and never in virtualized environments (known to break).
397 - generic : any other processor or no CPU-specific optimization. (default)
398
399Alternatively, you may just set the CPU_CFLAGS value to the optimal GCC options
400for your platform. A second variable named SMALL_OPTS also supports passing a
401number of defines and compiler options usually for small systems. For better
402clarity it's recommended to pass the options which result in a smaller binary
403(like memory limits or -Os) into this variable.
404
405If you are building for a different system than the one you're building on,
406this is called "cross-compiling". HAProxy supports cross-compilation pretty
407well and tries to ease it by letting you adjust paths to all libraries (please
408read section 4 on dependencies for more details). When cross-compiling, you
409just need to pass the path to your compiler in the "CC" variable, and the path
410to the linker in the "LD" variable. Most of the time, setting the CC variable
411is enough since LD points to it by default.
412
413By default the build process runs in quiet mode and hide the details of the
414commands that are executed. This allows to more easily catch build warnings
415and see what is happening. However it is not convenient at all to observe what
416flags are passed to the compiler nor what compiler is involved. Simply append
417"V=1" to the "make" command line to switch to verbose mode and display the
418details again. It is recommended to use this option when cross-compiling to
419verify that the paths are correct and that /usr/include is never invovled.
420
421You may want to build specific target binaries which do not match your native
422compiler's target. This is particularly true on 64-bit systems when you want
423to build a 32-bit binary. Use the ARCH variable for this purpose. Right now
424it only knows about a few x86 variants (i386,i486,i586,i686,x86_64), two
425generic ones (32,64) and sets -m32/-m64 as well as -march=<arch> accordingly.
426This variable is only used to set ARCH_FLAGS to preset values, so if you know
427the arch-specific flags that your system needs, you may prefer to set
428ARCH_FLAGS instead. Note that these flags are passed both to the compiler and
429to the linker. For example, in order to build a 32-bit binary on an x86_64
430Linux system with SSL support without support for compression but when OpenSSL
431requires ZLIB anyway :
432
Willy Tarreaud254aa82019-06-14 18:40:48 +0200433 $ make TARGET=linux-glibc ARCH=i386 USE_OPENSSL=1 ADDLIB=-lz
Willy Tarreau7f332732018-12-16 22:27:15 +0100434
435Recent systems can resolve IPv6 host names using getaddrinfo(). This primitive
436is not present in all libcs and does not work in all of them either. Support in
437glibc was broken before 2.3. Some embedded libs may not properly work either,
438thus, support is disabled by default, meaning that some host names which only
439resolve as IPv6 addresses will not resolve and configs might emit an error
440during parsing. If you know that your OS libc has reliable support for
441getaddrinfo(), you can add USE_GETADDRINFO=1 on the make command line to enable
442it. This is the recommended option for most Linux distro packagers since it's
443working fine on all recent mainstream distros. It is automatically enabled on
444Solaris 8 and above, as it's known to work.
445
446If your system supports PCRE (Perl Compatible Regular Expressions), then you
447really should build with libpcre which is between 2 and 10 times faster than
448other libc implementations. Regex are used for header processing (deletion,
449rewriting, allow, deny). Please see section 4 about dependencies to figure
450how to build with PCRE support.
451
452It is possible to add native support for SSL, by passing "USE_OPENSSL=1" on the
453make command line. The libssl and libcrypto will automatically be linked with
454HAProxy. Some systems also require libz, so if the build fails due to missing
455symbols such as deflateInit(), then try again with "ADDLIB=-lz". Please check
456section 4 about dependencies for more information on how to build with OpenSSL.
457
458HAProxy can compress HTTP responses to save bandwidth. Please see section 4
459about dependencies to see the available libraries and associated options.
460
461By default, the DEBUG variable is set to '-g' to enable debug symbols. It is
462not wise to disable it on uncommon systems, because it's often the only way to
463get a usable core when you need one. Otherwise, you can set DEBUG to '-s' to
464strip the binary.
465
466If the ERR variable is set to any non-empty value, then -Werror will be added
467to the compiler so that any build warning will trigger an error. This is the
468recommended way to build when developing, and it is expected that contributed
469patches were tested with ERR=1.
470
471The SSL stack supports session cache synchronization between all running
472processes. This involves some atomic operations and synchronization operations
473which come in multiple flavors depending on the system and architecture :
474
475 Atomic operations :
476 - internal assembler versions for x86/x86_64 architectures
477
478 - gcc builtins for other architectures. Some architectures might not
479 be fully supported or might require a more recent version of gcc.
480 If your architecture is not supported, you willy have to either use
481 pthread if supported, or to disable the shared cache.
482
483 - pthread (posix threads). Pthreads are very common but inter-process
484 support is not that common, and some older operating systems did not
485 report an error when enabling multi-process mode, so they used to
486 silently fail, possibly causing crashes. Linux's implementation is
487 fine. OpenBSD doesn't support them and doesn't build. FreeBSD 9 builds
488 and reports an error at runtime, while certain older versions might
489 silently fail. Pthreads are enabled using USE_PTHREAD_PSHARED=1.
490
491 Synchronization operations :
492 - internal spinlock : this mode is OS-independent, light but will not
493 scale well to many processes. However, accesses to the session cache
494 are rare enough that this mode could certainly always be used. This
495 is the default mode.
496
497 - Futexes, which are Linux-specific highly scalable light weight mutexes
498 implemented in user-space with some limited assistance from the kernel.
499 This is the default on Linux 2.6 and above and is enabled by passing
500 USE_FUTEX=1
501
502 - pthread (posix threads). See above.
503
504If none of these mechanisms is supported by your platform, you may need to
505build with USE_PRIVATE_CACHE=1 to totally disable SSL cache sharing. Then it
506is better not to run SSL on multiple processes. Note that you don't need these
507features if you only intend to use multi-threading and never multi-process.
508
509If you need to pass other defines, includes, libraries, etc... then please
510check the Makefile to see which ones will be available in your case, and
511use/override the USE_* variables from the Makefile.
512
513AIX 5.3 is known to work with the generic target. However, for the binary to
514also run on 5.2 or earlier, you need to build with DEFINE="-D_MSGQSUPPORT",
515otherwise __fd_select() will be used while not being present in the libc, but
516this is easily addressed using the "aix52" target. If you get build errors
517because of strange symbols or section mismatches, simply remove -g from
518DEBUG_CFLAGS.
519
520You can easily define your own target with the GNU Makefile. Unknown targets
521are processed with no default option except USE_POLL=default. So you can very
522well use that property to define your own set of options. USE_POLL can even be
523disabled by setting USE_POLL="". For example :
524
525 $ gmake TARGET=tiny USE_POLL="" TARGET_CFLAGS=-fomit-frame-pointer
526
527If you need to pass some defines to the preprocessor or compiler, you may pass
528them all in the DEFINE variable. Example:
529
530 $ make TARGET=generic DEFINE="-DDEBUG_DONT_SHARE_POOLS -DDEBUG_MEMORY_POOLS"
531
532The ADDINC variable may be used to add some extra include paths; this is
533sometimes needed when cross-compiling. Similarly the ADDLIB variable may be
534used to specifify extra paths to library files. Example :
535
536 $ make TARGET=generic ADDINC=-I/opt/cross/include ADDLIB=-L/opt/cross/lib64
537
538
5396) How to install HAProxy
540=========================
541
542To install haproxy, you can either copy the single resulting binary to the
543place you want, or run :
544
545 $ sudo make install
546
547If you're packaging it for another system, you can specify its root directory
548in the usual DESTDIR variable.
549
550-- end