• Get In Touch
May 29, 2017

How to Install Nagios Core 4.2 on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Nagios is a free and open source monitoring tool that gives a more comprehensive monitoring environment to monitor all your machines and networks. You can monitor your remote hosts and their services remotely on a single window using Nagios. It will give you a warnings and indicates if something goes wrong in your servers which eventually helps you to detect some problems before they occur. It helps you to reduce downtime and business losses. Some of its features are listed below please have a look at them.

  • Monitor your entire IT infrastructure
  • Identify problems before they occur
  • Know immediately when problems arise
  • Share availability data with stakeholders.hypothetical question
  • Detect security breaches
  • Plan and budget for IT upgrades
  • Reduce downtime and business losses.

Requirements

To follow this guide you’ll need only a CentOS 7 server and a user with root privileges over it to install Nagios 4.2.0 on your CentOS 7 server. You can switch from non root user to root user using sudo -i command.

Update System

It is highly recommended to install Nagios Core 4.2 on a freshly updated server. Run following command to upgrade available packages and update system.

yum -y update

Install Dependencies

You’ll need to install some dependencies required to install Nagios. These dependencies are the Apache web server, PHP and some libraries like gcc, glibc, glibc-common and GD libraries with its development libraries. So first of all let’s install Apache web server using following command.

yum -y install httpd

Now you can start Apache and enable it to start at boot time, using the following commands.

systemctl start httpd.service systemctl enable httpd.service

You can check the status of Apache web server using the following command.

systemctl status httpd

Next, install other required dependencies like PHP and some libraries using following command.

yum -y install php gcc glibc glibc-common gd gd-devel make net-snmp

Creating Nagios User and Group

You’ll need to create a new nagios user and nagcmd group account and you can do so using following commands.

useradd nagios
groupadd nagcmd

Next, add both the nagios user and the apache user to the nagcmd group.

usermod -G nagcmd nagios
usermod -G nagcmd apache

Download Nagios Core 4.2

First of all create a new directory and switch to that directory for Nagios Core installtion and all its future downloads. Run following commands and it’ll do the job for you.

mkdir /root/nagios
cd /root/nagios

If in case you don’t have already installed wget package on your server then you can install it using yum -y install wget

Once directory is created now download the Nagios core 4.2 using following command.

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.2.0.tar.gz

Next, you’ll have to download Nagios plugins 2.1.2 package using following command.

wget https://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

Next, extract these downloaded packages with tar command like shown below:

tar -xvf nagios-4.2.0.tar.gz
tar -xvf nagios-plugins-2.1.2.tar.gz

Configure Nagios

Now we will configure Nagios Core and to do so first we’ll have to switch to Nagios directory and run following command.

cd nagios-4.2.0
./configure --with-command-group=nagcmd

Next, you’ll need to compile and install all the binaries with make command and make install command will install all the needed libraries in your machine and we can proceed further.

make all
make install

Run this command to install the init scripts for Nagios.

make install-init

You’ll need to install command-mode so that Nagios can work from command line.

make install-commandmode
make install-config

Customize Nagios Configuration

Edit the contacts.cfg file and to do so open this file using any text editor, here we are using nano text editor.

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

Replace email with your own email then save the file and exit from the text editor.

###############################################################################
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################
# Just one contact defined by default - the Nagios admin (that's you)
# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.
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                      me@sajidbhaijaan.net     ; *** CHANGE THIS TO YOUR EMAIL ADDRESS ****
}

Configure Web Interface

Let’s configure the Web Interface For Nagios with following command. The below command will Configure Web interface for Nagios and a web admin user will be created nagiosadmin.

make install-webconf

Now create a password for nagiosadmin and this password will be used when you login in the Nagios Web interface.

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

Restart your Apache web server to apply these changes that we just configured.

systemctl restart httpd.service

Run following commands one by one to compile and install Nagios plugin.

cd /root/nagios
cd nagios-plugins-2.1.2/
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install

Now we have configured Nagios successfully but it is recommended to verify all the Nagios configuration file. To do so run following command.
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

You should see following output at the end.

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

Finally start Nagios and enable it to start at boot time, using the following commands.

systemctl enable nagios
systemctl start nagios.service

Web Access of Nagios

Open up your favorite web browser and please visit http://YourIPaddress/nagios and you’ll see a Nagios login page and use nagiosadmin as username and password that you set up earlier to login to Nagios web dashboard.

Conclusion

In this you’ve learned how to install Nagios Core on your CentOS 7 server and configure it for your server. We hope now you have enough knowledge to work with Nagios Core monitoring tool.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]