Red Hat Training

A Red Hat training course is available for Red Hat Ceph Storage

Chapter 2. Installing Nagios Core

Installing Nagios Core involves downloading the Nagios Core source code; then, configuring, making and installing it on the host that will run Nagios Core instance.

The following sections describe the process for Ubuntu 16.04 and later releases.

For Ubuntu 16.04, execute all commands as root:

[user@nagios]$ sudo -i

2.1. Installing Nagios Prerequisites

Install the prerequisites.

[user@nagios]# yum install -y httpd php php-cli gcc glibc glibc-common gd gd-devel net-snmp openssl openssl-devel wget unzip
[user@nagios]# apt-get install wget build-essential apache2 php apache2-mod-php7.0 openssl libssl-dev gcc make php-gd libgd-dev unzip

Open port 80 for httpd.

[user@nagios]# firewall-cmd --zone=public --add-port=80/tcp
[user@nagios]# firewall-cmd --zone=public --add-port=80/tcp --permanent

Open port 80 for apache2:

[user@nagios]# iptables -A INPUT -p tcp --dport 80 -j ACCEPT
[user@nagios]# apt-get install iptables-persistent

2.2. Creating a Nagios User and Group

Create a user and group for Nagios Core.

[user@nagios]# useradd nagios
[user@nagios]# passwd nagios
[user@nagios]# groupadd nagcmd
[user@nagios]# usermod -a -G nagcmd nagios

Then, execute the following:

[user@nagios]# usermod -a -G nagcmd apache
[user@nagios]# usermod -a -G nagios,nagcmd www-data

2.3. Download Nagios Source Code and Plug-ins

Download the latest version of Nagios Core and Plug-ins.

[user@nagios]# wget --inet4-only https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.1.tar.gz
[user@nagios]# wget --inet4-only http://www.nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
[user@nagios]# tar zxf nagios-4.3.1.tar.gz
[user@nagios]# tar zxf nagios-plugins-2.2.1.tar.gz
[user@nagios]# cd nagios-4.3.1

2.4. Make and Install Nagios Core

To make and install Nagios Core, first run ./configure.

[user@nagios]# ./configure --with-command-group=nagcmd
[user@nagios]# ./configure --with-command-group=nagcmd --with-httpd-conf=/etc/apache2/

After running ./configure, compile the Nagios Core source code.

[user@nagios]# make all

After making Nagios Core, install it.

[user@nagios]# make install
[user@nagios]# make install-init
[user@nagios]# make install-config
[user@nagios]# make install-commandmode
[user@nagios]# make install-webconf

Copy the event handlers and change their ownership.

[user@nagios]# cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
[user@nagios]# chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

Finally, run the pre-flight check.

[user@nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

2.5. Make and Install Nagios Core Plug-ins

Make and install the Nagios Core plug-ins.

[user@nagios]# cd ../nagios-plugins-2.2.1
[user@nagios]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[user@nagios]# make
[user@nagios]# make install

2.6. Create a Default Nagios Core User

Create a user for the Nagios Core user interface.

[user@nagios]$ sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Important

If adding a user other than nagiosadmin, ensure the /usr/local/nagios/etc/cgi.cfg file gets updated with the username too.

Also modify the /usr/local/nagios/etc/objects/contacts.cfg file with the user name, full name and email address as needed.

2.7. Start Nagios

Add Nagios Core as a service and enable it. Then start the Nagios Core daemon and Apache.

[user@nagios]# chkconfig --add nagios
[user@nagios]# chkconfig --level 35 nagios on
[user@nagios]# systemctl start nagios
[user@nagios]# systemctl enable httpd
[user@nagios]# systemctl start httpd
[user@nagios]# a2ensite nagios
[user@nagios]# a2enmod rewrite cgi
[user@nagios]# sudo cp /etc/init.d/skeleton /etc/init.d/nagios

Then, edit the initialization file:

[user@nagios]# vi /etc/init.d/nagios

Add the following lines:

DESC="Nagios"
NAME=nagios
DAEMON=/usr/local/nagios/bin/$NAME
DAEMON_ARGS="-d /usr/local/nagios/etc/nagios.cfg"
PIDFILE=/usr/local/nagios/var/$NAME.lock

Finally, start Nagios:

[user@nagios]# systemctl restart apache2
[user@nagios]# systemctl start nagios

2.8. Log in to Nagios Core

With Nagios up and running, log in to the web user interface.

http://<ip-address>/nagios

Nagios Core will prompt for a user name and password. Input the login and password of the default Nagios Core user.