Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 1 | Installation instructions for HAProxy |
| 2 | ===================================== |
| 3 | |
Willy Tarreau | 46fb37c | 2021-05-14 09:02:22 +0200 | [diff] [blame] | 4 | HAProxy 2.4 is a long-term supported version, which means that it will get |
| 5 | fixes for bugs as they are discovered till around Q2 2026 and will not receive |
| 6 | new features. This version is suitable for general deployment as it is expected |
| 7 | to receive less frequent updates than regular stable branches which have an odd |
| 8 | digit in the minor version number. New users are strongly advised encouraged to |
| 9 | use only such long-term supported versions such as the ones provided by their |
| 10 | software vendor or Linux distribution. If for any reason you would prefer a |
| 11 | different version than the one packaged for your system, you want to be certain |
| 12 | to have all the fixes or to get some commercial support, other choices are |
| 13 | available at http://www.haproxy.com/. |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 14 | |
| 15 | |
| 16 | Areas covered in this document |
| 17 | ============================== |
| 18 | |
| 19 | 1) Quick build & install |
| 20 | 2) Basic principles |
| 21 | 3) Build environment |
| 22 | 4) Dependencies |
| 23 | 5) Advanced build options |
| 24 | 6) How to install HAProxy |
| 25 | |
| 26 | |
| 27 | 1) Quick build & install |
| 28 | ======================== |
| 29 | |
| 30 | If you've already built HAProxy and are just looking for a quick reminder, here |
| 31 | are a few build examples : |
| 32 | |
| 33 | - recent Linux system with all options, make and install : |
| 34 | $ make clean |
Willy Tarreau | d254aa8 | 2019-06-14 18:40:48 +0200 | [diff] [blame] | 35 | $ make -j $(nproc) TARGET=linux-glibc \ |
Abhijeet Rastogi | b402450 | 2024-02-07 18:47:42 -0800 | [diff] [blame] | 36 | USE_OPENSSL=1 USE_LUA=1 USE_PCRE2=1 USE_SYSTEMD=1 |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 37 | $ sudo make install |
| 38 | |
| 39 | - FreeBSD and OpenBSD, build with all options : |
Abhijeet Rastogi | b402450 | 2024-02-07 18:47:42 -0800 | [diff] [blame] | 40 | $ gmake -j 4 TARGET=freebsd USE_OPENSSL=1 USE_LUA=1 USE_PCRE2=1 |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 41 | |
| 42 | - embedded Linux, build using a cross-compiler : |
Abhijeet Rastogi | b402450 | 2024-02-07 18:47:42 -0800 | [diff] [blame] | 43 | $ make -j $(nproc) TARGET=linux-glibc USE_OPENSSL=1 USE_PCRE2=1 \ |
Willy Tarreau | d254aa8 | 2019-06-14 18:40:48 +0200 | [diff] [blame] | 44 | CC=/opt/cross/gcc730-arm/bin/gcc ADDLIB=-latomic |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 45 | |
| 46 | - Build with static PCRE on Solaris / UltraSPARC : |
Abhijeet Rastogi | b402450 | 2024-02-07 18:47:42 -0800 | [diff] [blame] | 47 | $ make TARGET=solaris CPU=ultrasparc USE_STATIC_PCRE2=1 |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 48 | |
| 49 | For more advanced build options or if a command above reports an error, please |
| 50 | read the following sections. |
| 51 | |
| 52 | |
| 53 | 2) Basic principles |
| 54 | =================== |
| 55 | |
| 56 | HAProxy uses a single GNU Makefile which supports options on the command line, |
| 57 | so that there is no need to hack a "configure" file to work on your system. The |
| 58 | makefile totally supports parallel build using "make -j <jobs>" where <jobs> |
| 59 | matches the number of usable processors, which on some platforms is returned by |
| 60 | the "nproc" utility. The explanations below may occasionally refer to some |
| 61 | options, usually in the form "name=value", which have to be passed to the |
| 62 | command line. This means that the option has to be passed after the "make" |
| 63 | command. For example : |
| 64 | |
| 65 | $ make -j $(nproc) TARGET=generic USE_GZIP=1 |
| 66 | |
| 67 | One required option is TARGET, it must be set to a target platform name, which |
| 68 | provides a number of presets. The list of known platforms is displayed when no |
| 69 | target is specified. It is not strictly required to use the exact target, you |
| 70 | can use a relatively similar one and adjust specific variables by hand. |
| 71 | |
| 72 | Most configuration variables are in fact booleans. Some options are detected and |
| 73 | enabled by default if available on the target platform. This is the case for all |
| 74 | those named "USE_<feature>". These booleans are enabled by "USE_<feature>=1" |
Willy Tarreau | 1efe689 | 2021-04-02 15:53:34 +0200 | [diff] [blame] | 75 | and are disabled by "USE_<feature>=" (with no value). An exhaustive list of the |
| 76 | supported USE_* features is located at the top of the main Makefile. The last |
| 77 | occurrence of such an option on the command line overrides any previous one. |
| 78 | Example : |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 79 | |
| 80 | $ make TARGET=generic USE_THREAD= |
| 81 | |
| 82 | In case of error or missing TARGET, a help screen is displayed. It is also |
| 83 | possible to display a list of all known options using "make help". |
| 84 | |
Willy Tarreau | 1efe689 | 2021-04-02 15:53:34 +0200 | [diff] [blame] | 85 | Some optional components which may depend on third-party libraries, are used |
| 86 | with popular tools which are not necessarily standard implementations, or are |
| 87 | maintained at slower pace than the core of the project, are located in the |
| 88 | "addons/" directory. These ones may disappear in a future version if the |
| 89 | product they depend on disappears or if their maintainers do not assign enough |
| 90 | resources to maintain them any more. For this reason they are not built by |
| 91 | default, but some USE_* options are usually provided for them, and their build |
| 92 | is routinely tested anyway. |
| 93 | |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 94 | |
| 95 | 3) Build environment |
| 96 | ==================== |
| 97 | |
| 98 | HAProxy requires a working GCC or Clang toolchain and GNU make : |
| 99 | |
| 100 | - GNU make >= 3.80. Note that neither Solaris nor OpenBSD's make work with |
| 101 | the GNU Makefile. If you get many syntax errors when running "make", you |
| 102 | may want to retry with "gmake" which is the name commonly used for GNU make |
| 103 | on BSD systems. |
| 104 | |
Willy Tarreau | f5c5107 | 2022-05-11 11:29:54 +0200 | [diff] [blame] | 105 | - GCC >= 4.2 (up to 12 tested). Older versions can be made to work with a |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 106 | few minor adaptations if really needed. Newer versions may sometimes break |
| 107 | due to compiler regressions or behaviour changes. The version shipped with |
| 108 | your operating system is very likely to work with no trouble. Clang >= 3.0 |
| 109 | is also known to work as an alternative solution. Recent versions may emit |
Willy Tarreau | 4ced4bd | 2020-07-07 16:17:00 +0200 | [diff] [blame] | 110 | a bit more warnings that are worth reporting as they may reveal real bugs. |
Willy Tarreau | c22747d | 2020-11-05 16:56:37 +0100 | [diff] [blame] | 111 | TCC (https://repo.or.cz/tinycc.git) is also usable for developers but will |
| 112 | not support threading and was found at least once to produce bad code in |
| 113 | some rare corner cases (since fixed). But it builds extremely quickly |
| 114 | (typically half a second for the whole project) and is very convenient to |
| 115 | run quick tests during API changes or code refactoring. |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 116 | |
| 117 | - GNU ld (binutils package), with no particular version. Other linkers might |
| 118 | work but were not tested. |
| 119 | |
| 120 | On debian or Ubuntu systems and their derivatives, you may get all these tools |
| 121 | at once by issuing the two following commands : |
| 122 | |
| 123 | $ sudo apt-get update |
| 124 | $ sudo apt-get install build-essential |
| 125 | |
| 126 | On Fedora, CentOS, RHEL and derivatives, you may get the equivalent packages |
| 127 | with the following command : |
| 128 | |
| 129 | $ sudo yum groupinstall "Development Tools" |
| 130 | |
| 131 | Please refer to your operating system's documentation for other systems. |
| 132 | |
| 133 | It is also possible to build HAProxy for another system or platform using a |
| 134 | cross-compiler but in this case you probably already have installed these |
| 135 | tools. |
| 136 | |
Willy Tarreau | c5aa060 | 2021-05-14 08:03:00 +0200 | [diff] [blame] | 137 | Building HAProxy may require between 60 and 80 MB of free space in the |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 138 | directory where the sources have been extracted, depending on the debugging |
| 139 | options involved. |
| 140 | |
| 141 | |
| 142 | 4) Dependencies |
| 143 | =============== |
| 144 | |
| 145 | HAProxy in its basic form does not depend on anything beyond a working libc. |
| 146 | However a number of options are enabled by default, or are highly recommended, |
| 147 | and these options will typically involve some external components or libraries, |
Ilya Shipitsin | 2a950d0 | 2020-03-06 13:07:38 +0500 | [diff] [blame] | 148 | depending on the targeted platform. |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 149 | |
| 150 | Optional dependencies may be split into several categories : |
| 151 | |
| 152 | - memory allocation |
| 153 | - regular expressions |
| 154 | - multi-threading |
| 155 | - password encryption |
| 156 | - cryptography |
| 157 | - compression |
| 158 | - lua |
| 159 | - device detection |
| 160 | - miscellaneous |
| 161 | |
| 162 | |
| 163 | 4.1) Memory allocation |
| 164 | ---------------------- |
| 165 | By default, HAProxy uses the standard malloc() call provided by the libc. It |
Willy Tarreau | c364351 | 2019-03-27 14:20:43 +0100 | [diff] [blame] | 166 | may also be built to use jemalloc, which is fast and thread-safe. In order to |
| 167 | use it, please add "-ljemalloc" to the ADDLIB variable. You may possibly also |
| 168 | need to append "-lpthread" and/or "-ldl" depending on the operating system. |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 169 | |
| 170 | |
| 171 | 4.2) Regular expressions |
| 172 | ------------------------ |
| 173 | HAProxy may make use regular expressions (regex) to match certain patterns. The |
| 174 | regex engine is provided by default in the libc. On some operating systems, it |
| 175 | might happen that the original regex library provided by the libc is too slow, |
| 176 | too limited or even bogus. For example, on older Solaris versions up to 8, the |
| 177 | default regex used not to properly extract group references, without reporting |
| 178 | compilation errors. Also, some early versions of the GNU libc used to include a |
| 179 | regex engine which could be slow or even crash on certain patterns. |
| 180 | |
| 181 | If you plan on importing a particularly heavy configuration involving a lot of |
Ilya Shipitsin | c6ecf56 | 2021-08-07 14:41:56 +0500 | [diff] [blame] | 182 | regex, you may benefit from using some alternative regex implementations such as |
Abhijeet Rastogi | b402450 | 2024-02-07 18:47:42 -0800 | [diff] [blame] | 183 | PCRE. HAProxy natively supports PCRE and PCRE2 (recommended), both in standard |
| 184 | and JIT flavors (Just In Time). The following options are available depending on |
| 185 | the library version provided on your system : |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 186 | |
| 187 | - "USE_PCRE=1" : enable PCRE version 1, dynamic linking |
| 188 | - "USE_STATIC_PCRE=1" : enable PCRE version 1, static linking |
| 189 | - "USE_PCRE_JIT=1" : enable PCRE version 1 in JIT mode |
| 190 | - "USE_PCRE2=1" : enable PCRE version 2, dynamic linking |
| 191 | - "USE_STATIC_PCRE2=1" : enable PCRE version 2, static linking |
| 192 | - "USE_PCRE2_JIT=1" : enable PCRE version 2 in JIT mode |
| 193 | |
| 194 | Both of these libraries may be downloaded from https://www.pcre.org/. |
| 195 | |
| 196 | By default, the include and library paths are figured from the "pcre-config" |
| 197 | and "pcre2-config" utilities. If these ones are not installed or inaccurate |
| 198 | (for example when cross-compiling), it is possible to force the path to include |
| 199 | files using "PCRE_INC" and "PCRE2_INC" respectively, and the path to library |
| 200 | files using "PCRE_LIB" and "PCRE2_LIB" respectively. For example : |
| 201 | |
| 202 | $ make TARGET=generic \ |
| 203 | USE_PCRE2_JIT=1 PCRE2_INC=/opt/cross/include PCRE2_LIB=/opt/cross/lib |
| 204 | |
| 205 | |
| 206 | 4.3) Multi-threading |
| 207 | -------------------- |
| 208 | On some systems for which positive feedback was reported, multi-threading will |
| 209 | be enabled by default. When multi-threading is used, the libpthread library |
| 210 | (POSIX threading) will be used. If the target system doesn't contain such a |
| 211 | library, it is possible to forcefully disable multi-threading by adding |
| 212 | "USE_THREAD=" on the command line. |
| 213 | |
| 214 | |
| 215 | 4.4) Password encryption |
| 216 | ------------------------ |
| 217 | Many systems provide password encryption functions used for authentication. On |
| 218 | some systems these functions are part of the libc. On others, they're part of a |
| 219 | separate library called "libcrypt". The default targets are pre-configured |
| 220 | based on which system needs the library. It is possible to forcefully disable |
| 221 | the linkage against libcrypt by adding "USE_LIBCRYPT=" on the command line, or |
| 222 | to forcefully enable it using "USE_LIBCRYPT=1". |
| 223 | |
| 224 | |
| 225 | 4.5) Cryptography |
| 226 | ----------------- |
| 227 | For SSL/TLS, it is necessary to use a cryptography library. HAProxy currently |
Willy Tarreau | b9ccef2 | 2022-05-08 10:59:00 +0200 | [diff] [blame] | 228 | supports the OpenSSL library, and is known to build and work with branches |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 229 | 0.9.8, 1.0.0, 1.0.1, 1.0.2, 1.1.0 and 1.1.1. OpenSSL follows a long-term |
| 230 | support cycle similar to HAProxy's, and each of the branches above receives its |
| 231 | own fixes, without forcing you to upgrade to another branch. There is no excuse |
| 232 | for staying vulnerable by not applying a fix available for your version. There |
| 233 | is always a small risk of regression when jumping from one branch to another |
| 234 | one, especially when it's very new, so it's preferable to observe for a while |
| 235 | if you use a different version than your system's defaults. |
| 236 | |
| 237 | Two OpenSSL derivatives called LibreSSL and BoringSSL are reported to work as |
| 238 | well. While there are some efforts from the community to ensure they work well, |
| 239 | OpenSSL remains the primary target and this means that in case of conflicting |
| 240 | choices, OpenSSL support will be favored over other options. |
| 241 | |
| 242 | In order to enable SSL/TLS support, simply pass "USE_OPENSSL=1" on the command |
| 243 | line and the default library present on your system will be used : |
| 244 | |
| 245 | $ make TARGET=generic USE_OPENSSL=1 |
| 246 | |
| 247 | If you want to use a different version from the one provided by your system |
| 248 | (which is not recommended due to the risk of missing security fixes), it is |
| 249 | possible to indicate the path to the SSL include files using SSL_INC, and the |
| 250 | SSL library files using SSL_LIB. Example : |
| 251 | |
| 252 | $ make TARGET=generic \ |
| 253 | USE_OPENSSL=1 SSL_INC=/opt/ssl-1.1.1/include SSL_LIB=/opt/ssl-1.1.1/lib |
| 254 | |
| 255 | In order to link OpenSSL statically against HAProxy, first download OpenSSL |
| 256 | from https://www.openssl.org/ then build it with the "no-shared" keyword and |
| 257 | install it to a local directory, so your system is not affected : |
| 258 | |
| 259 | $ export STATICLIBSSL=/tmp/staticlibssl |
| 260 | $ ./config --prefix=$STATICLIBSSL no-shared |
| 261 | $ make && make install_sw |
| 262 | |
| 263 | Then when building haproxy, pass that path via SSL_INC and SSL_LIB : |
| 264 | |
| 265 | $ make TARGET=generic \ |
| 266 | USE_OPENSSL=1 SSL_INC=$STATICLIBSSL/include SSL_LIB=$STATICLIBSSL/lib |
| 267 | |
| 268 | When building with OpenSSL on some systems, you may also need to enable support |
| 269 | for the "libz" library, which is visible if the linker complains about function |
| 270 | "deflateInit()" not being found. In this case, simply append "ADDLIB=-lz" to |
| 271 | the command line. |
| 272 | |
| 273 | It is worth mentioning that asynchronous cryptography engines are supported on |
| 274 | OpenSSL 1.1.0 and above. Such engines are used to access hardware cryptography |
| 275 | acceleration that might be present on your system. |
| 276 | |
| 277 | |
| 278 | 4.6) Compression |
| 279 | ---------------- |
| 280 | HAProxy can compress HTTP responses before delivering them to clients, in order |
| 281 | to save network bandwidth. Two compression options are available. The first one |
Willy Tarreau | 12840be | 2021-04-22 14:14:22 +0200 | [diff] [blame] | 282 | relies on the libslz library (http://libslz.org) that is embedded in haproxy. |
| 283 | It is enabled by default as it is very fast and does not keep a copy of the |
| 284 | contents in memory. It is possible to disable it, for example for very small |
| 285 | systems, by passing "USE_SLZ=" to the "make" command. |
| 286 | |
| 287 | Please note that SLZ will benefit from some CPU-specific instructions like the |
| 288 | availability of the CRC32 extension on some ARM processors. Thus it can further |
Willy Tarreau | 40a871f | 2021-05-12 09:47:30 +0200 | [diff] [blame] | 289 | improve its performance to build with "CPU=native" on the target system, or |
| 290 | "CPU=armv81" (modern systems such as Graviton2 or A55/A75 and beyond), |
| 291 | "CPU=a72" (e.g. for RPi4, or AWS Graviton), "CPU=a53" (e.g. for RPi3), or |
| 292 | "CPU=armv8-auto" (automatic detection with minor runtime penalty). |
Willy Tarreau | 12840be | 2021-04-22 14:14:22 +0200 | [diff] [blame] | 293 | |
| 294 | A second option involves the widely known zlib library, which is very likely |
| 295 | installed on your system. In order to use zlib, simply pass "USE_ZLIB=1" to the |
| 296 | "make" command line, which will also automatically disable SLZ. If the library |
| 297 | is not installed in your default system's path, it is possible to specify the |
| 298 | path to the include files using ZLIB_INC, and the path to the library files |
| 299 | using ZLIB_LIB : |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 300 | |
| 301 | $ make TARGET=generic \ |
| 302 | USE_ZLIB=1 ZLIB_INC=/opt/zlib-1.2.11/include ZLIB_LIB=/opt/zlib-1.2.11/lib |
| 303 | |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 304 | Zlib is commonly found on most systems, otherwise updates can be retrieved from |
| 305 | http://www.zlib.net/. It is easy and fast to build, and new versions sometimes |
Willy Tarreau | 12840be | 2021-04-22 14:14:22 +0200 | [diff] [blame] | 306 | provide better performance so it might be worth using an up-to-date one. |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 307 | |
Willy Tarreau | 12840be | 2021-04-22 14:14:22 +0200 | [diff] [blame] | 308 | Zlib compresses a bit better than libslz but at the expense of more CPU usage |
| 309 | (about 3.5 times more minimum), and a huge memory usage (~260 kB per compressed |
| 310 | stream). The only valid reason for uzing Zlib instead of SLZ here usually is to |
| 311 | deal with a very limited internet bandwidth while CPU and RAM are abundant so |
| 312 | that the last few percent of compression ratio are worth the invested hardware. |
| 313 | |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 314 | |
| 315 | 4.7) Lua |
| 316 | -------- |
Ilya Shipitsin | 2a950d0 | 2020-03-06 13:07:38 +0500 | [diff] [blame] | 317 | Lua is an embedded programming language supported by HAProxy to provide more |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 318 | advanced scripting capabilities. Only versions 5.3 and above are supported. |
| 319 | In order to enable Lua support, please specify "USE_LUA=1" on the command line. |
| 320 | Some systems provide this library under various names to avoid conflicts with |
Christian Ruppert | 09b4e50 | 2022-06-28 10:03:00 +0200 | [diff] [blame] | 321 | previous versions. By default, HAProxy looks for "lua5.4", "lua54", "lua5.3", |
| 322 | "lua53", "lua". If your system uses a different naming, you may need to set the |
| 323 | library name in the "LUA_LIB_NAME" variable. |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 324 | |
| 325 | If Lua is not provided on your system, it can be very simply built locally. It |
| 326 | can be downloaded from https://www.lua.org/, extracted and built, for example : |
| 327 | |
| 328 | $ cd /opt/lua-5.3.5 |
| 329 | $ make linux |
| 330 | |
| 331 | The path to the include files and library files may be set using "LUA_INC" and |
| 332 | "LUA_LIB" respectively. For example : |
| 333 | |
| 334 | $ make TARGET=generic \ |
| 335 | USE_LUA=1 LUA_INC=/opt/lua-5.3.5/src LUA_LIB=/opt/lua-5.3.5/src |
| 336 | |
| 337 | |
| 338 | 4.8) Device detection |
| 339 | --------------------- |
| 340 | HAProxy supports several device detection modules relying on third party |
| 341 | products. Some of them may provide free code, others free libs, others free |
| 342 | evaluation licenses. Please read about their respective details in the |
| 343 | following files : |
| 344 | |
| 345 | doc/DeviceAtlas-device-detection.txt for DeviceAtlas |
| 346 | doc/51Degrees-device-detection.txt for 51Degrees |
Willy Tarreau | b3cc9f2 | 2019-04-19 16:03:32 +0200 | [diff] [blame] | 347 | doc/WURFL-device-detection.txt for Scientiamobile WURFL |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 348 | |
| 349 | |
| 350 | 4.9) Miscellaneous |
| 351 | ------------------ |
| 352 | Some systems have specificities. Usually these specificities are known and/or |
| 353 | detected and properly set for you. If you need to adjust the behaviour, here |
| 354 | are the extra libraries that may be referenced at build time : |
| 355 | |
| 356 | - USE_RT=1 build with librt, which is sometimes needed on some systems |
| 357 | when using threads. It is set by default on Linux platforms, |
| 358 | and may be disabled using "USE_RT=" if your system doesn't |
Willy Tarreau | 4703fdd | 2019-06-16 19:39:44 +0200 | [diff] [blame] | 359 | have one. You may have to set it as well if you face an error |
| 360 | indicating that clock_gettime() was not found. |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 361 | |
| 362 | - USE_DL=1 build with libdl, which is usually needed for Lua and OpenSSL |
| 363 | on Linux. It is automatically detected and may be disabled |
| 364 | using "USE_DL=", though it should never harm. |
| 365 | |
| 366 | - USE_SYSTEMD=1 enables support for the sdnotify features of systemd, |
| 367 | allowing better integration with systemd on Linux systems |
| 368 | which come with it. It is never enabled by default so there |
| 369 | is no need to disable it. |
| 370 | |
Willy Tarreau | 4ced4bd | 2020-07-07 16:17:00 +0200 | [diff] [blame] | 371 | |
Willy Tarreau | 4703fdd | 2019-06-16 19:39:44 +0200 | [diff] [blame] | 372 | 4.10) Common errors |
| 373 | ------------------- |
| 374 | Some build errors may happen depending on the options combinations or the |
| 375 | selected target. When facing build errors, if you know that your system is a |
| 376 | bit special or particularly old, start from TARGET=generic, it is easier to |
| 377 | start from there and fix the remaining issues than trying to degrade another |
| 378 | target. Common issues may include: |
| 379 | |
| 380 | - clock_gettime() not found |
| 381 | => your system needs USE_RT=1 |
| 382 | |
| 383 | - __sync_sub_and_fetch undefined in cache.o |
| 384 | => your system needs either USE_PTHREAD_PSHARED=1 or USE_PRIVATE_CACHE=1 |
| 385 | |
| 386 | - many __sync_<something> errors in many files |
| 387 | => your gcc is too old, build without threads and with private cache. |
| 388 | |
| 389 | - many openssl errors |
| 390 | => your OpenSSL version really is too old, do not enable OpenSSL |
| 391 | |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 392 | |
| 393 | 5) How to build HAProxy |
| 394 | ======================= |
| 395 | |
| 396 | This section assumes that you have already read section 2 (basic principles) |
| 397 | and section 3 (build environment). It often refers to section 4 (dependencies). |
| 398 | |
| 399 | To build haproxy, you have to choose your target OS amongst the following ones |
| 400 | and assign it to the TARGET variable : |
| 401 | |
Lukas Tribus | cc1eb16 | 2019-09-01 16:48:36 +0200 | [diff] [blame] | 402 | - linux-glibc for Linux kernel 2.6.28 and above |
| 403 | - linux-glibc-legacy for Linux kernel 2.6.28 and above without new features |
Willy Tarreau | 39b2fda | 2020-04-16 15:14:17 +0200 | [diff] [blame] | 404 | - linux-musl for Linux kernel 2.6.28 and above with musl libc |
Brad Smith | 7c503bb | 2020-09-30 15:46:16 -0400 | [diff] [blame] | 405 | - solaris for Solaris 10 and above |
Brad Smith | 3f1977c | 2020-10-02 18:36:58 -0400 | [diff] [blame] | 406 | - freebsd for FreeBSD 10 and above |
Brad Smith | 382001b | 2020-10-08 01:15:06 -0400 | [diff] [blame] | 407 | - dragonfly for DragonFlyBSD 4.3 and above |
Brad Smith | 0fdfe41 | 2020-10-08 16:24:52 -0400 | [diff] [blame] | 408 | - netbsd for NetBSD 8 and above |
Lukas Tribus | cc1eb16 | 2019-09-01 16:48:36 +0200 | [diff] [blame] | 409 | - osx for Mac OS/X |
Brad Smith | 3f1977c | 2020-10-02 18:36:58 -0400 | [diff] [blame] | 410 | - openbsd for OpenBSD 6.3 and above |
Lukas Tribus | cc1eb16 | 2019-09-01 16:48:36 +0200 | [diff] [blame] | 411 | - aix51 for AIX 5.1 |
| 412 | - aix52 for AIX 5.2 |
Christian Lachner | c132230 | 2020-02-10 10:29:13 +0100 | [diff] [blame] | 413 | - aix72-gcc for AIX 7.2 (using gcc) |
Lukas Tribus | cc1eb16 | 2019-09-01 16:48:36 +0200 | [diff] [blame] | 414 | - cygwin for Cygwin |
| 415 | - haiku for Haiku |
| 416 | - generic for any other OS or version. |
| 417 | - custom to manually adjust every setting |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 418 | |
| 419 | You may also choose your CPU to benefit from some optimizations. This is |
| 420 | particularly important on UltraSparc machines. For this, you can assign |
| 421 | one of the following choices to the CPU variable : |
| 422 | |
| 423 | - i686 for intel PentiumPro, Pentium 2 and above, AMD Athlon (32 bits) |
| 424 | - i586 for intel Pentium, AMD K6, VIA C3. |
| 425 | - ultrasparc : Sun UltraSparc I/II/III/IV processor |
Christian Lachner | c132230 | 2020-02-10 10:29:13 +0100 | [diff] [blame] | 426 | - power8 : IBM POWER8 processor |
| 427 | - power9 : IBM POWER9 processor |
Willy Tarreau | 40a871f | 2021-05-12 09:47:30 +0200 | [diff] [blame] | 428 | - armv81 : modern ARM cores (Cortex A55/A75/A76/A78/X1, Neoverse, Graviton2) |
| 429 | - a72 : ARM Cortex-A72 or A73 (e.g. RPi4, Odroid N2, AWS Graviton) |
| 430 | - a53 : ARM Cortex-A53 or any of its successors in 64-bit mode (e.g. RPi3) |
| 431 | - armv8-auto : support both older and newer armv8 cores with a minor penalty, |
| 432 | thanks to gcc 10's outline atomics (default with gcc 10.2). |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 433 | - native : use the build machine's specific processor optimizations. Use with |
| 434 | extreme care, and never in virtualized environments (known to break). |
| 435 | - generic : any other processor or no CPU-specific optimization. (default) |
| 436 | |
| 437 | Alternatively, you may just set the CPU_CFLAGS value to the optimal GCC options |
| 438 | for your platform. A second variable named SMALL_OPTS also supports passing a |
| 439 | number of defines and compiler options usually for small systems. For better |
| 440 | clarity it's recommended to pass the options which result in a smaller binary |
| 441 | (like memory limits or -Os) into this variable. |
| 442 | |
| 443 | If you are building for a different system than the one you're building on, |
| 444 | this is called "cross-compiling". HAProxy supports cross-compilation pretty |
| 445 | well and tries to ease it by letting you adjust paths to all libraries (please |
| 446 | read section 4 on dependencies for more details). When cross-compiling, you |
| 447 | just need to pass the path to your compiler in the "CC" variable, and the path |
| 448 | to the linker in the "LD" variable. Most of the time, setting the CC variable |
| 449 | is enough since LD points to it by default. |
| 450 | |
| 451 | By default the build process runs in quiet mode and hide the details of the |
| 452 | commands that are executed. This allows to more easily catch build warnings |
| 453 | and see what is happening. However it is not convenient at all to observe what |
| 454 | flags are passed to the compiler nor what compiler is involved. Simply append |
| 455 | "V=1" to the "make" command line to switch to verbose mode and display the |
| 456 | details again. It is recommended to use this option when cross-compiling to |
| 457 | verify that the paths are correct and that /usr/include is never invovled. |
| 458 | |
| 459 | You may want to build specific target binaries which do not match your native |
| 460 | compiler's target. This is particularly true on 64-bit systems when you want |
| 461 | to build a 32-bit binary. Use the ARCH variable for this purpose. Right now |
| 462 | it only knows about a few x86 variants (i386,i486,i586,i686,x86_64), two |
| 463 | generic ones (32,64) and sets -m32/-m64 as well as -march=<arch> accordingly. |
| 464 | This variable is only used to set ARCH_FLAGS to preset values, so if you know |
| 465 | the arch-specific flags that your system needs, you may prefer to set |
| 466 | ARCH_FLAGS instead. Note that these flags are passed both to the compiler and |
| 467 | to the linker. For example, in order to build a 32-bit binary on an x86_64 |
| 468 | Linux system with SSL support without support for compression but when OpenSSL |
| 469 | requires ZLIB anyway : |
| 470 | |
Willy Tarreau | d254aa8 | 2019-06-14 18:40:48 +0200 | [diff] [blame] | 471 | $ make TARGET=linux-glibc ARCH=i386 USE_OPENSSL=1 ADDLIB=-lz |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 472 | |
| 473 | Recent systems can resolve IPv6 host names using getaddrinfo(). This primitive |
| 474 | is not present in all libcs and does not work in all of them either. Support in |
| 475 | glibc was broken before 2.3. Some embedded libs may not properly work either, |
| 476 | thus, support is disabled by default, meaning that some host names which only |
| 477 | resolve as IPv6 addresses will not resolve and configs might emit an error |
| 478 | during parsing. If you know that your OS libc has reliable support for |
| 479 | getaddrinfo(), you can add USE_GETADDRINFO=1 on the make command line to enable |
| 480 | it. This is the recommended option for most Linux distro packagers since it's |
| 481 | working fine on all recent mainstream distros. It is automatically enabled on |
| 482 | Solaris 8 and above, as it's known to work. |
| 483 | |
| 484 | If your system supports PCRE (Perl Compatible Regular Expressions), then you |
| 485 | really should build with libpcre which is between 2 and 10 times faster than |
| 486 | other libc implementations. Regex are used for header processing (deletion, |
| 487 | rewriting, allow, deny). Please see section 4 about dependencies to figure |
| 488 | how to build with PCRE support. |
| 489 | |
| 490 | It is possible to add native support for SSL, by passing "USE_OPENSSL=1" on the |
| 491 | make command line. The libssl and libcrypto will automatically be linked with |
| 492 | HAProxy. Some systems also require libz, so if the build fails due to missing |
| 493 | symbols such as deflateInit(), then try again with "ADDLIB=-lz". Please check |
| 494 | section 4 about dependencies for more information on how to build with OpenSSL. |
| 495 | |
| 496 | HAProxy can compress HTTP responses to save bandwidth. Please see section 4 |
| 497 | about dependencies to see the available libraries and associated options. |
| 498 | |
| 499 | By default, the DEBUG variable is set to '-g' to enable debug symbols. It is |
| 500 | not wise to disable it on uncommon systems, because it's often the only way to |
| 501 | get a usable core when you need one. Otherwise, you can set DEBUG to '-s' to |
| 502 | strip the binary. |
| 503 | |
| 504 | If the ERR variable is set to any non-empty value, then -Werror will be added |
| 505 | to the compiler so that any build warning will trigger an error. This is the |
| 506 | recommended way to build when developing, and it is expected that contributed |
| 507 | patches were tested with ERR=1. |
| 508 | |
| 509 | The SSL stack supports session cache synchronization between all running |
| 510 | processes. This involves some atomic operations and synchronization operations |
| 511 | which come in multiple flavors depending on the system and architecture : |
| 512 | |
| 513 | Atomic operations : |
| 514 | - internal assembler versions for x86/x86_64 architectures |
| 515 | |
| 516 | - gcc builtins for other architectures. Some architectures might not |
| 517 | be fully supported or might require a more recent version of gcc. |
| 518 | If your architecture is not supported, you willy have to either use |
| 519 | pthread if supported, or to disable the shared cache. |
| 520 | |
| 521 | - pthread (posix threads). Pthreads are very common but inter-process |
| 522 | support is not that common, and some older operating systems did not |
| 523 | report an error when enabling multi-process mode, so they used to |
| 524 | silently fail, possibly causing crashes. Linux's implementation is |
| 525 | fine. OpenBSD doesn't support them and doesn't build. FreeBSD 9 builds |
| 526 | and reports an error at runtime, while certain older versions might |
| 527 | silently fail. Pthreads are enabled using USE_PTHREAD_PSHARED=1. |
| 528 | |
| 529 | Synchronization operations : |
| 530 | - internal spinlock : this mode is OS-independent, light but will not |
| 531 | scale well to many processes. However, accesses to the session cache |
| 532 | are rare enough that this mode could certainly always be used. This |
| 533 | is the default mode. |
| 534 | |
| 535 | - Futexes, which are Linux-specific highly scalable light weight mutexes |
| 536 | implemented in user-space with some limited assistance from the kernel. |
| 537 | This is the default on Linux 2.6 and above and is enabled by passing |
| 538 | USE_FUTEX=1 |
| 539 | |
| 540 | - pthread (posix threads). See above. |
| 541 | |
| 542 | If none of these mechanisms is supported by your platform, you may need to |
| 543 | build with USE_PRIVATE_CACHE=1 to totally disable SSL cache sharing. Then it |
| 544 | is better not to run SSL on multiple processes. Note that you don't need these |
| 545 | features if you only intend to use multi-threading and never multi-process. |
| 546 | |
| 547 | If you need to pass other defines, includes, libraries, etc... then please |
| 548 | check the Makefile to see which ones will be available in your case, and |
| 549 | use/override the USE_* variables from the Makefile. |
| 550 | |
| 551 | AIX 5.3 is known to work with the generic target. However, for the binary to |
| 552 | also run on 5.2 or earlier, you need to build with DEFINE="-D_MSGQSUPPORT", |
| 553 | otherwise __fd_select() will be used while not being present in the libc, but |
| 554 | this is easily addressed using the "aix52" target. If you get build errors |
| 555 | because of strange symbols or section mismatches, simply remove -g from |
| 556 | DEBUG_CFLAGS. |
| 557 | |
Christian Lachner | c132230 | 2020-02-10 10:29:13 +0100 | [diff] [blame] | 558 | Building on AIX 7.2 works fine using the "aix72-gcc" TARGET. It adds two |
Thayne McCombs | cdbcca9 | 2021-01-07 21:24:41 -0700 | [diff] [blame] | 559 | special CFLAGS to prevent the loading of AIX's xmem.h and var.h. This is done |
Christian Lachner | c132230 | 2020-02-10 10:29:13 +0100 | [diff] [blame] | 560 | by defining the corresponding include-guards _H_XMEM and _H_VAR. Without |
| 561 | excluding those header-files the build fails because of redefinition errors. |
Ilya Shipitsin | 2a950d0 | 2020-03-06 13:07:38 +0500 | [diff] [blame] | 562 | Furthermore, the atomic library is added to the LDFLAGS to allow for |
Christian Lachner | c132230 | 2020-02-10 10:29:13 +0100 | [diff] [blame] | 563 | multithreading via USE_THREAD. |
| 564 | |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 565 | You can easily define your own target with the GNU Makefile. Unknown targets |
| 566 | are processed with no default option except USE_POLL=default. So you can very |
Willy Tarreau | 12840be | 2021-04-22 14:14:22 +0200 | [diff] [blame] | 567 | well use that property to define your own set of options. USE_POLL and USE_SLZ |
| 568 | can even be disabled by setting them to an empty string. For example : |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 569 | |
Willy Tarreau | 12840be | 2021-04-22 14:14:22 +0200 | [diff] [blame] | 570 | $ gmake TARGET=tiny USE_POLL="" USE_SLZ="" TARGET_CFLAGS=-fomit-frame-pointer |
Willy Tarreau | 7f33273 | 2018-12-16 22:27:15 +0100 | [diff] [blame] | 571 | |
| 572 | If you need to pass some defines to the preprocessor or compiler, you may pass |
| 573 | them all in the DEFINE variable. Example: |
| 574 | |
| 575 | $ make TARGET=generic DEFINE="-DDEBUG_DONT_SHARE_POOLS -DDEBUG_MEMORY_POOLS" |
| 576 | |
| 577 | The ADDINC variable may be used to add some extra include paths; this is |
| 578 | sometimes needed when cross-compiling. Similarly the ADDLIB variable may be |
| 579 | used to specifify extra paths to library files. Example : |
| 580 | |
| 581 | $ make TARGET=generic ADDINC=-I/opt/cross/include ADDLIB=-L/opt/cross/lib64 |
| 582 | |
| 583 | |
| 584 | 6) How to install HAProxy |
| 585 | ========================= |
| 586 | |
| 587 | To install haproxy, you can either copy the single resulting binary to the |
| 588 | place you want, or run : |
| 589 | |
| 590 | $ sudo make install |
| 591 | |
| 592 | If you're packaging it for another system, you can specify its root directory |
| 593 | in the usual DESTDIR variable. |
| 594 | |
| 595 | -- end |