Step by step guide to install Nagios core in RHEL/CentOS

For every system admin, making sure that all the servers are working fine is an important aspect of the job. So if you have a few servers, we can run commands like top or df -h or free -m to make sure that our CPU, HDD space & memory are performing well or not. But when dealing with large number of servers, this manual way will not work & we should than use a tool, a tool that can do monitoring for us & inform us in case an error occurs.

One such tool is Nagios server, Nagios server (AKA nagios core) is a very useful, open-source monitoring tool. With the help of Nagios server, we can monitor stats like ram usage, cpu usage, hdd usage along with other parameters of a number of machines/servers on single screen. If there is an error related memory or CPU or any other services that we configured Nagios to monitor, than nagios shows errors on the nagios server itself, can make a sound to grab oour attention towards the error & can also send an email or a SMS.

In this tutorial, we will install a Nagios core 4.2.4 server on RHEL/CentOS server.

Step 1 – Installing Dependencies

We need to install some packages like httpd, php, gcc, glibc, glibc-comman & GD on our system before we can install nagios on server. To install all these packages, run following

# yum install –y httpd php gcc glibc glibc-comman gd gd-devel make net-snmp

Step 2 – Downloading nagios & plugins

We will install nagios using the source files, the nagios & its plugins are avaiilable from the links mentioned below,

# wget https://downloads.sourceforge.net/project/Nagios/Nagios-4.x/Nagios-4.2.4/Nagios-4.2.4.tar.gz
# wget https://Nagios-plugins.org/download/Nagios-plugins-2.1.4.tar.gz

Step 3 – Create a user & group for Nagios

We need to create a seperate user & group to install nagios. So, we will add a user ‘nagios’, then assign it a password & then will add a group ‘nagcmd’ on our server

# useradd nagios
# passwd nagios
# groupadd nagcmd

Now, we will add nagios & apache to nagcmd group

# usermod –G nagcmd nagios
# usermod –G nagcmd apache

Step 4- Extracting Nagios files

Once the user & group have been added, we will proced with the nagios instllation. Goto the directory with nagios & its plagins source packages & extract them,

# cd /home/dan/Downloads
# tar -xvf nagios-4.2.4.tar.gz
# tar -xvf nagios-plugins-2.1.4.tar.gz

Step 5- Configuring Nagios

After the fiiles have been extracted, we will now compile & install the packages. Goto the folder with extracted packages,

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

Next, we will now run make & make install to complete our installation

# make
# make install

Next, we will install init –scripts, commandmode & some sample Nagios files ,

# make install-init
# make install-comandmode
# make install-config

Step 6– Configuring Web-Interface

Now, we need to setup web-interface where we can view all the warnings & alerts for our all our services/servers. To install web-interface, run

# make install-webconf

We need credentials to login to the web-interface. Web-interface is installed with a default user “nagiosadmin” . We will now assign password to user “nagiosadmin”, to do so run the follwoing command,

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

Step 7- Setting an email for sending alerts

This is an optional step but a useful one. We can define an email address in nagios configurations, where we will receive alerts related to our servers or services,
To add an email, open

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

and enter an email address.

Step 8- Installing the Nagios Plugins

Nagios has been installed on our system, next part is to install the nagios plugins. To install plugins, we will first goto the folder with extracted plugins file & then will complile & install the plugins,

# cd nagios-plugins-2.1.4/
# ./configure – -with-nagios-user=nagios –with-nagios-group=nagios
# make
# make install

Step 9 – Verify Nagios files

There is a sample configuration file in /usr/local/nagios/bin/nagios, which we can use to verify our configuration file,

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

If all the configurations made to nagios.cfg are correct, we will not receive any error. Now restart nagios server & httpd server

# systemctl restart nagios
# systemctl enable nagios
# systemctl restart httpd
# systemctl enable httpd

Step 10- Logging into Web-interface

All the configurations related to setting up Nagios server are complete & we can now login to web interface to view the status of the services, which at this point are only services from localhost.

To login to web interface, open browser & enter the address of nagios server (which in our case is 192.168.1.100) on a remote system in LAN or if using same system to login as nagios, then just enter localhost in address bar

http://192.168.1.100 or localhost

You will now be asked to provide username, password & upon successful authentication, we should see the nagios web interface page.

Click now on ‘Service overview’ page & we should see services of our localhost . That is because we have not added other host services on Nagios. In our future tutorial, we will discuss how we can add windows machine and Linux machines for monitoring.

Shujat Husain

A continuous learner with several years of experience in linux environment. I love to read, learn & write about Linux & new technologies. And I also write at linuxtechlab.com

You may also like...

What is in your mind, about this post ? Leave a Reply

Close
  Our next learning article is ready, subscribe it in your email

What is your Learning Goal for Next Six Months ? Talk to us