Nagios is a powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes. Nagios can help monitor various attributes of Linux/UNIX servers, such as CPU load, Memory usage, Disk usage, Logged in users, Running processes etc. It can also monitor services including HTTP, FTP, SSH, SMTP, etc.

In this tutorial, we will install Nagios and configure it for us to monitor host resources via Nagios' web interface.

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.

Once you have signed up, log into your Cloudwafer Client Area with the password provided in your mail and deploy your Cloudwafer cloud server.

Updating System Packages
It is always recommended that you update the system to the latest packages before beginning any major installations. This is done with the command below:

sudo yum update


Disable SELinux: Prior to starting our install, we need to disable SELinux.
setenforce 0

Modify /etc/selinux/config and change enforcing to disabled.

Install Build Dependencies: We are going to be building Nagios Core from source, which will require we install a few development libraries that will allow us to complete the build. Type the command below to install the necessary packages:

yum install httpd php php-cli gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget unzip

Step 1: Create Nagios User and Group
Create a nagios user and nagcmd group to run the Nagios process.

useradd nagios
groupadd nagcmd

Note: Remember to add sudo ahead of the command if you are signed in as a non-root user with sudo privileges.

Add the newly created user to the group:

usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

Step 2: Download and Install Nagios
This is where we will download the required .tar.gz files for the latest stable release of Nagios Core and Nagios Plugins. Visit the Nagios downloads page and proceed to copy the link address for the latest stable release for download.

At the time of this writing, the latest stable release is Nagios 4.4.1.

cd /tmp

Extract the Nagios archive with this command:

tar zxf nagios-4.4.1.tar.gz

Move to the extracted directory:

cd nagios-4.4.1

After extracting, compile Nagios with the command below:

./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Note: The screenshots above have been cropped.

Step 3: Download and Install Nagios Plugins
Download and install the latest version of Nagios plugins here. At the time of this writing, the latest version of 2.2.1.
cd /tmp

Extract the Nagios plugin archive with this command:

tar -zxvf /tmp/nagios-plugins-*.tar.gz
cd /tmp/nagios-plugins-*/

After extracting, compile Nagios plugins with the command below:

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

Step 4: Create a password for Nagiosadmin
We now need to create a password for the nagiosadmin user. This will be used to login to your core web GUI.
Note the password that you assign to this user as it will be required later.

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

Restart Apache web server to make the new settings take effect.

For CentOS 7/RHEL 7
systemctl restart httpd
systemctl enable httpd

CentOS 6/RHEL 6
service httpd start
chkconfig httpd on

Start Nagios:

 service nagios start

Access Web Interface
If everything has been correctly configured, you should be able to access the Nagios web interface using the URL: http://your-ip-address/nagios/.

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

The username is nagiosadmin while the password is what was created earlier. Proceed to log in:

After successfully logging in, this is the web interface for Nagios:

On the left pane, click on Hosts to get a list of systems being monitored by Nagios. Currently, the only host we are monitoring is the localhost itself as we have not added any host to Nagios.

If you cannot access the Nagios web page, it may be related to your firewall rules. Type the following command to open up port 80 if you are using firewallD:

firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload

In our next article, we will monitor Remote Linux System with Nagios Server.