]> granicus.if.org Git - icinga2/blob - INSTALL.md
Merge pull request #6313 from Icinga/fix/win-check-swap
[icinga2] / INSTALL.md
1 # Installing Icinga 2
2
3 The recommended way of installing Icinga 2 is to use [packages](https://packages.icinga.com).
4 The Icinga project provides both release and development packages for a number
5 of operating systems.
6
7 Please check the documentation in the [doc/](doc/) directory for a current list
8 of available packages and detailed installation instructions.
9
10 The online documentation is available on [icinga.com/docs](https://www.icinga.com/docs/)
11 and will guide you step by step.
12
13 There are a number of known caveats when installing from source such as
14 incorrect directory and file permissions. So even if you're planning to
15 not use the official packages it is advisable to build your own Debian
16 or RPM packages. You can use the source packages from [packages.icinga.com](https://packages.icinga.com)
17 for this purpose.
18
19 > **Disclaimer**
20 >
21 > This information is intended for developers and packagers. It might be incomplete or unclear
22 > in some cases. Ensure to check our [packaging scripts on GitHub](https://github.com/Icinga/icinga-packaging) too!
23
24 # Build Requirements
25
26 The following requirements need to be fulfilled in order to build the
27 application using a dist tarball (including notes for distributions):
28
29 * cmake >= 2.6
30 * GNU make (make) or ninja-build
31 * C++ compiler which supports C++11
32   - RHEL/Fedora/SUSE: gcc-c++ >= 4.7 (extra Developer Tools on RHEL5/6 see below)
33   - Debian/Ubuntu: build-essential
34   - Alpine: build-base
35   - you can also use clang++
36 * pkg-config
37 * OpenSSL library and header files >= 1.0.1
38   - RHEL/Fedora: openssl-devel
39   - SUSE: libopenssl-devel (for SLES 11: libopenssl1-devel)
40   - Debian/Ubuntu: libssl-dev
41   - Alpine: libressl-dev
42 * Boost library and header files >= 1.48.0
43   - RHEL/Fedora: boost148-devel
44   - Debian/Ubuntu: libboost-all-dev
45   - Alpine: boost-dev
46 * GNU bison (bison)
47 * GNU flex (flex) >= 2.5.35
48 * Systemd headers
49   - Only required when using Systemd
50   - Debian/Ubuntu: libsystemd-dev
51   - RHEL/Fedora: systemd-devel
52
53 ## Optional features
54
55 * MySQL (disable with CMake variable `ICINGA2_WITH_MYSQL` to `OFF`)
56   - RHEL/Fedora: mysql-devel
57   - SUSE: libmysqlclient-devel
58   - Debian/Ubuntu: default-libmysqlclient-dev | libmysqlclient-dev
59   - Alpine: mariadb-dev
60 * PostgreSQL (disable with CMake variable `ICINGA2_WITH_PGSQL` to `OFF`)
61   - RHEL/Fedora: postgresql-devel
62   - Debian/Ubuntu: libpq-dev
63   - postgresql-dev on Alpine
64 * YAJL (Faster JSON library)
65   - RHEL/Fedora: yajl-devel
66   - Debian: libyajl-dev
67   - Alpine: yajl-dev
68 * libedit (CLI console)
69   - RHEL/Fedora: libedit-devel on CentOS (RHEL requires rhel-7-server-optional-rpms)
70   - Debian/Ubuntu/Alpine: libedit-dev
71 * Termcap (only required if libedit doesn't already link against termcap/ncurses)
72   - RHEL/Fedora: libtermcap-devel
73   - Debian/Ubuntu: (not necessary)
74
75 ## Special requirements
76
77 **FreeBSD**: libexecinfo (automatically used when Icinga 2 is installed via port or package)
78
79 **RHEL6**: Requires a newer boost version which is available on packages.icinga.com
80 with a version suffixed name.
81
82 ## Runtime user environment
83
84 By default Icinga will run as user `icinga` and group `icinga`. Additionally the
85 external command pipe and livestatus features require a dedicated command group
86 `icingacmd`. You can choose your own user/group names and pass them to CMake
87 using the `ICINGA2_USER`, `ICINGA2_GROUP` and `ICINGA2_COMMAND_GROUP` variables.
88
89 ```
90 # groupadd icinga
91 # groupadd icingacmd
92 # useradd -c "icinga" -s /sbin/nologin -G icingacmd -g icinga icinga
93 ```
94
95 On Alpine (which uses ash busybox) you can run:
96
97 ```
98 # addgroup -S icinga
99 # addgroup -S icingacmd
100 # adduser -S -D -H -h /var/spool/icinga2 -s /sbin/nologin -G icinga -g icinga icinga
101 # adduser icinga icingacmd
102 ```
103
104 Add the web server user to the icingacmd group in order to grant it write
105 permissions to the external command pipe and livestatus socket:
106 ```
107 # usermod -a -G icingacmd www-data
108 ```
109
110 Make sure to replace "www-data" with the name of the user your web server
111 is running as.
112
113 # Building Icinga 2
114
115 Once you have installed all the necessary build requirements you can build
116 Icinga 2 using the following commands:
117
118 ```
119 $ mkdir release && cd release
120 $ cmake ..
121 $ cd ..
122 $ make -C release
123 $ make install -C release
124 ```
125
126 You can specify an alternative installation prefix using `-DCMAKE_INSTALL_PREFIX`:
127
128 ```
129 $ cmake .. -DCMAKE_INSTALL_PREFIX=/tmp/icinga2
130 ```
131
132 ## CMake Variables
133
134 In addition to `CMAKE_INSTALL_PREFIX` here are most of the supported Icinga-specific cmake variables.
135
136 For all variables regarding defaults paths on in CMake, see
137 [GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html).
138
139 Also see `CMakeLists.txt` for details.
140
141 **System Environment**
142 - `CMAKE_INSTALL_SYSCONFDIR`: The configuration directory; defaults to `CMAKE_INSTALL_PREFIX/etc`
143 - `CMAKE_INSTALL_LOCALSTATEDIR`: The state directory; defaults to `CMAKE_INSTALL_PREFIX/var`
144 - `ICINGA2_CONFIGDIR`: Main config directory; defaults to `CMAKE_INSTALL_SYSCONFDIR/icinga2` usually `/etc/icinga2`
145 - `ICINGA2_CACHEDIR`: Directory for cache files; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/cache/icinga2` usually `/var/cache/icinga2`
146 - `ICINGA2_DATADIR`: Data directory  for the daemon; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/lib/icinga2` usually `/var/lib/icinga2`
147 - `ICINGA2_LOGDIR`: Logfiles of the daemon; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/log/icinga2 usually `/var/log/icinga2`
148 - `ICINGA2_SPOOLDIR`: Spooling directory ; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/spool/icinga2` usually `/var/spool/icinga2`
149 - `ICINGA2_INITRUNDIR`: Runtime data for the init system; defaults to `CMAKE_INSTALL_LOCALSTATEDIR/run/icinga2` usually `/run/icinga2`
150 - `ICINGA2_GIT_VERSION_INFO`: Whether to use Git to determine the version number; defaults to `ON`
151 - `ICINGA2_USER`: The user Icinga 2 should run as; defaults to `icinga`
152 - `ICINGA2_GROUP`: The group Icinga 2 should run as; defaults to `icinga`
153 - `ICINGA2_COMMAND_GROUP`: The command group Icinga 2 should use; defaults to `icingacmd`
154 - `ICINGA2_SYSCONFIGFILE`: Where to put the config file the initscript/systemd pulls it's dirs from;
155   defaults to `CMAKE_INSTALL_PREFIX/etc/sysconfig/icinga2`
156 - `ICINGA2_PLUGINDIR`: The path for the Monitoring Plugins project binaries; defaults to `/usr/lib/nagios/plugins`
157
158 **Build Optimization**
159 - `ICINGA2_UNITY_BUILD`: Whether to perform a unity build; defaults to `ON`. Note: This requires additional memory and is not advised for building VMs, Docker for Mac and embedded hardware.
160 - `ICINGA2_LTO_BUILD`: Whether to use link time optimization (LTO); defaults to `OFF`
161
162 **Init System**
163 - `USE_SYSTEMD=ON|OFF`: Use systemd or a classic SysV initscript; defaults to `OFF`
164 - `INSTALL_SYSTEMD_SERVICE_AND_INITSCRIPT=ON|OFF` Force install both the systemd service definition file
165   and the SysV initscript in parallel, regardless of how `USE_SYSTEMD` is set.
166   Only use this for special packaging purposes and if you know what you are doing.
167   Defaults to `OFF`.
168
169 **Features:**
170 - `ICINGA2_WITH_CHECKER`: Determines whether the checker module is built; defaults to `ON`
171 - `ICINGA2_WITH_COMPAT`: Determines whether the compat module is built; defaults to `ON`
172 - `ICINGA2_WITH_DEMO`: Determines whether the demo module is built; defaults to `OFF`
173 - `ICINGA2_WITH_HELLO`: Determines whether the hello module is built; defaults to `OFF`
174 - `ICINGA2_WITH_LIVESTATUS`: Determines whether the Livestatus module is built; defaults to `ON`
175 - `ICINGA2_WITH_NOTIFICATION`: Determines whether the notification module is built; defaults to `ON`
176 - `ICINGA2_WITH_PERFDATA`: Determines whether the perfdata module is built; defaults to `ON`
177 - `ICINGA2_WITH_TESTS`: Determines whether the unit tests are built; defaults to `ON`
178
179 **MySQL or MariaDB:**
180
181 The following settings can be tuned for the MySQL / MariaDB IDO feature.
182
183 - `ICINGA2_WITH_MYSQL`: Determines whether the MySQL IDO module is built; defaults to `ON`
184 - `MYSQL_CLIENT_LIBS`: Client implementation used (mysqlclient / mariadbclient); defaults searches for `mysqlclient` and `mariadbclient`
185 - `MYSQL_INCLUDE_DIR`: Directory containing include files for the mysqlclient; default empty -
186   checking multiple paths like `/usr/include/mysql`
187
188 See [FindMySQL.cmake](third-party/cmake/FindMySQL.cmake) for the implementation.
189
190 **PostgreSQL:**
191
192 The following settings can be tuned for the PostgreSQL IDO feature.
193
194 - `ICINGA2_WITH_PGSQL`: Determines whether the PostgreSQL IDO module is built; defaults to `ON`
195 - `PostgreSQL_INCLUDE_DIR`: Top-level directory containing the PostgreSQL include directories
196 - `PostgreSQL_LIBRARY`: File path to PostgreSQL library : libpq.so (or libpq.so.[ver] file)
197
198 See [FindMySQL.cmake](third-party/cmake/FindPostgreSQL.cmake) for the implementation.
199
200 **Version detection:**
201
202 CMake determines the Icinga 2 version number using `git describe` if the
203 source directory is contained in a Git repository. Otherwise the version number
204 is extracted from the [VERSION](VERSION) file. This behavior can be
205 overridden by creating a file called `icinga-version.h.force` in the source
206 directory. Alternatively the `-DICINGA2_GIT_VERSION_INFO=OFF` option for CMake
207 can be used to disable the usage of `git describe`.
208
209 # Building packages
210
211 > **WARNING:** Some of this information is outdated!
212
213 ## Building RPMs
214
215 ### Build Environment on RHEL, CentOS, Fedora, Amazon Linux
216
217 Setup your build environment:
218 ```
219 yum -y install rpmdevtools
220 ```
221
222 ### Build Environment on SuSE/SLES
223
224 SLES:
225 ```
226 zypper addrepo http://download.opensuse.org/repositories/devel:tools/SLE_12_SP2/devel:tools.repo
227 zypper refresh
228 zypper install rpmdevtools spectool
229 ```
230
231 OpenSuSE:
232 ```
233 zypper addrepo http://download.opensuse.org/repositories/devel:tools/openSUSE_Leap_42.3/devel:tools.repo
234 zypper refresh
235 zypper install rpmdevtools spectool
236 ```
237
238 ### Package Builds
239
240 Prepare the rpmbuild directory tree:
241 ```
242 cd $HOME
243 rpmdev-setuptree
244 ```
245
246 Copy the icinga2.spec file to `rpmbuild/SPEC` or fetch the latest version:
247 ```
248 curl https://raw.githubusercontent.com/Icinga/rpm-icinga2/master/icinga2.spec -o $HOME/rpmbuild/SPECS/icinga2.spec
249 ```
250
251 > **Note**
252 >
253 > The above command builds snapshot packages. Change to the `release` branch
254 > for release package builds.
255
256 Copy the tarball to `rpmbuild/SOURCES` e.g. by using the `spectool` binary
257 provided with `rpmdevtools`:
258 ```
259 cd $HOME/rpmbuild/SOURCES
260 spectool -g ../SPECS/icinga2.spec
261
262 cd $HOME/rpmbuild
263 ```
264
265 Install the build dependencies. Example for CentOS 7:
266 ```
267 yum -y install libedit-devel ncurses-devel gcc-c++ libstdc++-devel openssl-devel \
268 cmake flex bison boost-devel systemd mysql-devel postgresql-devel httpd \
269 selinux-policy-devel checkpolicy selinux-policy selinux-policy-doc
270 ```
271
272 Note: If you are using Amazon Linux, systemd is not required.
273
274 A shorter way is available using the `yum-builddep` command on RHEL based systems:
275 ```
276 yum-builddep SPECS/icinga2.spec
277 ```
278
279 Build the RPM:
280 ```
281 rpmbuild -ba SPECS/icinga2.spec
282 ```
283
284 ### Additional Hints
285
286 #### SELinux policy module
287
288 The following packages are required to build the SELinux policy module:
289
290 * checkpolicy
291 * selinux-policy (selinux-policy on CentOS 6, selinux-policy-devel on CentOS 7)
292 * selinux-policy-doc
293
294 #### RHEL/CentOS 6
295
296 The RedHat Developer Toolset is required for building Icinga 2 beforehand.
297 This contains a modern version of flex and a C++ compiler which supports
298 C++11 features.
299 ```
300 cat >/etc/yum.repos.d/devtools-2.repo <<REPO
301 [testing-devtools-2-centos-\$releasever]
302 name=testing 2 devtools for CentOS $releasever
303 baseurl=https://people.centos.org/tru/devtools-2/\$releasever/\$basearch/RPMS
304 gpgcheck=0
305 REPO
306 ```
307
308 Dependencies to devtools-2 are used in the RPM SPEC, so the correct tools
309 should be used for building.
310
311 As an alternative, you can use newer Boost packages provided on
312 [packages.icinga.com](https://packages.icinga.com/epel).
313 ```
314 cat >$HOME/.rpmmacros <<MACROS
315 %build_icinga_org 1
316 MACROS
317 ```
318
319 #### Amazon Linux
320
321 If you prefer to build packages offline, a suitable Vagrant box is located
322 [here](https://atlas.hashicorp.com/mvbcoding/boxes/awslinux/).
323
324 #### SLES 11
325
326 The Icinga repository provides the required boost package version and must be
327 added before building.
328
329 ## Build Debian/Ubuntu packages
330
331 > **WARNING:** This information is outdated!
332
333 Setup your build environment on Debian/Ubuntu, copy the 'debian' directory from
334 the Debian packaging Git repository (https://github.com/Icinga/deb-icinga2)
335 into your source tree and run the following command:
336 ```
337 $ dpkg-buildpackage -uc -us
338 ```
339
340 ## Build Alpine Linux packages
341
342 A simple way to setup a build environment is installing Alpine in a chroot.
343 In this way, you can set up an Alpine build environment in a chroot under a
344 different Linux distro.
345 There is a script that simplifies these steps with just two commands, and
346 can be found [here](https://github.com/alpinelinux/alpine-chroot-install).
347
348 Once the build environment is installed, you can setup the system to build
349 the packages by following [this document](https://wiki.alpinelinux.org/wiki/Creating_an_Alpine_package).
350
351 # Build Post Install Tasks
352
353 After building Icinga 2 yourself, your package build system should at least run the following post
354 install requirements:
355
356 * enable the `checker`, `notification` and `mainlog` feature by default
357 * run 'icinga2 api setup' in order to enable the `api` feature and generate SSL certificates for the node
358
359 ## Run Icinga 2
360
361 Icinga 2 comes with a binary that takes care of loading all the relevant
362 components (e.g. for check execution, notifications, etc.):
363 ```
364 # icinga2 daemon
365 [2016-12-08 16:44:24 +0100] information/cli: Icinga application loader (version: v2.5.4-231-gb10a6b7; debug)
366 [2016-12-08 16:44:24 +0100] information/cli: Loading configuration file(s).
367 [2016-12-08 16:44:25 +0100] information/ConfigItem: Committing config item(s).
368 ...
369 ```
370
371 ### Init Script
372
373 Icinga 2 can be started as a daemon using the provided init script:
374 ```
375 # /etc/init.d/icinga2
376 Usage: /etc/init.d/icinga2 {start|stop|restart|reload|checkconfig|status}
377 ```
378
379 ### Systemd
380
381 If your distribution uses Systemd:
382 ```
383 # systemctl {start|stop|reload|status|enable|disable} icinga2
384 ```
385
386 In case the distribution is running Systemd >227, you'll also
387 need to package and install the `etc/initsystem/icinga2.service.limits.conf`
388 file into `/etc/systemd/system/icinga2.service.d`.
389
390 ### openrc
391
392 Or if your distribution uses openrc (like Alpine):
393 ```
394 # rc-service icinga2
395 Usage: /etc/init.d/icinga2 {start|stop|restart|reload|checkconfig|status}
396   ```
397
398 Note: the openrc's init.d is not shipped by default.
399 A working init.d with openrc can be found here: (https://git.alpinelinux.org/cgit/aports/plain/community/icinga2/icinga2.initd). If you have customized some path, edit the file and adjust it according with your setup.
400 Those few steps can be followed:
401 ```
402 # wget https://git.alpinelinux.org/cgit/aports/plain/community/icinga2/icinga2.initd
403 # mv icinga2.initd /etc/init.d/icinga2
404 # chmod +x /etc/init.d/icinga2
405 ```
406
407 Icinga 2 reads a single configuration file which is used to specify all
408 configuration settings (global settings, hosts, services, etc.). The
409 configuration format is explained in detail in the [doc/](doc/) directory.
410
411 By default `make install` installs example configuration files in
412 `/usr/local/etc/icinga2` unless you have specified a different prefix or
413 sysconfdir.