How To Install Nagios 4.4.2 on Ubuntu 18.04 / Ubuntu 16.04

6

Nagios is one of the most widely used open source monitoring tool for monitoring the services and application that run’s on Windows and Linux. It also has the capability to monitor routers and other network devices.

With the help of Nagios, you can monitor basic services and attributes. We can access the Nagios using web interface coming with the bundle, but the configurations need to be done on the file level.

Services List

Nagios can monitor your “private” services and attributes of Linux/UNIX servers, such as:

Attributes

  • CPU load
  • Memory usage
  • Disk usage
  • Logged in users
  • Running processes
  • etc.

Private Services

  • HTTP
  • FTP
  • SSH
  • SMTP
  • etc

Install Nagios Server

Prerequisites

Get the Latest version of Nagios (v 4.4.2) from the official page. Before compiling the Nagios from the source, you would need to install dependent packages for Nagios.

Let’s switch to root user.

sudo su -

Update the repository cache and install the dependencies for Nagios.

apt-get update 
apt-get install build-essential apache2 php openssl perl make php-gd libgd-dev libapache2-mod-php libperl-dev libssl-dev daemon wget apache2-utils unzip

Create nagios user and nagcmd group (allowing the external commands to be executed through the web interface), add the nagios and apache user to the part of the nagcmd group.

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data
cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.2.tar.gz
tar -zxvf /tmp/nagios-4.4.2.tar.gz
cd /tmp/nagios-4.4.2/

Compile and Install Nagios

Perform the below steps to compile the Nagios from the source code.

./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Configure Nagios

The installer has now placed configuration files in the /usr/local/nagios/etc directory. These default configuration files should work fine for now to start Nagios.  All you need to make just one change before you proceed.

Edit the /usr/local/nagios/etc/objects/contacts.cfg file and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.

vi /usr/local/nagios/etc/objects/contacts.cfg

Change the email address field to receive the notification.

define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user

        email                           nagios@itzgeek.com      ;

<<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

        }

Configure Web Interface

Create a user account (nagiosadmin) for logging into the Nagios web interface. Remember the password you assign to this account – you’ll need it later.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Run the following command.

a2enmod cgi

Restart Apache to make the new settings take effect.

systemctl restart apache2

Download and Install Nagios Plugins

Now, it’s time to download Nagios plugins for monitoring the services. Place it into /tmp directory.

cd /tmp
wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
tar -zxvf /tmp/nagios-plugins-2.2.1.tar.gz
cd /tmp/nagios-plugins-2.2.1/

Compile and install the plugins.

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

Starting Nagios

Verify the sample Nagios configuration files.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Output:

Nagios Core 4.4.2
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2018-08-16
License: GPL

Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
        Checked 8 services.
        Checked 1 hosts.
        Checked 1 host groups.
        Checked 0 service groups.
        Checked 1 contacts.
        Checked 1 contact groups.
        Checked 24 commands.
        Checked 5 time periods.
        Checked 0 host escalations.
        Checked 0 service escalations.
Checking for circular paths...
        Checked 1 hosts
        Checked 0 service dependencies
        Checked 0 host dependencies
        Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

Enable Nagios to start automatically at system startup.

systemctl enable nagios

Now, start Nagios service.

systemctl start nagios

Access Nagios Web Interface

Now access the Nagios web interface using the following URL.

http://ip-address/nagios/

You’ll be prompted for the username (nagiosadmin) and password you specified earlier.

Install Nagios 4.4.2 on Ubuntu 18.04 - Enter Nagios Password
Install Nagios 4.4.2 on Ubuntu 18.04 – Enter Nagios Password

Upon successful login, you would get the Nagios’s home page.

Install Nagios 4.4.2 on Ubuntu 18.04 - Nagios Monitoring Home Page
Install Nagios 4.4.2 on Ubuntu 18.04 – Nagios Monitoring Home Page

You can monitor the services by clicking on Services in the left pane.

Install Nagios 4.4.2 on Ubuntu 18.04 - Service Monitoring Page
Install Nagios 4.4.2 on Ubuntu 18.04 – Service Monitoring Page

By default, Nagios can monitor only the localhost, i.e., Nagios server. If you want to monitor remote machines, then you need to install and configure NRPE plugin.

READ: How To Add Linux Host To Nagios Monitoring Using NRPE Plugin

Interested in Other Server Monitoring Tools

READ: How To Install Zabbix Server 4.0 on CentOS 7 / Ubuntu 16.04 & Debian 9

READ: Install Icinga2 on Ubuntu 18.04 / Ubuntu 16.04 & Debian 9

That’s All.

Further Reading

You might also like

How To Install Nagios 4.4.2 on Ubuntu 18.04 / Ubuntu 16.04

6