How to Install Nagios on CentOS 7

r00t August 10, 2017

Install Nagios on CentOS 7

In this tutorial we’ll learn how to install Nagios on CentOS 7. We will also install and configure its prerequisites. Nagios is the most widely used open source monitoring tools which help us to monitor the services and application that run’s on Windows, Linux, Routers and other network devices. The server administrator who uses Nagios gains access to a wide variety of features such as SSH-enabled remote monitoring, network and host traffic monitoring, and a versatile plugin ecosystem.

I recommend to use a minimal Ubuntu server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install Nagios on CentOS 7

Step 1. First, ensure your system is fully up-to-date by running the following:

yum -y update

Step 2. Installing Required Dependencies.

You’all need to install some basic prerequisite packages for Nagios:

yum install httpd gcc glibc glibc-common gd gd-devel net-snmp openssl-devel wget unzip nano -y

Step 3. Creating Nagios User and Group.

Create a nagios user and nagcmd group for allowing the external commands to be executed through the web interface, add the nagios and apache user to be a part of nagcmd group:

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache

Step 4. Installing Nagios.

After installing required dependencies and adding user accounts. Let’s start with Nagios core installation:

cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.1.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

Extract nagios tarball archive you downloaded and use the script inside to install:

tar -zxvf nagios-4.2.1.tar.gz
cd nagios-4.2.1/
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Step 4. Configure Nagios.

Edit the contacts.cfg file and to do so open this file using any 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:

[...]
# 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 nagios@localhost ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } [...]

We need to setup apache authentication for user nagiosadmin. Do not change this username. else you would required more changes in configuration:

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

Step 5. Installing Nagios Plugins.

After installing and configuring Nagios core service, Download latest nagios-plugins source and install using following commands:

cd /tmp
tar -zxvf nagios-plugins-2.1.2.tar.gz
cd nagios-plugins-2.1.2/
./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make
make install

Verify the sample Nagios configuration files:

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

The final step is to start up the Nagios and Apache daemons:

systemctl start httpd
systemctl start nagios

Step 6. Accessing Nagios Web Installation.

Now you can access the Nagios web install wizard in your browser by entering the domain name or http://your_ip/nagios/ to continue your  installation. You’ll be prompted for the username (nagiosadmin) and password you specified earlier.

Congratulation’s! You have successfully install and configured Nagios on your CentOS 7 server.

Save

The Tags:

Leave a Comment

Comments are closed.