Setting up Nagios

Sreehas Dommata
Linux Monitoring With Nagios
3 min readJun 13, 2017

Nagios is an open source monitoring system for computer systems. It was designed with core components to run on the Linux operating system and can monitor devices running Linux, Windows and Unix OSes.

Nagios runs periodic checks on critical parameters of application, network and server resources. It can monitor, for example, memory usage, disk usage, microprocessor load, the number of currently running processes and log files. Nagios also can monitor services, such as Simple Mail Transfer Protocol (SMTP), Post Office Protocol 3 (POP3), Hypertext Transfer Protocol (HTTP) and other common network protocols. Active checks are initiated by Nagios, while passive checks come from external applications connected to the monitoring tool.

Step 1: Assign the hostname to the test server

# ifconfig (to check ip)# hostname nagios.testserver.com# vi /etc/hosts (provide the entry in the host file)192.168.0.1 nagios.testserver.com nagios:wq!# vi /etc/hostname (to make host permanent)# nagios.testserver.com

Step 2: Install the dependencies for Nagios

# yum install http* gcc* php* glib* gd* --skip-broken -y

Step 3: Create Nagios system user and group

# useradd nagios# useradd nagios (assign the password)# groupadd nagioscmd

Step 4: Make nagioscmd group as a secondary for user-nagios, apache

# usermod -G nagioscmd nagios#usermod -G nagioscmd apache

Step 5: Install Nagios application

Download and move the application directory of file into /opt directory

# cd /opt# ls (check)# tar -xvzf nagios-4.0.7.tar.gz (to uncompress & extract)# ls (to check)# cd nagios-4.0.7 (access directory)# ./configure — with-comand-group=nagioscmd# make all# make install#make install-init# make install-config# make install-commandmode# make install-webconf

Step 5: Provide the Email Address in the file

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

Go to line no.34 & Change the Email ID for Alerts

For example:- root@testserver.com (save & quit the file)

Step 6: Create Nagios Admin account for accessing the application

# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminPassword: nagios (for example)# service httpd restart# systemctl enable httpd.service 

Step 7: Install Nagios plugins

# cd .. (to move one directory backward)# ls (check the contents of the directory)# tar -xvzf nagios-plugings-2.0.2.tar.gz# cd nagios-plugins-2.0.2 (access the required directory)# ./configure — with-nagios-user=nagios — with-nagios-group=nagios# make# make install

Step 8: Verify the configuration and start Nagios service

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg# service nagios start#chkconfig — add nagios# chkconfig nagios on

Step 9: Access Nagios application

# firefox http://nagios.testserver.com/nagiosUsername: nagiosadminPassword: nagios

Step 10: Add hosts and services

# vim /user/local/nagios/etc/objects/localhost.cfg

Copy the lines from lines 24 to 31 and paste at the end of the file and modify the changes as per required services.

Example: Let us assume, we are having a ftp server running on 192.168.0.25

define host{use linux-serverhost_name ftp.testserver.comalias ftp.testserver.comaddress 192.168.50.250}

:wq(save & quit the file)

Restart the Nagios service by typing

# service nagios restart

To Check

Go to Nagios web interface and select the option-Hosts for the left column

Add the service (such as ftp) based on the previous configuration by typing

# vim /usr/local/nagios/etc/objects/localhost.cfg

Copy the lines from line no.149 to 155 (i.e, 7 lines) & Paste at the endof the file & do the changes as given below:

define service{use local-servicehost_name ftp.zoom.comservice_description FTPcheck_command check_ftpnotifications_enabled 0}

:wq(save & quit the file)

Restart the Nagios service by typing

# service nagios restart

To check

Go to Nagios Interface and select the option: Services from the left extreme to check the status of the entered hosts.

--

--