| by Arround The Web | No comments

Installing Nagios on Centos 7


Nagios is an extremely popular open source monitoring and alerting tool. The name nagios is an offshoot of an older system called ‘net saint’. Although Nagios has it’s limits and is not an all in one solution but provides a considerable feature set nonetheless. The monitoring platform is available in two variants: Nagios core which is the open source and free variant and Nagios XI which is the enterprise version. In this article we will demonstrate step by step how to install the latest version of Nagios core on a Centos 7 system.

Step 1: Install prerequisites for Nagios
Nagios requires a web server like apache or nginx and it also requires php for some of its’ functionality. We will be installing Nagios from source and will therefore require some packages to help us compile Nagios core from source and install it. The dependencies could be installed using the following yum command.

[ssuri@linuxnix:~] $ sudo yum install gcc glibc glibc-common gd gd-devel make net-snmp openssl-devel xinetd unzip -y
Loaded plugins: langpacks, rhnplugin
This system is receiving updates from RHN Classic or Red Hat Satellite.
Package gcc-4.8.5-28.el7_5.1.x86_64 already installed and latest version
Package glibc-2.17-222.el7.x86_64 already installed and latest version
Package glibc-common-2.17-222.el7.x86_64 already installed and latest version
Package gd-2.0.35-26.el7.x86_64 already installed and latest version
Package 1:make-3.82-23.el7.x86_64 already installed and latest version
Package 1:net-snmp-5.7.2-33.el7_5.2.x86_64 already installed and latest version
Package unzip-6.0-19.el7.x86_64 already installed and latest version
Resolving Dependencies
---------------------------------output truncated for brevity
gd-devel.x86_64 0:2.0.35-26.el7 openssl-devel.x86_64 1:1.0.2k-12.el7 xinetd.x86_64 2:2.3.15-13.el7 

Dependency Installed:
expat-devel.x86_64 0:2.1.0-10.el7_3 fontconfig-devel.x86_64 0:2.10.95-11.el7 freetype-devel.x86_64 0:2.4.11-15.el7 keyutils-libs-devel.x86_64 0:1.5.8-3.el7 
krb5-devel.x86_64 0:1.15.1-19.el7 libX11-devel.x86_64 0:1.6.5-1.el7 libXau-devel.x86_64 0:1.0.8-2.1.el7 libXpm-devel.x86_64 0:3.5.12-1.el7 
libcom_err-devel.x86_64 0:1.42.9-12.el7_5 libjpeg-turbo-devel.x86_64 0:1.2.90-5.el7 libpng-devel.x86_64 2:1.5.13-7.el7_2 libselinux-devel.x86_64 0:2.5-12.el7 
libsepol-devel.x86_64 0:2.5-8.1.el7 libverto-devel.x86_64 0:0.2.5-4.el7 libxcb-devel.x86_64 0:1.12-1.el7 pcre-devel.x86_64 0:8.32-17.el7 
xorg-x11-proto-devel.noarch 0:7.7-20.el7 zlib-devel.x86_64 0:1.2.7-17.el7 



Step 2: Create Nagios user and group
We must create a user and group that will run the Nagios process. Create a “nagios” user and “nagcmd” group, then add the user to the group with these commands:

sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios

Step 3: Install Nagios core
The Centos 7 EPEL repository generally does not have RPMs for the latest release of Nagios at a given point in time.
We will therefore download the latest version of Nagios and compile and build it from source code. As of this writting the latesrt version of Nagios core available is 4.4.2. We will download it using the curl command as shown below.

[ssuri@linuxnix:~] $ curl -L -O https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz?__hstc=118811158.7cd8ac3f198c0d8870295ba37c1e469c.1538750369927.1538750 
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
50 10.7M 50 5584k 0 0 10.0M 0 0:00:01 --:--:-- 0:00:01 10.0M
100 10.7M 100 10.7M 0 0 16.1M 0 --:--:-- --:--:-- --:--:-- 16.1M
Now let's extract the downloaded file using the tar command.
[ssuri@linuxnix:~] $ tar -xvf nagios-4.4.2.tar.gz 
------------------------------output truncated for brevity
[ssuri@linuxnix:~] $ cd nagios-4.4.2/
[ssuri@linuxnix:~/nagios-4.4.2] $ ls
aclocal.m4 Changelog configure docs include install-sh Makefile.in nagios.spec sample-config tap update-version
autoconf-macros common configure.ac doxy.conf indent-all.sh LEGAL make-tarball nagios.sysconfig startup test UPGRADING
base config.guess contrib functions indent.sh lib mkpackage pkginfo.in subst.in THANKS worker
cgi config.sub CONTRIBUTING.md html INSTALLING LICENSE module README.md t t-tap xdata

Now we will configure Nagios using the configure script provides with the source code.

[ssuri@linuxnix:~/nagios-4.4.2] $ ./configure --with-command-group=nagiossudo 
checking for a BSD-compatible install... /usr/bin/install -c
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether make sets $(MAKE)... yes
------------------------------output truncated for brevity
Creating sample config files in sample-config/ ...

*** Configuration summary for nagios 4.4.2 2018-08-16 ***:

General Options:
Nagios executable: nagios
Nagios user/group: nagios,nagios
Command user/group: nagios,nagios
Event Broker: yes
Install ${prefix}: /usr/local/nagios
Install ${includedir}: /usr/local/nagios/include/nagios
Lock file: /run/nagios.lock
Check result directory: /usr/local/nagios/var/spool/checkresults
Init directory: /lib/systemd/system
Apache conf.d directory: /etc/httpd/conf.d
Mail program: /usr/bin/mail
Host OS: linux-gnu
IOBroker Method: epoll

Web Interface Options:
HTML URL: http://localhost/nagios/
CGI URL: http://localhost/nagios/cgi-bin/
Traceroute (used by WAP): /usr/bin/traceroute
Review the options above for accuracy. If they look okay, type 'make all' to compile the main program and CGIs.


Now compile Nagios with this command:

[ssuri@linuxnix:~/nagios-4.4.2] $ make all
cd ./base && make
make[1]: Entering directory `/export/home/ssuri/nagios-4.4.2/base'
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nagios.o nagios.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o broker.o broker.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nebmods.o nebmods.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o ../common/shared.o ../common/shared.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o query-handler.o query-handler.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o workers.o workers.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o checks.o checks.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o config.o config.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o commands.o commands.c
gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o events.o events.c
------------------------------output truncated for brevity

Now we can will run the following make commands to install Nagios, init scripts, and sample configuration files:

sudo make install
sudo make install-commandmode
sudo make install-init
sudo make install-config
sudo make install-webconf

In order to issue external commands via the web interface to Nagios, we must add the web server user, apache, to the nagcmd group or we could run apache with the nagios user as we’ve done in this setup.

[ssuri@linuxnix:/etc/httpd/conf] $ grep nagios httpd.conf
User nagios
Group nagios

[ssuri@linuxnix:/etc/httpd/conf] $ ps -ef | grep httpd
root 15383 1 0 Oct13 ? 00:00:20 /usr/sbin/httpd -DFOREGROUND
ssuri 17815 17653 0 07:13 pts/1 00:00:00 grep --color=auto httpd
nagios 31641 15383 0 Oct21 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
nagios 31642 15383 0 Oct21 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
nagios 31643 15383 0 Oct21 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
nagios 31644 15383 0 Oct21 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
nagios 31645 15383 0 Oct21 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
nagios 31646 15383 0 Oct21 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
nagios 51004 15383 0 Oct21 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
nagios 51008 15383 0 Oct21 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
nagios 51011 15383 0 Oct21 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
nagios 51030 15383 0 Oct21 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND
nagios 51032 15383 0 Oct21 ? 00:00:00 /usr/sbin/httpd -DFOREGROUND


Getting Nagios core up and running is a four part process. In this article we’ve explained the installation of Nagios core on a Centos 7 system which was the first part. In the next article we will demonstrate how to install Nagios plugins and the NRPE package.

The post Installing Nagios on Centos 7 appeared first on The Linux Juggernaut.

Share Button

Source: The Linux Juggernaut

Leave a Reply