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