How to set-up Nagios on Ubuntu

Last updated on Nov 28 2021
Nitin Bajabalkar

Table of Contents

How to set-up Nagios on Ubuntu

Nagios – Installation

In this blog, the steps to setup Nagios on Ubuntu are discussed in detail.

Before you install Nagios, some packages such as Apache, PHP, building packages etc., are required to be present on your Ubuntu system. Hence, let us install them first.

Step 1 − Run the following command to install pre-required packages −

sudo apt-get install wget build-essential apache2 php apache2-mod-php7.0 php-gd
libgd-dev sendmail unzip

Step 2 − Next, create user and group for Nagios and add them to Apache www-data user.

sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagios,nagcmd www-data

Step 3 − Download the latest Nagios package.

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-
4.4.3.tar.gz

Step 4 − Extract the tarball file.

tar -xzf nagios-4.4.3.tar.gz
cd nagios-4.4.3/

Step 5 − Run the following command to compile Nagios from source.

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

Step 6 − Run the following command to build Nagios files.

make all

Step 7 − Run the command shown below to install all the Nagios files.

sudo make install

Step 8 − Run the following commands to install init and external command configuration files.

sudo make install-commandmode
sudo make install-init
sudo make install-config
sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sitesavailable/
nagios.conf

Step 9 − Now copy the event handler directory to Nagios directory.

sudo cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
sudo chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers

Step 10 − Download and extract Nagios plugins.

cd
wget https://nagios-plugins.org/download/nagiosplugins-
2.2.1.tar.gz
tar -xzf nagios-plugins*.tar.gz
cd nagios-plugins-2.2.1/

Step 11 − Install Nagios plugins using the below command.

./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl
make
sudo make install

Step 12 − Now edit the Nagios configuration file and uncomment line number 51 → cfg_dir=/usr/local/nagios/etc/servers

sudo gedit /usr/local/nagios/etc/nagios.cfg

Step 13 − Now, create a server directory.

sudo mkdir -p /usr/local/nagios/etc/servers

Step 14 − Edit contacts configuration file.

sudo gedit /usr/local/nagios/etc/objects/contacts.cfg
image1 35     

Step 15 − Now enable the Apache modules and configure a user nagiosadmin.

sudo a2enmod rewrite
sudo a2enmod cgi
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
sudo ln -s /etc/apache2/sites-available/nagios.conf /etc/apache2/sites-enabled/

Step 16 − Now, restart Apache and Nagios.

service apache2 restart
service nagios start
cd /etc/init.d/
sudo cp /etc/init.d/skeleton /etc/init.d/Nagios

Step 17 − Edit the Nagios file.

sudo gedit /etc/init.d/Nagios
DESC = "Nagios"
NAME = nagios
DAEMON = /usr/local/nagios/bin/$NAME
DAEMON_ARGS = "-d /usr/local/nagios/etc/nagios.cfg"
PIDFILE = /usr/local/nagios/var/$NAME.lock

Step 18 − Make the Nagios file executable and start Nagios.

sudo chmod +x /etc/init.d/nagios
service apache2 restart
service nagios start

Step 19 − Now go to your browser and open url → http://localhost/nagios. Now login to Nagios with username nagiosadmin and use the password which you had set earlier. The login screen of Nagios is as shown in the screenshot given below −

image2 28

If you have followed all the steps correctly, you Nagios web interface will show up. You can find the Nagios dashboard as shown below −

image3 24

 

Nagios – Configuration

In the previous chapter, we have seen the installation of Nagios. In this chapter, let us understand its configuration in detail.

The configuration files of Nagios are located in /usr/local/nagios/etc. These files are shown in the screenshot given below −

image4 23

Let us understand the importance of each file now −

nagios.cfg

This is the main configuration file of Nagios core. This file contains the location of log file of Nagios, hosts and services state update interval, lock file and status.dat file. Nagios users and groups on which the instances are running are defined in this file. It has path of all the individual object config files like commands, contacts, templates etc.

cgi.cfg

By default, the CGI configuration file of Nagios is named cgi.cfg. It tells the CGIs where to find the main configuration file. The CGIs will read the main and host config files for any other data they might need. It contains all the user and group information and their rights and permissions. It also has the path for all frontend files of Nagios.

resource.cfg

You can define $USERx$ macros in this file, which can in turn be used in command definitions in your host config file(s). $USERx$ macros are useful for storing sensitive information such as usernames, passwords, etc.

They are also handy for specifying the path to plugins and event handlers – if you decide to move the plugins or event handlers to a different directory in the future, you can just update one or two $USERx$ macros, instead of modifying a lot of command definitions. Resource files may also be used to store configuration directives for external data sources like MySQL.

image5 18

image6 15

The configuration files inside objects directory have are used to define commands, contacts, hosts, services etc.

commands.cfg

This config file provides you with some example command definitions that you can refer in host, service, and contact definitions. These commands are used to check and monitor hosts and services. You can run these commands locally on a Linux console where you will also get the output of the command you run.

Example

define command {
command_name check_local_disk
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}

define command {
command_name check_local_load
command_line $USER1$/check_load -w $ARG1$ -c $ARG2$
}

define command {
command_name check_local_procs
command_line $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
}

contacts.cfg

This file contains contacts and groups information of Nagios. By default, one contact is already present Nagios admin.

Example

define contact {
contact_name nagiosadminuse 
generic-contactalias 
Nagios Adminemail 
avi.dunken1991@gmail.com
}

define contactgroup {
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}

templates.cfg

This config file provides you with some example object definition templates that are referred by other host, service, contact, etc. definitions in other config files.

timeperiods.cfg

This config file provides you with some example time period definitions that you can refer in host, service, contact, and dependency definitions.

So, this brings us to the end of blog. This Tecklearn ‘How to set-up Nagios on Ubuntu’ blog helps you with commonly asked questions if you are looking out for a job in DevOps. If you wish to learn Nagios and build a career in DevOps domain, then check out our interactive, Continuous Monitoring using Nagios Training, that comes with 24*7 support to guide you throughout your learning period. Please find the link for course details:

https://www.tecklearn.com/course/continuous-monitoring-using-nagios/

Continuous Monitoring using Nagios Training

About the Course

Tecklearn has specially designed this Continuous Monitoring using Nagios Training Course to advance your skills for a successful career in this domain. The course will cover different components of Nagios and how they are used in software development operations. You will get an in-depth knowledge of these concepts and will be able to work on related demos. Upon completion of this online training, you will hold a solid understanding and hands-on experience with Nagios.

Why Should you take Continuous Monitoring using Nagios Training?

  • The average salary for Nagios Monitoring Engineer is $107,506 per year, ranging from $85,655 to $124,818.
  • Oracle, Raytheon, Abacus, Next, Apple, Wells Fargo & many other MNC’s worldwide use Nagios across industries.
  • According to Grand View Research, the DevOps market size is estimated to be worth $12.85 billion by 2025. DevOps professionals are highly paid and in-demand throughout industries including retail, eCommerce, finance, and technology.

What you will Learn in this Course?

Introduction to DevOps

  • What is Software Development
  • Software Development Life Cycle
  • Why DevOps?
  • What is DevOps?
  • DevOps Lifecycle
  • DevOps Tools
  • Benefits of DevOps
  • How DevOps is related to Agile Delivery
  • DevOps Implementation

Continuous Monitoring using Nagios

  • Introduction to Continuous Monitoring
  • Introduction to Nagios
  • Nagios Architecture
  • Monitoring Services in Nagios
  • Installing Nagios
  • Nagios Plugins (NRPE) and Objects
  • Nagios Commands and Notification
  • Monitoring of different servers using Nagios

Got a question for us? Please mention it in the comments section and we will get back to you.

 

0 responses on "How to set-up Nagios on Ubuntu"

Leave a Message

Your email address will not be published. Required fields are marked *