Nagios is an open source network monitoring software which was released under the GPL license. It has more than 1 million users worldwide. It provides full access of source code so that anyone can make improvements to enhance its features. It has active community which provides free support. Nagios has hundreds of addons developed by this community.

Nagios has ability to monitor services, network protocols, applications, operating systems, system metrics and infrastructure components. It allows easy monitoring of systems, services and applications using its powerful script APIs.

Nagios provides a centralized view of the whole IT infrastructure. It provides detailed information via web interface. It supports fast detection of infrastructure outages. Nagios allows to send alerts to technical staff via SMS and email. It has escalation capabilities which ensure that alert notifications have reached to right people.

Nagios has event handlers which allows automatic restart of failed applications and services. It has alert acknowledgement which provides communication on known issues and problem response. During infrastructure upgrades, scheduled downtime allows for alert suppression. Capacity planning and trending addons help to ensure that you are aware of aging infrastructure. To ensure that SLAs are met, availability reports are available. You can check historical reports to provide you record of alerts, outages, alert response and notifications.

Nagios provides many third party addons to extend reporting capabilities. It supports multiple users. A client only sees his restricted and bounded view of infrastructure components. Multi-user access to web interface allows stake holders to view infrastructure components. It provides easy integration with third party and in-house applications by using multiple APIs. There are hundreds of addons developed by community which extend Nagios functionality.

Nagios was written in C-language. It involves over 10 years of active development. Nagios got a number of awards, media coverage and recognition which prove its value. It has failover capabilities which ensure non-stop monitoring of critical IT infrastructure components. It can be scaled to monitor thousands of nodes.­

As a developer, I prefer web development and IT services of WebSoft. Highly scalable and flexible VPS are available. You can upgrade the hardware resources anytime when required.

In this tutorial, I will be using Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04 installed on it. I will install and setup Nagios.

System updates & upgrades:

Before proceeding with installation of any kind of package, use the following command to update your Ubuntu system. To execute this command, remember to login from non-root user with sudo privileges. After execution of this command, you will be prompted to Is this ok? Type ‘y’ and hit Enter key.

Step 1:

# sudo apt update && sudo apt upgrade

PHP:

Nagios requires installation of PHP 5.3 or newer version of PHP. In this tutorial, you will install PHP 7.2. To install PHP 7.2, execute the following steps.

Step 1:

In the first step, you will need to install python software properties and software properties common. To do so, execute the command below.

# sudo apt-get install software-properties-common python-software-properties

You will need to add repository for newer versions of PHP. To do so, execute the commands below.

# sudo add-apt-repository ppa:ondrej/php

Step 2:

Update the system to refresh the available repositories. To do so, execute the command for updating Ubuntu system.

# sudo apt update

Step 3:

Now let’s install PHP 7.2. To install PHP 7.2, execute the following command.

# sudo apt install -y php7.2

PHP extensions:

Nagios requires the following PHP extensions:

  1. php7.2-mbstring
  2. php7.2-mysql
  3. php7.2-curl
  4. libapache2-mod-php

To install the above extensions of PHP, execute the following command.

# sudo apt install -y php7.2-mysql php7.2-curl php7.2-mbstring libapache2-mod-php

When you have done installation of the above extensions, apache2 will be installed automatically. Hence, you don’t need to install apache explicitly.

Install Nagios:

To install Nagios, you will need to follow the steps below.

Step 1:

In the first step, you will create a user group and add a user.

# sudo adduser nagios

# sudo groupadd nagcmd

Add user to nagcmd group.

# sudo adduser nagios nagcmd

Download Nagios by executing the command below.

# curl -L -O https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.4.tar.gz

Step 2:

In the second step, you will need to extract files from archived folder by using the command below.

# tar zxf nagios-4.3.4.tar.gz

Step 3:

In the third step, rename the extracted folder.

# mv nagios-4.3.4 nagios

Step 4:

Remove the downloaded archived directory.

# sudo rm nagios-4.3.4.tar.gz

Step 5:

Navigate to nagios using the command below.

# cd nagios

Step 6:

Before building Nagios, you will need to run configure where you will specify username and group you want Nagios to use.

# ./configure –with-nagios-group=nagios –with-command-group=nagcmd

Step 7:

Now execute the following command to compile Nagios.

# make all

Step 8:

Now execute the following commands to install Nagios, default configuration and init scripts.

# sudo make install

# sudo make install-commandmode

# sudo make install-init

# sudo make install-config

Install required plugins:

Nagios monitors remote hosts using Nagios Remote Plugin Extractor. To install it, follow the steps below.

Step 1:

Navigate to home directory.

# cd ~

Step 2:

Download archived folder by using the command below.

# curl -L -O https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz

Step 3:

Extract archived directory using the command below.

# tar zxf nrpe-*.tar.gz

Step 4:

Navigate to nrpe-* extracted directory.

# cd nrpe-*

Step 5:

Execute the following commands to configure, compile and install nrpe.

# ./configure

# make check_nrpe

# sudo make install-plugin

Configure Nagios:

Now you will need to use Apache for serving web interface of Nagios. Execute the following command to copy apache configurations for Nagios to sites-available directory.

# sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf

To entertain external commands via web interface to Nagios, you will need to add www-data user to nagcmd group.

# sudo usermod -G nagcmd www-data

Open Nagio configuration file using command below.

# sudo nano /usr/local/nagios/etc/nagios.cfg

Find the line shown below and remove # to uncomment it and then save the file.

Now you will need to create a directory to store configuration file for each server that you will monitor by executing the command below.

# sudo mkdir /usr/local/nagios/etc/servers

Execute the following command to open contacts configuration file and replace email with your own email.

# sudo nano /usr/local/nagios/etc/objects/contacts.cfg

Open the file by executing command below.

# sudo nano /usr/local/nagios/etc/objects/commands.cfg

Add the following text to the end of opened file and save it.

define command {
command_name check_nrpe           
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$   
}    

Now you will need to enable rewrite mod. You can do so by editing configuration file in apache2 directory or you can simply execute the command below.

# sudo a2enmod rewrite

Now you will need to enable cgi mod. You can do so by editing configuration file in apache2 directory or you can simply execute the command below.

# sudo a2enmod cgi

To set the password for accesssing admin panel using username nagiosadmin execute the following command.

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

Execute the command below to disable default site.

# sudo a2dissite 000-default.conf

Now you will need to enable the virtual host for Nagios. To do so, execute the command below.

# sudo a2ensite nagios

Now you will have to restart apache server to apply the changes and load the settings by executing command below.

# sudo service apache2 restart

Create systemd service for Nagios:

Execute the following command to open a file for setting up Nagios service.

# sudo nano /etc/systemd/system/nagios.service

Now copy and paste the following text in opened file.

[Unit]   
Description=Nagios   
BindTo=network.target       

[Install]   
WantedBy=multi-user.target       

[Service]   
Type=simple   
User=nagios   
Group=nagios   
ExecStart=/usr/local/nagios/bin/nagios/usr/local/nagios/etc/nagios.cfg       

Now execute the following command to start Nagios service.

# sudo systemctl start Nagios

Now you can access your Nagios server via IP address or domain name.

https://www.imarslan.com

After entering username and password for admin, you will be redirected to Nagios dashboard.

Here you go…you have successfully installed and configured Nagios server monitoring.