How to Install and Configure Nagios Monitoring Software
Nagios is known as the top, open source solution to monitor your servers. It provides complete monitoring of Linux operating systems and distributions – including operating system metrics, service state, process state, file system usage and more. Server monitoring is easy with Nagios software because of flexibility to monitor your servers with both: agent based and agent-less monitoring.
Nagios monitoring system is useful for ensuring that your critical services are up and running. Using a monitoring service, such as Nagios, is an essential tool for all servers.
This tutorial will explain you how to install and set up Nagios monitoring system and web interface management to your Linux based server. We will use Ubuntu 14.04 x64 distribution as an example.
NOTE: You must have super user privileges in order to perform the steps explained below.
This part of tutorial will explain you how to install Nagios Core on your server. This procedure must be done only once.
Installation of Nagios core requires the local server to have at least 2 GB of SWAP memory, so you have to enable SWAP memory first.
On the VPS server you will have to upgrade your RAM memory at least to 4 GB if you want to have 2 GB of SWAP.
If you are planning to run Nagios on the dedicated server, so you must run following commands:
sudo mkswap /swap && sudo chown root. /swap && sudo chmod 0600 /swap && sudo swapon /swap
sudo sh -c “echo /swap swap swap defaults 0 0 >> /etc/fstab”
sudo sh -c “echo vm.swappiness = 0 >> /etc/sysctl.conf && sysctl -p”
Installing Required Packages
Nagios Core installation requires your operating system to be up to date and also have some development libraries, which allows you to compile the Core from the source, installed on your server.
First, update your operating system’s repository:
If you are installing Nagios on FRESH Ubuntu 14.04 installation, it is recommended to upgrade your existing operating system by running the following command:
NOTE: Do not upgrade your existing installation if you are already running any software on this server, as it may interrupt work of existing programs.
and then it is time to install required packages:
NOTE: By following this tutorial you will also install apache2 and php5 packages. Do not install them if you are using another package, such as Nginx, for Web Server.
Creating user and group
You have to create a new user and group for Nagios monitoring system. It will run all the processes under this user. Create a user named “nagios” and group named “naggrp”:
sudo groupadd naggrp
sudo usermod -a -G naggrp nagios
Install Nagios Core
Your server is now prepared for Nagios Core installation. First you have to download the source code of the latest stable Nagios Core version. It can be downloaded from Official Nagios website. You will be asked to provide some personal details of yours, however there is a small button “skip to download”, click on it if you do not want to receive the notifications about latest releases of Nagios. Download the latest version:
Extract the newly downloaded archive:
Go to the extracted folder:
Once you are in the Nagios installation folder, you have to configure it before installing:
Compile Nagios as follows:
Run the following commands in order to install Nagios, init scripts and sample 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/sites-available/nagios.conf
In order to be able to issue external command via the web interface, you have to add web server’s user to Nagios group:
Installation of Nagios Plugins
The installation of Nagios Core is completed, now you must download the latest stable version of Nagios plugins and install them. The latest plugins can be found in the official site of Nagios. Download the latest version:
Extract downloaded archive:
Navigate into newly extracted directory and configure the Nagios Plugins before the installation:
./configure –with-nagios-user=nagios –with-nagios-group=nagios –with-openssl
Compile Nagios Plugins as follows:
And, finally, install Nagios Plugins:
Installing Nagios RPE
Nagios RPE or Remote Plugins Executor allows users to execute Nagios Plugins on other Linux machines. It allows users to monitor remote machine metrics – CPU load, Disk usage and etc. The latest release of NRPE can be downloaded from official Nagios website.
In this tutorial, 2.15 version is used:
Extract downloaded archive:
Navigate to extracted directory:
Configure NRPE as follows:
Build and install NRPE using the following commands:
Sudo make install
Sudo make install-xinetd
Sudo make install-daemon-config
Edit the startup script of xinetd after the installation is finished using your favorite text editor, for example nano:
And edit only the only_from line by adding the IP of your Nagios Core server in order to allow incoming connections only from Nagios Core Server:
Save and exit and finally restart xinetd daemon:
Nagios installation is now completed. The next step is to configure it.
In this part of tutorial, you will learn how to perform basic configuration of Nagios. This part must be performed only once, on the Nagios Core server.
First, you have to organize your Nagios Core configuration. Open Nagios configuration file with your favorite text editor:
Search for the following line and uncomment it (delete # sign):
Save and exit.
Next – create folder, where Nagios Core will store information about server that are monitored:
Add your e-mail as contact e-mail address for notifications from Nagios Core server:
And change nagios@localhost to your e-mail address as displayed below:
Save the file and exit.
Define check_nrpe command
Add the new function, called check_nrpe to your Nagios configuration, which allows you to use check_nrpe command in your Nagios service definitions. Open the file where all commands are defined:
And add the following lines in the end of the file:
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
Save the file and exit.
Configure Apache Web Server
Nagios allows you to access the information about the servers you are monitoring via web interface, so in this part you will learn how to configure Apache Web Server properly.
First, you have to enable Rewrite and CGI modules:
sudo a2enmod cgi
Next, create user, named, for example “nagiosadmin”, which will be used to access Nagios Web Interface:
You will be asked to create the password. Enter it, and write down somewhere – you will need it to access Nagios Web Interface.
Enable Nagios Web interface by creating a symlink from Nagios configuration file to sites-enabled directory as follows:
Everything is set now. Finally, restart Nagios and Apache services:
sudo service apache2 restart
Nagios will not start on boot by default, however you can enable on boot start-up by running the following command:
Restricting Web Access for particular IP address
This part of tutorial is optional, but recommended. In this part you will learn how to restrict web access to Nagios Web Interface for particular IP address. It can be done by editing Apache’s configuration file:
And comment the following two lines (add # sign in front of them):
Allow from all
And uncomment the following lines (delete # sing in the front of them) and add the specific IP or range of IP addresses you want to allow to access Nagios Web Interface:
# Deny from all
# Allow from 127.0.0.1
As these lines will appear twice in the configuration file, so you will need to perform these steps once more.
Save the file, exit and restart Nagios and Apache services as displayed below:
sudo service apache2 restart
Everything is set now. Try to access your Nagios Core Web Interface.
Accessing Nagios Web Interface
In order to access Nagios Web Interface you have to open your favorite internet browser and type the following address in the navigation bar:
Nagios admin area cannot be accessed without identification. System will ask you to enter the username and password. You must enter the login credentials you have created earlier (nagiosadmin in my case). You will see Nagios Admin area after the successful login. Now click “Hosts” button which can be found in the left side. You will see that the Nagios Core server now is monitoring only localhost. That means that it monitors only itself.
Click on the “Statistic” icon in order to see detailed information:
Do not be afraid to try exploring the admin area by yourself.
In this part of tutorial you will learn how to add new services to your monitoring service. You must repeat these steps on all servers that you want to monitor. The server we use for example is also running Ubuntu 14.04 operating system.
First, update the repository of the server:
Install Nagios Plugins and Nagios Remote Plugins Executor (NRPE):
Configure Nagios NRPE server
Now you have to edit Nagios Remote Plugin Executor (NRPE) configuration file. Open configuration file with your favorite text editor:
Nagios NRPE configuration file is very big, however you are interested just in 3 lines. You have to specify the following values:
server_address – Enter the current IP address of your current Server (client).
allowed_hosts – Enter localhost IP address and the IP of your Nagios Core server.
command[/dev/hda1] – Change the values to your root filesystem’s name*.
as displayed in example below:
command[/dev/hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/ploop21979p1
NOTE: Filesystem’s name can be retrieved by running the command: df –h /:
/dev/ploop21979p1 20G 730M 18G 4% /
Save the file, exit the text editor and restart Nagios NRPE server:
Adding Host To Nagios Core Configuration
Almost everything is set at the moment. Now you just have to inform your Nagios Core server that you have the server which is waiting to be monitored.
Open the directory you previously defined as the place where you put the information about monitored servers:
and create the configuration file for the monitored server:
open this file:
and add the following lines:
alias My Monitored Server #1
}The most important parts in this text are:
alias My Monitored Server #1
You must change these values to your specific values of your Nagios server. Save the file and restart Nagios service:
Check Hosts section in Nagios Web Interface, the new host is already monitored:
The steps you provided so far will just check if the host is up or not. You can add any other services or processes to monitor on your Nagios Server by editing the same file. Let’s start to monitor how server is responding to ping:
and add the following line:
Add the following lines to monitor SSH service:
NOTE: Do not forget to change the host_name value to your own.
Save the file and restart Nagios Core server:
Check monitored services on your Host. As you can see SSH check has been included in Nagios Monitoring system for this host.
You can add even more services or processes to check in your Nagios configuration. The list of available commands can be found in /usr/local/nagios/etc/objects/commands.cfg file. Open the file:
and look for the sample commands section:
# SAMPLE SERVICE CHECK COMMANDS
# These are some example service check commands. They may or may not work on
# your system, as they must be modified for your plugins. See the HTML
# documentation on the plugins for examples of how to configure command definitions.
# NOTE: The following ‘check_local_…’ functions are designed to monitor
# various metrics on the host that Nagios is running on (i.e. this one).
################################################################################# ‘check_local_disk’ command definition
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
In this file there is a full list of basic commands, however If you are an experienced user, you can create your own, modified commands.
After reading this tutorial you should be able to set up, configure your own Nagios Core server and add hosts for monitoring to the configuration. This will help you to ensure that all your critical services are up and running and it successfully increases the stability of your servers. Nagios also allows users to set up notifications, which can be sent via e-mail or other channels in order to notify you about critical services being down or inaccessible. You can visit official website of Nagios in order to learn more about this useful and powerful monitoring tool.