Install and Configure Nagios Server

Date Posted: 08-06-2017

Nagios is an open source monitor tool widely used to monitor client machines. Here, we are going to explain on how to install and configure nagios server.

Prerequisites:

  1. Centos 7.0 Server – In this post, we are using centos server 7.0. We can use Ubuntu host as well to install nagios server.

Implementation:

We assumes that this is a fresh centos server. Let’s start with disabling selinux.

setenforce 0

Disable selinux permanently.

vi /etc/selinux/config

SELINUX=disabled

Install dependencies.

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

Create a nagios user and group nagcmd

useradd nagios
groupadd nagcmd

Add the users nagios and apache to nagcmd

usermod -G nagcmd nagios
usermod -G nagcmd apache

Download the nagios-server and nagios-plugins

cd /usr/local/src/
wget https://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.3.2/nagios-4.3.2.tar.gz

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

Extract the files nagios-server file and nagios plugin file.

tar -xzf nagios-4.3.2.tar.gz
tar -xzf nagios-plugins-2.2.1.tar.gz

Change the directory.

cd nagios-4.3.2

Configure the nagios.

./configure --with-command-group=nagcmd

Make and make install.

make all
make install

Create init script and command mode

make install-init

make install-commandmode

Create nagios configuration

make install-config

The above command will create basic configuration file.

Configuring Nagios:

Open contacts.cfg  and update the email address where we want to receive notification.

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

email                           nagios@domain.tld

Install web-conf

make install-webconf

Create a nagiosadmin user to maintain authentication page on nagios interface

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

Enter the password and repeat the password.

Start the httpd service

service httpd start

Now, install the nagios plugin which we downloaded already.

cd /usr/local/src/nagios-plugins-2.2.1

Configure the plugins.

./configure --with-nagios-user=nagios --with-nagios-group=nagios

Make & Make install the configured plugin

make && make install

Enable both nagios and httpd service on startup.

systemctl enable nagios
systemctl enable httpd

Start the nagios service

service nagios start

Additional Information:

Now, we create a configuration directory for the client hosts.

mkdir /usr/local/nagios/etc/servers

Add the configuration directory nagios.cfg

vi /usr/local/nagios/etc/nagios.cfg

Uncomment the following line,

cfg_dir=/usr/local/nagios/etc/servers

Add the NRPE command_line to check remote hosts.

vi /usr/local/nagios/etc/objects/commands.cfg

###############################################################################
# NRPE CHECK COMMAND
#
# Command to use NRPE to check remote host systems
###############################################################################
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

Verify the nagios configuration for syntax error.

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

Restart the nagios service.

/etc/init.d/nagios restart

Access the nagios URL on the browser.

http://IPADDRESS/nagios

Enter the password which we created using htpasswd.

Leave a Reply