blob: ca47aa83da68adf8407957d6b77bad58fa84db09 [file] [log] [blame]
Willy Tarreau7f332732018-12-16 22:27:15 +01001Installation instructions for HAProxy
2=====================================
3
Willy Tarreau989c55d2022-12-01 15:23:12 +01004This is a development version, so it is expected to break from time to time,
5to add and remove features without prior notification and it should not be used
6in production, unless you're an experienced user and are willing to follow
7weekly updates. If you are not used to build from sources or if you are not
8used to follow updates then it is recommended that instead you use the packages
9provided by your software vendor or Linux distribution. Most of them are taking
10this task seriously and are doing a good job at backporting important fixes.
Willy Tarreaud705b852022-12-01 15:15:24 +010011
12If for any reason you'd prefer to use a different version than the one packaged
Willy Tarreau3b068c42021-11-23 15:48:35 +010013for your system, you want to be certain to have all the fixes or to get some
14commercial support, other choices are available at 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 Tarreau12840be2021-04-22 14:14:22 +020037 USE_OPENSSL=1 USE_LUA=1 USE_PCRE=1 USE_SYSTEMD=1
Willy Tarreau7f332732018-12-16 22:27:15 +010038 $ sudo make install
39
40 - FreeBSD and OpenBSD, build with all options :
Willy Tarreau12840be2021-04-22 14:14:22 +020041 $ gmake -j 4 TARGET=freebsd USE_OPENSSL=1 USE_LUA=1 USE_PCRE=1
Willy Tarreau7f332732018-12-16 22:27:15 +010042
43 - embedded Linux, build using a cross-compiler :
Willy Tarreau12840be2021-04-22 14:14:22 +020044 $ make -j $(nproc) TARGET=linux-glibc USE_OPENSSL=1 USE_PCRE=1 \
Willy Tarreaud254aa82019-06-14 18:40:48 +020045 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"
Willy Tarreau1efe6892021-04-02 15:53:34 +020076and are disabled by "USE_<feature>=" (with no value). An exhaustive list of the
77supported USE_* features is located at the top of the main Makefile. The last
78occurrence of such an option on the command line overrides any previous one.
79Example :
Willy Tarreau7f332732018-12-16 22:27:15 +010080
81 $ make TARGET=generic USE_THREAD=
82
83In case of error or missing TARGET, a help screen is displayed. It is also
84possible to display a list of all known options using "make help".
85
Willy Tarreau1efe6892021-04-02 15:53:34 +020086Some optional components which may depend on third-party libraries, are used
87with popular tools which are not necessarily standard implementations, or are
88maintained at slower pace than the core of the project, are located in the
89"addons/" directory. These ones may disappear in a future version if the
90product they depend on disappears or if their maintainers do not assign enough
91resources to maintain them any more. For this reason they are not built by
92default, but some USE_* options are usually provided for them, and their build
93is routinely tested anyway.
94
Willy Tarreau7f332732018-12-16 22:27:15 +010095
963) Build environment
97====================
98
99HAProxy requires a working GCC or Clang toolchain and GNU make :
100
101 - GNU make >= 3.80. Note that neither Solaris nor OpenBSD's make work with
102 the GNU Makefile. If you get many syntax errors when running "make", you
103 may want to retry with "gmake" which is the name commonly used for GNU make
104 on BSD systems.
105
Willy Tarreau30985402023-05-24 22:32:46 +0200106 - GCC >= 4.2 (up to 13 tested). Older versions can be made to work with a
Willy Tarreau7f332732018-12-16 22:27:15 +0100107 few minor adaptations if really needed. Newer versions may sometimes break
108 due to compiler regressions or behaviour changes. The version shipped with
109 your operating system is very likely to work with no trouble. Clang >= 3.0
110 is also known to work as an alternative solution. Recent versions may emit
Willy Tarreau4ced4bd2020-07-07 16:17:00 +0200111 a bit more warnings that are worth reporting as they may reveal real bugs.
Willy Tarreauc22747d2020-11-05 16:56:37 +0100112 TCC (https://repo.or.cz/tinycc.git) is also usable for developers but will
113 not support threading and was found at least once to produce bad code in
114 some rare corner cases (since fixed). But it builds extremely quickly
115 (typically half a second for the whole project) and is very convenient to
116 run quick tests during API changes or code refactoring.
Willy Tarreau7f332732018-12-16 22:27:15 +0100117
118 - GNU ld (binutils package), with no particular version. Other linkers might
119 work but were not tested.
120
121On debian or Ubuntu systems and their derivatives, you may get all these tools
122at once by issuing the two following commands :
123
124 $ sudo apt-get update
125 $ sudo apt-get install build-essential
126
127On Fedora, CentOS, RHEL and derivatives, you may get the equivalent packages
128with the following command :
129
130 $ sudo yum groupinstall "Development Tools"
131
132Please refer to your operating system's documentation for other systems.
133
134It is also possible to build HAProxy for another system or platform using a
135cross-compiler but in this case you probably already have installed these
136tools.
137
Willy Tarreauc5aa0602021-05-14 08:03:00 +0200138Building HAProxy may require between 60 and 80 MB of free space in the
Willy Tarreau7f332732018-12-16 22:27:15 +0100139directory where the sources have been extracted, depending on the debugging
140options involved.
141
142
1434) Dependencies
144===============
145
146HAProxy in its basic form does not depend on anything beyond a working libc.
147However a number of options are enabled by default, or are highly recommended,
148and these options will typically involve some external components or libraries,
Ilya Shipitsin2a950d02020-03-06 13:07:38 +0500149depending on the targeted platform.
Willy Tarreau7f332732018-12-16 22:27:15 +0100150
151Optional dependencies may be split into several categories :
152
153 - memory allocation
154 - regular expressions
155 - multi-threading
156 - password encryption
157 - cryptography
158 - compression
159 - lua
160 - device detection
161 - miscellaneous
162
163
1644.1) Memory allocation
165----------------------
166By default, HAProxy uses the standard malloc() call provided by the libc. It
Willy Tarreauc3643512019-03-27 14:20:43 +0100167may also be built to use jemalloc, which is fast and thread-safe. In order to
168use it, please add "-ljemalloc" to the ADDLIB variable. You may possibly also
169need to append "-lpthread" and/or "-ldl" depending on the operating system.
Willy Tarreau7f332732018-12-16 22:27:15 +0100170
171
1724.2) Regular expressions
173------------------------
174HAProxy may make use regular expressions (regex) to match certain patterns. The
175regex engine is provided by default in the libc. On some operating systems, it
176might happen that the original regex library provided by the libc is too slow,
177too limited or even bogus. For example, on older Solaris versions up to 8, the
178default regex used not to properly extract group references, without reporting
179compilation errors. Also, some early versions of the GNU libc used to include a
180regex engine which could be slow or even crash on certain patterns.
181
182If you plan on importing a particularly heavy configuration involving a lot of
Ilya Shipitsin01881082021-08-07 14:41:56 +0500183regex, you may benefit from using some alternative regex implementations such as
Willy Tarreau7f332732018-12-16 22:27:15 +0100184PCRE. HAProxy natively supports PCRE and PCRE2, both in standard and JIT
185flavors (Just In Time). The following options are available depending on the
186library version provided on your system :
187
188 - "USE_PCRE=1" : enable PCRE version 1, dynamic linking
189 - "USE_STATIC_PCRE=1" : enable PCRE version 1, static linking
190 - "USE_PCRE_JIT=1" : enable PCRE version 1 in JIT mode
191 - "USE_PCRE2=1" : enable PCRE version 2, dynamic linking
192 - "USE_STATIC_PCRE2=1" : enable PCRE version 2, static linking
193 - "USE_PCRE2_JIT=1" : enable PCRE version 2 in JIT mode
194
195Both of these libraries may be downloaded from https://www.pcre.org/.
196
197By default, the include and library paths are figured from the "pcre-config"
198and "pcre2-config" utilities. If these ones are not installed or inaccurate
199(for example when cross-compiling), it is possible to force the path to include
200files using "PCRE_INC" and "PCRE2_INC" respectively, and the path to library
201files using "PCRE_LIB" and "PCRE2_LIB" respectively. For example :
202
203 $ make TARGET=generic \
204 USE_PCRE2_JIT=1 PCRE2_INC=/opt/cross/include PCRE2_LIB=/opt/cross/lib
205
206
2074.3) Multi-threading
208--------------------
209On some systems for which positive feedback was reported, multi-threading will
210be enabled by default. When multi-threading is used, the libpthread library
211(POSIX threading) will be used. If the target system doesn't contain such a
212library, it is possible to forcefully disable multi-threading by adding
213"USE_THREAD=" on the command line.
214
215
2164.4) Password encryption
217------------------------
218Many systems provide password encryption functions used for authentication. On
219some systems these functions are part of the libc. On others, they're part of a
220separate library called "libcrypt". The default targets are pre-configured
221based on which system needs the library. It is possible to forcefully disable
222the linkage against libcrypt by adding "USE_LIBCRYPT=" on the command line, or
223to forcefully enable it using "USE_LIBCRYPT=1".
224
225
2264.5) Cryptography
227-----------------
228For SSL/TLS, it is necessary to use a cryptography library. HAProxy currently
Willy Tarreau2b4dc5c2022-05-08 10:59:00 +0200229supports the OpenSSL library, and is known to build and work with branches
William Lallemandf9c0bca2023-05-26 14:44:33 +02002301.0.0, 1.0.1, 1.0.2, 1.1.0, 1.1.1, 3.0 and 3.1. It is recommended to use at
231least OpenSSL 1.1.1 to have support for all SSL keywords and configuration in
232HAProxy. OpenSSL follows a long-term support cycle similar to HAProxy's, and
233each of the branches above receives its own fixes, without forcing you to
234upgrade to another branch. There is no excuse for staying vulnerable by not
235applying a fix available for your version. There is always a small risk of
236regression when jumping from one branch to another one, especially when it's
237very new, so it's preferable to observe for a while if you use a different
238version than your system's defaults. Specifically, it has been well established
239that OpenSSL 3.0 can be 2 to 20 times slower than earlier versions on
240multiprocessor systems due to design issues that cannot be fixed without a
241major redesign, so in this case upgrading should be carefully thought about
242(please see https://github.com/openssl/openssl/issues/20286 and
Willy Tarreau30985402023-05-24 22:32:46 +0200243https://github.com/openssl/openssl/issues/17627). If a migration to 3.x is
244mandated by support reasons, at least 3.1 recovers a small fraction of this
245important loss.
Willy Tarreau7f332732018-12-16 22:27:15 +0100246
Amaury Denoyellead3683b2021-11-03 18:14:44 +0100247Three OpenSSL derivatives called LibreSSL, BoringSSL and QUICTLS are reported
248to work as well. While there are some efforts from the community to ensure they
249work well, OpenSSL remains the primary target and this means that in case of
250conflicting choices, OpenSSL support will be favored over other options. Note
251that OpenSSL is not compatible when building haproxy with QUIC support. In this
Willy Tarreau30985402023-05-24 22:32:46 +0200252case, QUICTLS is the preferred alternative. As of writing this, the QuicTLS
253project follows OpenSSL very closely and provides update simultaneously, but
254being a volunteer-driven project, its long-term future does not look certain
255enough to convince operating systems to package it, so it needs to be build
256locally. See the section about QUIC in this document.
257
258A fifth option is wolfSSL (https://github.com/wolfSSL/wolfssl). It is the only
259supported alternative stack not based on OpenSSL, yet which implements almost
260all of its API and natively supports QUIC. At the time of writing, the vast
William Lallemand44c73ce2023-05-25 17:17:29 +0200261majority of SSL features are well supported by wolfSSL though not everything is
262exposed in haproxy yet, advanced users might notice tiny differences that the
263wolfSSL and HAProxy teams are working on together to address in the wolfSSL
264code base. Features like SSL resume, crt-list and client auth might not work as
265expected. As of May 2023, wolfSSL support is considered experimental. This
266stack is not affected by OpenSSL's design issue regarding multi-processor
267systems and is viewed by the HAProxy team as the most promising mid-term
268solution for general deployments and QUIC deployments.
Willy Tarreau7f332732018-12-16 22:27:15 +0100269
270In order to enable SSL/TLS support, simply pass "USE_OPENSSL=1" on the command
271line and the default library present on your system will be used :
272
273 $ make TARGET=generic USE_OPENSSL=1
274
275If you want to use a different version from the one provided by your system
276(which is not recommended due to the risk of missing security fixes), it is
277possible to indicate the path to the SSL include files using SSL_INC, and the
278SSL library files using SSL_LIB. Example :
279
280 $ make TARGET=generic \
281 USE_OPENSSL=1 SSL_INC=/opt/ssl-1.1.1/include SSL_LIB=/opt/ssl-1.1.1/lib
282
William Lallemand44c73ce2023-05-25 17:17:29 +0200283To use HAProxy with WolfSSL, WolfSSL must be built with haproxy support, at
284least WolfSSL 5.6.0 is needed, but a development version migh be needed for
285some of the features:
286
287 $ ./configure --enable-haproxy --enable-quic --prefix=/opt/wolfssl-5.6.0/
288
Willy Tarreau30985402023-05-24 22:32:46 +0200289Building with wolfSSL requires to specify the API variant on the "make"
290command line, for example:
291
292 $ make -j $(nproc) TARGET=generic USE_OPENSSL_WOLFSSL=1 USE_QUIC=1 \
293 SSL_INC=/opt/wolfssl-5.6.0/include SSL_LIB=/opt/wolfssl-5.6.0/lib
294
Willy Tarreau7f332732018-12-16 22:27:15 +0100295In order to link OpenSSL statically against HAProxy, first download OpenSSL
296from https://www.openssl.org/ then build it with the "no-shared" keyword and
297install it to a local directory, so your system is not affected :
298
299 $ export STATICLIBSSL=/tmp/staticlibssl
300 $ ./config --prefix=$STATICLIBSSL no-shared
301 $ make && make install_sw
302
303Then when building haproxy, pass that path via SSL_INC and SSL_LIB :
304
305 $ make TARGET=generic \
306 USE_OPENSSL=1 SSL_INC=$STATICLIBSSL/include SSL_LIB=$STATICLIBSSL/lib
307
308When building with OpenSSL on some systems, you may also need to enable support
309for the "libz" library, which is visible if the linker complains about function
310"deflateInit()" not being found. In this case, simply append "ADDLIB=-lz" to
311the command line.
312
313It is worth mentioning that asynchronous cryptography engines are supported on
314OpenSSL 1.1.0 and above. Such engines are used to access hardware cryptography
Willy Tarreauf985f032022-04-11 19:00:27 +0200315acceleration that might be present on your system. Due to API changes that
316appeared with OpenSSL 3.0 and cause lots of build warnings, engines are not
317enabled by default anymore in HAProxy 2.6. It is required to pass USE_ENGINE=1
318if they are desired.
Willy Tarreau7f332732018-12-16 22:27:15 +0100319
Willy Tarreau30985402023-05-24 22:32:46 +0200320If for any reason you are forced to use OpenSSL 3.x and the performance is not
321acceptable at all, you may want to try replacing the pthread locks that OpenSSL
322uses with HAProxy's much lighter locks that are able to emulate them:
323
324 $ make TARGET=generic \
325 USE_OPENSSL=1 USE_PTHREAD_EMULATION=1
326
327On large multi-processor systems, this may result in a performance increase of
32850 to 100% on OpenSSL 3.0 depending on the level of contention, but this will
329of course not recover everything. It should not be used by distro packagers as
330it is a bit less observable.
331
Willy Tarreau7f332732018-12-16 22:27:15 +0100332
3334.6) Compression
334----------------
335HAProxy can compress HTTP responses before delivering them to clients, in order
336to save network bandwidth. Two compression options are available. The first one
Willy Tarreau12840be2021-04-22 14:14:22 +0200337relies on the libslz library (http://libslz.org) that is embedded in haproxy.
338It is enabled by default as it is very fast and does not keep a copy of the
339contents in memory. It is possible to disable it, for example for very small
340systems, by passing "USE_SLZ=" to the "make" command.
341
342Please note that SLZ will benefit from some CPU-specific instructions like the
343availability of the CRC32 extension on some ARM processors. Thus it can further
Willy Tarreau40a871f2021-05-12 09:47:30 +0200344improve its performance to build with "CPU=native" on the target system, or
345"CPU=armv81" (modern systems such as Graviton2 or A55/A75 and beyond),
346"CPU=a72" (e.g. for RPi4, or AWS Graviton), "CPU=a53" (e.g. for RPi3), or
347"CPU=armv8-auto" (automatic detection with minor runtime penalty).
Willy Tarreau12840be2021-04-22 14:14:22 +0200348
349A second option involves the widely known zlib library, which is very likely
350installed on your system. In order to use zlib, simply pass "USE_ZLIB=1" to the
351"make" command line, which will also automatically disable SLZ. If the library
352is not installed in your default system's path, it is possible to specify the
353path to the include files using ZLIB_INC, and the path to the library files
354using ZLIB_LIB :
Willy Tarreau7f332732018-12-16 22:27:15 +0100355
356 $ make TARGET=generic \
357 USE_ZLIB=1 ZLIB_INC=/opt/zlib-1.2.11/include ZLIB_LIB=/opt/zlib-1.2.11/lib
358
Willy Tarreau7f332732018-12-16 22:27:15 +0100359Zlib is commonly found on most systems, otherwise updates can be retrieved from
360http://www.zlib.net/. It is easy and fast to build, and new versions sometimes
Willy Tarreau12840be2021-04-22 14:14:22 +0200361provide better performance so it might be worth using an up-to-date one.
Willy Tarreau7f332732018-12-16 22:27:15 +0100362
Willy Tarreau12840be2021-04-22 14:14:22 +0200363Zlib compresses a bit better than libslz but at the expense of more CPU usage
364(about 3.5 times more minimum), and a huge memory usage (~260 kB per compressed
365stream). The only valid reason for uzing Zlib instead of SLZ here usually is to
366deal with a very limited internet bandwidth while CPU and RAM are abundant so
367that the last few percent of compression ratio are worth the invested hardware.
368
Willy Tarreau7f332732018-12-16 22:27:15 +0100369
3704.7) Lua
371--------
Ilya Shipitsin2a950d02020-03-06 13:07:38 +0500372Lua is an embedded programming language supported by HAProxy to provide more
Willy Tarreau7f332732018-12-16 22:27:15 +0100373advanced scripting capabilities. Only versions 5.3 and above are supported.
374In order to enable Lua support, please specify "USE_LUA=1" on the command line.
375Some systems provide this library under various names to avoid conflicts with
Christian Ruppert3214b442022-06-28 10:03:00 +0200376previous versions. By default, HAProxy looks for "lua5.4", "lua54", "lua5.3",
377"lua53", "lua". If your system uses a different naming, you may need to set the
378library name in the "LUA_LIB_NAME" variable.
Willy Tarreau7f332732018-12-16 22:27:15 +0100379
380If Lua is not provided on your system, it can be very simply built locally. It
381can be downloaded from https://www.lua.org/, extracted and built, for example :
382
Willy Tarreau30985402023-05-24 22:32:46 +0200383 $ cd /opt/lua-5.4.6
Willy Tarreau7f332732018-12-16 22:27:15 +0100384 $ make linux
385
386The path to the include files and library files may be set using "LUA_INC" and
387"LUA_LIB" respectively. For example :
388
389 $ make TARGET=generic \
Willy Tarreau30985402023-05-24 22:32:46 +0200390 USE_LUA=1 LUA_INC=/opt/lua-5.4.6/src LUA_LIB=/opt/lua-5.4.6/src
Willy Tarreau7f332732018-12-16 22:27:15 +0100391
392
3934.8) Device detection
394---------------------
395HAProxy supports several device detection modules relying on third party
396products. Some of them may provide free code, others free libs, others free
397evaluation licenses. Please read about their respective details in the
398following files :
399
400 doc/DeviceAtlas-device-detection.txt for DeviceAtlas
401 doc/51Degrees-device-detection.txt for 51Degrees
Willy Tarreaub3cc9f22019-04-19 16:03:32 +0200402 doc/WURFL-device-detection.txt for Scientiamobile WURFL
Willy Tarreau7f332732018-12-16 22:27:15 +0100403
404
4054.9) Miscellaneous
406------------------
407Some systems have specificities. Usually these specificities are known and/or
408detected and properly set for you. If you need to adjust the behaviour, here
409are the extra libraries that may be referenced at build time :
410
411 - USE_RT=1 build with librt, which is sometimes needed on some systems
412 when using threads. It is set by default on Linux platforms,
413 and may be disabled using "USE_RT=" if your system doesn't
Willy Tarreau4703fdd2019-06-16 19:39:44 +0200414 have one. You may have to set it as well if you face an error
415 indicating that clock_gettime() was not found.
Willy Tarreau7f332732018-12-16 22:27:15 +0100416
417 - USE_DL=1 build with libdl, which is usually needed for Lua and OpenSSL
418 on Linux. It is automatically detected and may be disabled
419 using "USE_DL=", though it should never harm.
420
421 - USE_SYSTEMD=1 enables support for the sdnotify features of systemd,
422 allowing better integration with systemd on Linux systems
423 which come with it. It is never enabled by default so there
424 is no need to disable it.
425
Willy Tarreau4ced4bd2020-07-07 16:17:00 +0200426
Willy Tarreau4703fdd2019-06-16 19:39:44 +02004274.10) Common errors
428-------------------
429Some build errors may happen depending on the options combinations or the
430selected target. When facing build errors, if you know that your system is a
431bit special or particularly old, start from TARGET=generic, it is easier to
432start from there and fix the remaining issues than trying to degrade another
433target. Common issues may include:
434
435 - clock_gettime() not found
436 => your system needs USE_RT=1
437
Willy Tarreau4703fdd2019-06-16 19:39:44 +0200438 - many __sync_<something> errors in many files
Willy Tarreau6fd04502021-06-15 16:11:33 +0200439 => your gcc is too old, build without threads.
Willy Tarreau4703fdd2019-06-16 19:39:44 +0200440
441 - many openssl errors
442 => your OpenSSL version really is too old, do not enable OpenSSL
443
Willy Tarreau30985402023-05-24 22:32:46 +0200444 - quic_conn-t.h: field 'level' has incomplete type
445 => you tried to build QUIC with the legacy OpenSSL library, which does
446 not support QUIC. Either disable QUIC with "USE_QUIC=" or use any
447 other supported compatible library.
448
Willy Tarreau7f332732018-12-16 22:27:15 +0100449
Amaury Denoyellead3683b2021-11-03 18:14:44 +01004504.11) QUIC
451----------
452QUIC is the new transport layer protocol and is required for HTTP/3. This
453protocol stack is currently supported as an experimental feature in haproxy on
454the frontend side. In order to enable it, use "USE_QUIC=1 USE_OPENSSL=1".
455
456Note that the OpenSSL library is not compatible with QUIC. The preferred option
457is to use QUICTLS. This is a fork of OpenSSL with a QUIC-compatible API. Its
458repository is available at https://github.com/quictls/openssl. You can use the
459following instruction to build a functional QUICTLS.
460
Ilya Shipitsin85417482022-04-10 12:09:31 +0500461 $ ./config --libdir=lib [--prefix=/opt/quictls]
Amaury Denoyellead3683b2021-11-03 18:14:44 +0100462 $ make
463 $ make install
464
465On a development environment, use SSL_INC and SSL_LIB when building haproxy to
466point to the correct cryptographic library. It may be useful to specify QUICTLS
467location via rpath for haproxy execution. Example :
468
469 $ make TARGET=generic \
470 USE_QUIC=1 \
471 USE_OPENSSL=1 SSL_INC=/opt/quictls/include SSL_LIB=/opt/quictls/lib \
472 LDFLAGS="-Wl,-rpath,/opt/quictls/lib"
473
Willy Tarreau7f332732018-12-16 22:27:15 +01004745) How to build HAProxy
475=======================
476
477This section assumes that you have already read section 2 (basic principles)
478and section 3 (build environment). It often refers to section 4 (dependencies).
479
480To build haproxy, you have to choose your target OS amongst the following ones
481and assign it to the TARGET variable :
482
Lukas Tribuscc1eb162019-09-01 16:48:36 +0200483 - linux-glibc for Linux kernel 2.6.28 and above
484 - linux-glibc-legacy for Linux kernel 2.6.28 and above without new features
Willy Tarreau39b2fda2020-04-16 15:14:17 +0200485 - linux-musl for Linux kernel 2.6.28 and above with musl libc
Brad Smith7c503bb2020-09-30 15:46:16 -0400486 - solaris for Solaris 10 and above
Brad Smith3f1977c2020-10-02 18:36:58 -0400487 - freebsd for FreeBSD 10 and above
Brad Smith382001b2020-10-08 01:15:06 -0400488 - dragonfly for DragonFlyBSD 4.3 and above
Brad Smith0fdfe412020-10-08 16:24:52 -0400489 - netbsd for NetBSD 8 and above
Lukas Tribuscc1eb162019-09-01 16:48:36 +0200490 - osx for Mac OS/X
Brad Smith3f1977c2020-10-02 18:36:58 -0400491 - openbsd for OpenBSD 6.3 and above
Lukas Tribuscc1eb162019-09-01 16:48:36 +0200492 - aix51 for AIX 5.1
493 - aix52 for AIX 5.2
Christian Lachnerc1322302020-02-10 10:29:13 +0100494 - aix72-gcc for AIX 7.2 (using gcc)
Lukas Tribuscc1eb162019-09-01 16:48:36 +0200495 - cygwin for Cygwin
496 - haiku for Haiku
497 - generic for any other OS or version.
498 - custom to manually adjust every setting
Willy Tarreau7f332732018-12-16 22:27:15 +0100499
500You may also choose your CPU to benefit from some optimizations. This is
501particularly important on UltraSparc machines. For this, you can assign
502one of the following choices to the CPU variable :
503
504 - i686 for intel PentiumPro, Pentium 2 and above, AMD Athlon (32 bits)
505 - i586 for intel Pentium, AMD K6, VIA C3.
506 - ultrasparc : Sun UltraSparc I/II/III/IV processor
Christian Lachnerc1322302020-02-10 10:29:13 +0100507 - power8 : IBM POWER8 processor
508 - power9 : IBM POWER9 processor
Willy Tarreau40a871f2021-05-12 09:47:30 +0200509 - armv81 : modern ARM cores (Cortex A55/A75/A76/A78/X1, Neoverse, Graviton2)
510 - a72 : ARM Cortex-A72 or A73 (e.g. RPi4, Odroid N2, AWS Graviton)
511 - a53 : ARM Cortex-A53 or any of its successors in 64-bit mode (e.g. RPi3)
512 - armv8-auto : support both older and newer armv8 cores with a minor penalty,
513 thanks to gcc 10's outline atomics (default with gcc 10.2).
Willy Tarreau7f332732018-12-16 22:27:15 +0100514 - native : use the build machine's specific processor optimizations. Use with
515 extreme care, and never in virtualized environments (known to break).
516 - generic : any other processor or no CPU-specific optimization. (default)
517
518Alternatively, you may just set the CPU_CFLAGS value to the optimal GCC options
519for your platform. A second variable named SMALL_OPTS also supports passing a
520number of defines and compiler options usually for small systems. For better
521clarity it's recommended to pass the options which result in a smaller binary
522(like memory limits or -Os) into this variable.
523
524If you are building for a different system than the one you're building on,
525this is called "cross-compiling". HAProxy supports cross-compilation pretty
526well and tries to ease it by letting you adjust paths to all libraries (please
527read section 4 on dependencies for more details). When cross-compiling, you
528just need to pass the path to your compiler in the "CC" variable, and the path
529to the linker in the "LD" variable. Most of the time, setting the CC variable
530is enough since LD points to it by default.
531
532By default the build process runs in quiet mode and hide the details of the
533commands that are executed. This allows to more easily catch build warnings
534and see what is happening. However it is not convenient at all to observe what
535flags are passed to the compiler nor what compiler is involved. Simply append
536"V=1" to the "make" command line to switch to verbose mode and display the
537details again. It is recommended to use this option when cross-compiling to
Willy Tarreau2fefab62023-05-07 07:10:55 +0200538verify that the paths are correct and that /usr/include is never involved.
Willy Tarreau7f332732018-12-16 22:27:15 +0100539
540You may want to build specific target binaries which do not match your native
541compiler's target. This is particularly true on 64-bit systems when you want
542to build a 32-bit binary. Use the ARCH variable for this purpose. Right now
543it only knows about a few x86 variants (i386,i486,i586,i686,x86_64), two
544generic ones (32,64) and sets -m32/-m64 as well as -march=<arch> accordingly.
545This variable is only used to set ARCH_FLAGS to preset values, so if you know
546the arch-specific flags that your system needs, you may prefer to set
547ARCH_FLAGS instead. Note that these flags are passed both to the compiler and
548to the linker. For example, in order to build a 32-bit binary on an x86_64
549Linux system with SSL support without support for compression but when OpenSSL
550requires ZLIB anyway :
551
Willy Tarreaud254aa82019-06-14 18:40:48 +0200552 $ make TARGET=linux-glibc ARCH=i386 USE_OPENSSL=1 ADDLIB=-lz
Willy Tarreau7f332732018-12-16 22:27:15 +0100553
554Recent systems can resolve IPv6 host names using getaddrinfo(). This primitive
555is not present in all libcs and does not work in all of them either. Support in
556glibc was broken before 2.3. Some embedded libs may not properly work either,
557thus, support is disabled by default, meaning that some host names which only
558resolve as IPv6 addresses will not resolve and configs might emit an error
559during parsing. If you know that your OS libc has reliable support for
560getaddrinfo(), you can add USE_GETADDRINFO=1 on the make command line to enable
561it. This is the recommended option for most Linux distro packagers since it's
562working fine on all recent mainstream distros. It is automatically enabled on
563Solaris 8 and above, as it's known to work.
564
565If your system supports PCRE (Perl Compatible Regular Expressions), then you
566really should build with libpcre which is between 2 and 10 times faster than
567other libc implementations. Regex are used for header processing (deletion,
568rewriting, allow, deny). Please see section 4 about dependencies to figure
569how to build with PCRE support.
570
571It is possible to add native support for SSL, by passing "USE_OPENSSL=1" on the
572make command line. The libssl and libcrypto will automatically be linked with
573HAProxy. Some systems also require libz, so if the build fails due to missing
574symbols such as deflateInit(), then try again with "ADDLIB=-lz". Please check
575section 4 about dependencies for more information on how to build with OpenSSL.
576
577HAProxy can compress HTTP responses to save bandwidth. Please see section 4
578about dependencies to see the available libraries and associated options.
579
Willy Tarreaue97b04b2022-03-01 07:40:24 +0100580By default, the DEBUG_CFLAGS variable is set to '-g' to enable debug symbols.
581It is not wise to disable it on uncommon systems, because it's often the only
582way to get a usable core when you need one. Otherwise, you can set DEBUG to
583'-s' to strip the binary.
Willy Tarreau7f332732018-12-16 22:27:15 +0100584
585If the ERR variable is set to any non-empty value, then -Werror will be added
586to the compiler so that any build warning will trigger an error. This is the
587recommended way to build when developing, and it is expected that contributed
588patches were tested with ERR=1.
589
Willy Tarreau0dd8dd62022-03-01 08:31:50 +0100590The DEBUG variable is used to extend the CFLAGS and is preset to a list of
591build-time options that are known for providing significant reliability
592improvements and a barely perceptible performance cost. Unless instructed to do
593so by some project developers, or trying to save the last ounce of performance,
594these options should not be changed. Among the usable ones are:
595 - -DDEBUG_STRICT: enable some runtime assertions at key places in the code.
596 The goal is to emit a warning or stop the program if certain expected
597 conditions are not met, and whose violation will result in a misbehaving
598 process due to memory corruption or other significant trouble, possibly
599 caused by an attempt to exploit a bug in the program or a library it relies
600 on. The option knows 3 values: 0 (disable all such assertions, the default
601 when the option is not set), 1 (enable all inexpensive assertions), and
602 2 (enable all assertions even in fast paths). Setting the option with no
603 value corresponds to 1, which is the recommended value for production.
604
605 - -DDEBUG_STRICT_ACTION: indicates how to react to a check violation. There
606 are 3 types of checks: BUG (condition that is known to have serious
607 consequences), WARN (warning about a highly suspicious condition which the
608 process may recover from, but whose unknown cause may also have serious
609 consequences), CHECK (verification whether a condition that developers now
610 consider impossible still happens). The variable takes a value from 0 to 3,
611 that adjusts the behavior on these 3 violations:
612
613 BUG WARN CHECK
614 0 warn warn warn
615 1 stop warn warn
616 2 stop stop warn
617 3 stop stop stop
618
619 The default value is 1, which is the best balance for production in that it
620 will do its best to prevent a known bogus process from running away, but
621 will let it run if it believes it can recover. Users running the process in
622 sensitive environments (finance etc) may prefer to run at level 2 to make
623 sure to stop any detected anomaly before it may have an impact. Level 3
624 should only be used at the request of developers. In any case, any emitted
625 warning should be reported to developers.
626
627 - -DDEBUG_MEMORY_POOLS: this enables by default extra controls around memory
628 allocation that will help detect coding errors such as double-frees and
629 freeing a bad memory location. It will also detect earlier risks of memory
630 overflows, which may have security implications. The cost is extremely low
631 (less than 1% increase in memory footprint). This is equivalent to adding
632 "-dMtag" on the command line. This option is enabled in the default build
633 options.
634
635 - -DDEBUG_DONT_SHARE_POOLS: this will keep separate pools for same-sized
636 objects of different types. Using this increases the memory usage a little
637 bit but further reduces the risk of memory management related bugs and will
638 lead to more accurate traces in case of error. It is equivalent to adding
639 "-dMno-merge" on the command line. It is not enabled in the default build
640 options.
641
642 - -DDEBUG_POOL_INTEGRITY: this will enable runtime detection and stopping of
643 a class of bugs known as "use after free", which consists in modifying a
644 memory area after freeing it while it was reused for something else. This
645 option is quite powerful but such bugs are fortunately extremely rare, and
646 it will cause a measurable performance degradation (a few percent). This is
647 equivalent to adding "-dMcold-first,integrity" on the command line. This
648 option is not enabled by default but users running development versions on
649 moderate performance sites in order to participate to reliability testing
650 are encouraged to use it, in combination with -DDEBUG_DONT_SHARE_POOLS and
651 -DDEBUG_MEMORY_POOLS, as this could catch dangerous regressions.
652
653As such, for regular production, "-DDEBUG_STRICT -DDEBUG_MEMORY_POOLS" is
654recommended. For security sensitive environments, it is recommended to use
655"-DDEBUG_STRICT -DDEBUG_STRICT_ACTION=2 -DDEBUG_MEMORY_POOLS \
656-DDEBUG_DONT_SHARE_POOLS". For deployments dedicated to testing new versions or
657when trying to nail a bug down, use "-DDEBUG_STRICT=2 -DDEBUG_STRICT_ACTION=2 \
658-DDEBUG_MEMORY_POOLS -DDEBUG_DONT_SHARE_POOLS -DDEBUG_POOL_INTEGRITY".
659
Willy Tarreau09bdb112022-03-01 07:45:18 +0100660The DEP variable is automatically set to the list of include files and also
661designates a file that contains the last build options used. It is used during
662the build process to compute dependencies and decide whether or not to rebuild
663everything (we do rebuild everything when .h files are touched or when build
664options change). Sometimes when performing fast build iterations on inline
665functions it may be desirable to avoid a full rebuild. Forcing this variable
666to be empty will be sufficient to achieve this. This variable must never be
667forced to produce final binaries, and must not be used during bisect sessions,
668as it will often lead to the wrong commit.
669
Willy Tarreau7f332732018-12-16 22:27:15 +0100670If you need to pass other defines, includes, libraries, etc... then please
671check the Makefile to see which ones will be available in your case, and
672use/override the USE_* variables from the Makefile.
673
674AIX 5.3 is known to work with the generic target. However, for the binary to
675also run on 5.2 or earlier, you need to build with DEFINE="-D_MSGQSUPPORT",
676otherwise __fd_select() will be used while not being present in the libc, but
677this is easily addressed using the "aix52" target. If you get build errors
678because of strange symbols or section mismatches, simply remove -g from
679DEBUG_CFLAGS.
680
Christian Lachnerc1322302020-02-10 10:29:13 +0100681Building on AIX 7.2 works fine using the "aix72-gcc" TARGET. It adds two
Thayne McCombscdbcca92021-01-07 21:24:41 -0700682special CFLAGS to prevent the loading of AIX's xmem.h and var.h. This is done
Christian Lachnerc1322302020-02-10 10:29:13 +0100683by defining the corresponding include-guards _H_XMEM and _H_VAR. Without
684excluding those header-files the build fails because of redefinition errors.
Ilya Shipitsin2a950d02020-03-06 13:07:38 +0500685Furthermore, the atomic library is added to the LDFLAGS to allow for
Christian Lachnerc1322302020-02-10 10:29:13 +0100686multithreading via USE_THREAD.
687
Willy Tarreau7f332732018-12-16 22:27:15 +0100688You can easily define your own target with the GNU Makefile. Unknown targets
689are processed with no default option except USE_POLL=default. So you can very
Willy Tarreau12840be2021-04-22 14:14:22 +0200690well use that property to define your own set of options. USE_POLL and USE_SLZ
691can even be disabled by setting them to an empty string. For example :
Willy Tarreau7f332732018-12-16 22:27:15 +0100692
Willy Tarreau12840be2021-04-22 14:14:22 +0200693 $ gmake TARGET=tiny USE_POLL="" USE_SLZ="" TARGET_CFLAGS=-fomit-frame-pointer
Willy Tarreau7f332732018-12-16 22:27:15 +0100694
695If you need to pass some defines to the preprocessor or compiler, you may pass
696them all in the DEFINE variable. Example:
697
698 $ make TARGET=generic DEFINE="-DDEBUG_DONT_SHARE_POOLS -DDEBUG_MEMORY_POOLS"
699
700The ADDINC variable may be used to add some extra include paths; this is
701sometimes needed when cross-compiling. Similarly the ADDLIB variable may be
702used to specifify extra paths to library files. Example :
703
704 $ make TARGET=generic ADDINC=-I/opt/cross/include ADDLIB=-L/opt/cross/lib64
705
706
7076) How to install HAProxy
708=========================
709
710To install haproxy, you can either copy the single resulting binary to the
711place you want, or run :
712
713 $ sudo make install
714
715If you're packaging it for another system, you can specify its root directory
716in the usual DESTDIR variable.
717
718-- end