Nagios Tutorial for DevOps Aspirants
Organizations may detect and fix issues with their IT infrastructure before they impact important business operations using Nagios, a robust monitoring tool. Learn the fundamentals in this Nagios tutorial and gain expertise with event monitoring systems in DevOps.
Introduction to Nagios
Nagios is open-source, just like one of many of the most well-liked and practical platforms & solutions in the DevOps ecosystem. We cover the following in this Nagios tutorial:
- Overview of Nagios
- Architecture of Nagios
- Nagios Products
- Nagios Installation
- Nagios Configuration
- Hosts and Services
- Commands in Nagios
- Applications of Nagios
- Advantages of Nagios
If you are new to DevOps, enroll in our DevOps training course to kickstart.
Overview of Nagios
This event monitoring solution offers Nagios’s server, switch, application, and service monitoring and alerting features. It sends out two alerts to users: one when an issue is resolved and another when something goes wrong.
Nagios allows users to:
- Plan and budget for infrastructure upgrades before outdated systems lead to significant malfunctions and breakdowns.
- Address matters that are brewing and may soon come to a head.
- automatically resolve issues that are found
- Organize the technical teams’ reactions.
- Verify adherence to business SLAs.
- Ensure that any disruptions or unanticipated circumstances affect the business’s operations and financial results as little as possible.
- Monitor every aspect of the company’s infrastructure and operations.
Although Nagios now works on Linux, Windows, and Unix operating systems, it was first intended to operate on Linux.
Continuous Monitoring Tool
After the deployment is completed on the production servers, continuous monitoring begins. This stage is thereafter in charge of keeping an eye on everything that occurs. This phase is critical to the productivity of the firm.
The use of continuous monitoring has various advantages:
- It finds every issue with the network and server.
- It identifies the failure’s primary cause.
- It contributes to lower maintenance costs.
- It aids in resolving performance-related problems.
- It assists with modernizing infrastructure before it becomes antiquated.
- When issues are found, it can automatically resolve them.
- It guarantees that the network, servers, services, and apps are constantly up and operating.
- Every second, the entire infrastructure is monitored.
Architecture of Nagios
The following aspects of Nagios architecture are noteworthy:
- Server-agent architecture is used in Nagios.
- On the host, the Nagios server is installed, and on the distant hosts or servers that need to be watched, plugins are installed.
- Through the use of a process scheduler, Nagios instructs the local and remote hosts and servers to run the plugins.
- Plugins gather information (such as CPU and memory use) and relay it back to the scheduler.
- Next, the Nagios GUI is updated and the admin(s) receive notifications from the process schedules.

Our Agile training course helps you accelerate your software development lifecycle. Enroll now.
Nagios Products
Nagios offers a range of products, which are covered in more depth below:
Nagios XI
- It offers monitoring for every element of the IT infrastructure, including the network, operating systems, apps, and services.
- It provides a comprehensive perspective of your business procedures and infrastructure.
- With its ease of customization, the GUI offers flexibility to the user.
- This tool’s enterprise edition costs $3495, while the ordinary edition costs $1995.
Nagios Core
- It is the foundation of IT infrastructure monitoring.
- Nagios Core serves as the foundation for the Nagios XI product as well.
- The administrator receives an alert or message if there is an infrastructure failure, allowing them to promptly take action to fix the problem.
- There is no cost associated with this tool.
Nagios Log Server
- It makes log data searching straightforward.
- All of the log data is stored in one place and is configured for high availability.
- If any problems are discovered in the log data, it can quickly transmit alarms.
- Your log analysis platform will have additional power, speed, storage, and dependability due to its capacity to grow to thousands of servers.
Nagios Fusion
- A centralized view of the entire monitoring system is offered by this solution.
- You can set up different monitoring servers for different regions using Nagios Fusion.
- To provide total infrastructure visibility, it is readily connected with Nagios XI and Nagios Core.
- The price of these tools is $2495.
Nagios Network Analyser
- For the admin to respond quickly, it provides all of the network infrastructure information, including any potential dangers.
- It provides extremely extensive network data that has been thoroughly analyzed. The instrument costs $1,995.
Nagios Installation
Certain components, such as Apache, PHP, building packages, etc., must be installed on your Ubuntu system before installing Nagios. So let’s start by installing them.
Step 1: Install the prerequisite packages by running the following command.
sudo apt-get install wget build-essential apache2 php apache2-mod-php7.0 php-gd
libgd-dev sendmail unzip
Step 2: Next, add the Nagios user and group to the 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: Get the most recent Nagios package.
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios- 4.4.3.tar.gz
Step 4: Unzip the compressed file.
tar -xzf nagios-4.4.3.tar.gz
cd nagios-4.4.3/
Step 5: Execute the following command to compile Nagios from the source.
./configure –with-nagios-group=nagios –with-command-group=nagcmd
Step 6: Execute the below command to generate Nagios files.
make all
Step 7: Execute the command displayed beneath to install every Nagios file.
sudo make install
Step 8: Execute the subsequent commands to set up external command configuration files and init.
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: Copy the event handler directory to the Nagios directory.
sudo cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
sudo chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
Step 10: Extract and download the 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: Use the command below to install Nagios plugins.
./configure –with-nagios-user=nagios –with-nagios-group=nagios –with-openssl
make
sudo make install
Step 12: Next, open the Nagios configuration file and remove the comment on line 51, which reads cfg_dir=/usr/local/nagios/etc/servers.
sudo gedit /usr/local/nagios/etc/nagios.cfg
Step 13: Make a server directory now.
sudo mkdir -p /usr/local/nagios/etc/servers
Step 14: Modify the contacts configuration file
sudo gedit /usr/local/nagios/etc/objects/contacts.cfg
Step 15: At this point, configure a user named Nagiosadmin and enable the Apache components.
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: At this point, restart Nagios and Apache.
service apache2 restart
service nagios start
cd /etc/init.d/
sudo cp /etc/init.d/skeleton /etc/init.d/Nagios
Step 17: Modify 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: Start Nagios by making the Nagios file executable.
sudo chmod +x /etc/init.d/nagios
service apache2 restart
service nagios start
Step 19: Open your browser and type in the following URL: http://localhost/nagios. Now sign in to Nagios using the nagiosadmin account and the password you previously set. The screenshot provided below displays the Nagios login interface.
If everything is done correctly, the Nagios web interface will appear. The Nagios dashboard is displayed as follows:
Nagios Configuration
The directory /usr/local/nagios/etc contains the Nagios configuration files. The picture below displays these files:
Now let’s examine the significance of each file.
Nagios.cfg
- This is Nagios Core’s primary configuration file.
- The location of the Nagios log file, the hosts and services state update interval, the lock file, and the status.dat file are all listed in this file.
- This file defines the Nagios users and groups that the instances are executing on.
- It has the paths to every single object configuration file, including contacts, templates, commands, and so forth.
cgi.cfg
Nagios’s CGI configuration file is called cgi.cfg by default. It provides the location of the primary configuration file to the CGIs.
- If the CGIs require any more data, they will read the host configuration file and the main file.
- It includes all of the user and group data, together with their permissions and rights.
- It also contains the path to every Nagios frontend file.
resource.cfg
This file allows you to define $USERx$ macros, which may then be utilized in command definitions in your host configuration file or files. For storing sensitive data like passwords and usernames, $USERx$ macros are helpful.
- They are also useful for setting the path to plugins and event handlers; you only need to update a few $USERx$ macros rather than changing numerous command definitions if you ever decide to relocate the plugins or event handlers to a different directory.
- Moreover, configuration instructions for external data sources like MySQL may be kept in resource files.
To define commands, contacts, hosts, services, and other items, go to the configuration files located inside the objects directory. Learn to enable infrastructure as a code in the DevOps process through our Ansible course in Chennai.
commands.cfg
You can refer to some sample command definitions in the host, service, and contact definitions found in this configuration file.
- You can check and keep an eye on hosts and services with these commands.
- These commands can be executed locally on a Linux console, and the output of the command you run will also be displayed.
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 includes Nagios contacts and group information. Nagios admin, by default, already has one contact.
Example
define contact {
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
email [email protected]
}
define contactgroup {
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}
Hosts and Services of Nagios
The most widely used program for keeping an eye on the hosts and services that are operating in your IT infrastructure is called Nagios. The fundamental components of Nagios Core are hosts and service configurations.
- Similar to a computer, a host can be either virtual or physical.
- Services are those that Nagios uses to investigate a host’s background.
You can mention the host and service definitions in a host file that you generate inside of Nagios’ server directory.
Example
sudo gedit /usr/local/nagios/etc/servers/ubuntu_host.cfg
Ubuntu Host Config File
define host {
use linux-server
host_name ubuntu_host
alias Ubuntu Host
address 192.168.1.10
register 1
}
define service {
host_name ubuntu_host
service_description PING
check_command check_ping!100.0,20%!500.0,60%
max_check_attempts 2
check_interval 2
retry_interval 2
check_period 24×7
check_freshness 1
contact_groups admins
notification_interval 2
notification_period 24×7
notifications_enabled 1
register 1
}
The mentioned specifications define the services that will be performed on the host ubuntu_host and add a host to it. The designated services will begin to function and this host will be monitored by Nagios as soon as you restart it.
Nagios offers a plethora of additional services that enable you to monitor almost anything on the active host. Upskill your development skills with our Git training in Chennai at SLA.
Commands in Nagios
A command is defined by its definition. The following commands are available: host checks, host notifications, host event handlers, and service checks. The commands.cfg file contains the Nagios command definitions.
The format to create a Command-Line interface is as follows:
define command {
command_name command_name
command_line command_line
}
Command name: This directive serves as the command’s identification. Command name references the definitions of contact, host, and service.
Command line: This directive specifies what commands are processed by Nagios when they are used for event handlers, notifications, or service or host checks.
Example
define command{
command_name check_ssh
command_line /usr/lib/nagios/plugins/check_ssh ‘$HOSTADDRESS$’
}
This command will launch the plugin: /usr/libl/nagios/plugins/check_ssh, passing in ‘$HOSTADDRESS$’ as a single parameter. This check command might be used in a very brief host definition like the one below:
define host{
host_name host_tutorial
address 10.0.0.1
check_command check_ssh }
Additionally, you can pass arguments to the command, which increases the flexibility of how the checks are carried out. This is the way a command with a parameter:
define command {
command_name check-host-alive-limits
command_line $USER5$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
}
The host specification for the command mentioned above:
define host {
host_name system2
address 10.0.15.1
check_command check-host-alive-limits!1000.0,70%!5000.0,100%
}
By adding external instructions to the commands file, which the Nagios daemon periodically processes, you can use them to conduct tasks outside of Nagios.
The external commands in Nagios that need to be entered in the command file have the following syntax:
[time] command_id;command_arguments
Learn the in-demand DevOps tools with our Jenkins training program to automate the major parts of software development.
Applications of Nagios
Nagios is useful for a variety of applications. Here they are provided:
- Monitor the disk space, system logs, and other host resources.
- Watch the following network resources: ftp, smtp, ssh, http, etc.
- To find infra-issues, regularly monitor log files.
- Track the status of web, Linux, Unix, and Windows apps.
- Services can be remotely monitored by Nagios Remote Plugin Executer (NRPE).
- Perform parallel service checks.
- Remote monitoring can also be done via SSL or SSH tunnels.
- Send notifications or alerts
- Via pager, SMS, or email about any infrastructure-related issue
- Advising when the IT infrastructure should be upgraded.
Advantages of Nagios
Nagios provides the following advantages to its users:
- It facilitates doing away with recurrent testing.
- When the wrist strap is still in the “intermittent” stage, it is able to identify split-second malfunctions.
- It lowers maintenance costs without compromising functionality.
- It notifies control and breakdown management in a timely manner.
Conclusion
The most widely used continuous monitoring tool is Nagios. The whole IT infrastructure, including all of its systems, apps, services, and procedures, is monitored. We hope that this Nagios lesson served as a good introduction for you to use Nagios. Thrive in your DevOps career with our Nagios course in Chennai.