Nagios is the most popular, open source, powerful monitoring system for any kind of infrastructure. It enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes. Nagios has capability of monitoring application, services, entire IT infrastructure.
This article will help you to setup Nagios Monitoring Server on Ubuntu 14.10, 14.04 LTS and 12.04 LTS and Debian systems. After completed this article, you will like to follow below article.
How to Monitor remote Linux host using Nagios
How to Monitor remote Windows host using Nagios
Install Required Packages and Dependencies
We assume that you have fresh installed Ubuntu/Debian systems, So our first requirement is to install Apache and PHP first. Use the following commands to complete it. You can find detailed LAMP setup instructionhere.
Install Required Packages:
$ sudo apt-get install wget apache2 apache2-utils php5 libapache2-mod-php5 build-essential libgd2-xpm-dev
Start Services:
$ service apache2 start
Setup User Account for Nagios
Now create a new nagios user account and setup a password to this account
$ sudo useradd nagios $ sudo passwd nagios
Now create a groud for nagios setup “nagcmd” and add nagios user to this group. Also add nagios user in apache group.
$ sudo groupadd nagcmd $ sudo usermod -a -G nagcmd nagios $ sudo usermod -a -G nagcmd www-data
Installing Nagios Core Service
After installing required dependencies and adding user accounts. Lets start with Nagios core installation. Download latest nagios core service from official site.
$ cd /opt/ $ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz $ tar xzf nagios-4.0.8.tar.gz $ cd nagios-4.0.8 $ sudo ./configure --with-command-group=nagcmd $ sudo make all $ sudo make install $ sudo make install-init $ sudo make install-config $ sudo make install-commandmode
Now create nagios apache2 configuration file.
$ sudo vim /etc/apache2/sites-enabled/nagios.conf
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" <Directory "/usr/local/nagios/sbin"> Options ExecCGI AllowOverride None Order allow,deny Allow from all AuthName "Restricted Area" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user </Directory> Alias /nagios "/usr/local/nagios/share" <Directory "/usr/local/nagios/share"> Options None AllowOverride None Order allow,deny Allow from all AuthName "Restricted Area" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user </Directory>
Configuring Apache Authentication
We need to setup apache authentication for user nagiosadmin. Untill more specific reason use this user name as “nagiosadmin” else you would required more changes in configuration.
$ htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Now restart Apache service to make the new settings take effect.
$ service apache2 restart
Installing Nagios Plugins
After installing and configuring Nagios core service, Download latest nagios-plugins source and install using following commands.
$ cd /opt $ wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz $ tar xzf nagios-plugins-2.0.3.tar.gz $ cd nagios-plugins-2.0.3
Now compile and install nagios plugins
$ sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios $ sudo make $ sudo make install
Verify Configuration and Start Nagios
Use the following commands to verify Nagios install and start Nagios core service.
$ /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg $ service nagios start
Also configure Nagios to auto start on system boot.
$ ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
Access Nagios Web Interface
Access your nagios setup by access nagios server using hostname or ip address followed by /nagios.
[change domain name with your domain or ip]
http://svr1.tecadmin.net/nagios/
Prompting for Apache Authentication Password –
Now you have successfully installed and configured Nagios Monitoring Server core service in your system.
How to Monitor Remote Linux Host using Nagios and NRPE
NRPE is known as Nagios Remote Plugin Executor. The NRPE add-on is designed to execute plugins on remote Nix systems. In this setup NRPE daemon is installed on remote system to which services need to monitor through nagios server. NRPE runs as daemon on remote systems and wait for nagios requests. When nagios server need to check status of any resources or applications to that remote host, sends and commands signal, which command definition is stored on NRPE service. NRPE takes nagios server request and execute command on local system and sends the result back to nagios.
This article will help you to install NRPE service on your Linux system and add host in nagios for monitoring.
Step 1: Setup NRPE Service on Linux Host
1.1- Install NRPE
Firstly we would require to install nrpe service on remote Linux system, which we need to monitory through nagios server.
On CentOS/RHEL/Fedora
# yum install nrpe nagios-plugins\*
On Debian/Ubuntu/LinuxMint
# sudo apt-get install nagios-nrpe-server nagios-plugins
1.2- Configure NRPE
After successfully installing NRPE service, Edit nrpe configuration file (/etc/nagios/nrpe.cfg) in your favorite editor and add your nagios service ip in allowed hosts. For example your nagios server ip is 192.168.1.100.
# vim /etc/nagios/nrpe.cfg
allowed_hosts=127.0.0.1, 192.168.1.100
After making above changes in nrpe configuration file, Lets restart NRPE service as per your system
On CentOS/RHEL/Fedora # service nrpe restart On Debian/Ubuntu/LinuxMint $ sudo /etc/init.d/nagios-nrpe-server restart
1.3- Verify Connectivity from Nagios
Now make sure your nagios is able to connect nrpe client on remote Linux system. Login to your nagios server from command line and execute following command. For example your client system ip is 192.168.1.11
# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.11 NRPE v2.14
Step 2: Add Linux Host in Nagios
We recommend to use NagiosQL3 web interface for managing configuration of nagios server. Below steps is for CLI lovers. To add host in your nagios server from command line.
First create a configuration file/usr/local/nagios/etc/servers/MyLinuxHost001.cfg using below values. for example you Linux hosts ip is 192.168.1.11. We also need to define a service with host. So add a ping check service, which will continuously check that host is up or not.
# vim /usr/local/nagios/etc/servers/MyLinuxHost001.cfg
######################################################### # Linux Host 001 configuration file ######################################################### define host { use linux-server host_name Linux_Host_001 alias Linux Host 001 address 192.168.1.11 register 1 } define service{ host_name Linux_Host_001 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 24x7 check_freshness 1 contact_groups admins notification_interval 2 notification_period 24x7 notifications_enabled 1 register 1 } ######################################################### # END OF FILE #########################################################
Now verify configuration files using following command. If there are no errors found in configuration, restart nagios service.
# nagios -v /usr/local/nagios/etc/nagios.cfg # service nagios restart
Step 3: Check Host in Nagios Web Interface
Open your nagios web interface and check for new Linux hosts added in nagios core service. In my case it looks like below.
How to Monitor Remote Windows Host using Nagios
Nagios is most powerful infrastructure monitoring tools. Our earlier articles describes nagios core service installation and configure nagiosql with nagios core server. In this articles we are going to configure windows hosts to be monitor by Nagios server.
Similar to NRPE service on Linux, NSClinet++ is the service for windows hosts to monitor through check_nrpe from nagios server. “How to Install and Configure NSClient++ and Monitor Remote Windows Host”
Step 1: Download and Install NSClient++
Download the latest version of NSClient from its official site and start installation as below. The software will be named NSCP-xxxxxx.msi. During installation process, you would require to enter nagios server to allow server to connect nsclient through nrpe.
START the installation using .msi file
Accept the license terms and click Next
Click on Complete setup type
Select the permissions on nsclient++ configuration file
Enter Nagios server ip in Allowed Hosts and enter password
Click on Install button
Finish Installation
Step 2: Verify Connectivity from Nagios Server
After installing NSClient++ on your system. Let’s verify that your nagios server is properly connecting to windows client through nrpe service. To do this login to your nagios server and run following command. For example my windows client ip is 192.168.1.10.
# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.10 [Sample Output] I (0,4,1,105 2014-04-28) seem to be doing fine...
You nagios client setup has been completed on your windows host. Now you can add this host in nagios server.
Step 3: Adding Host in Nagios using Configuration File
We recommend to use NagiosQL3 for configuration nagios. It provides a user friendly web interface for managing your nagios service. In case you are not using nagiosql and want to add your host in nagios server.
Create a configuration file/usr/local/nagios/etc/servers/MyWindowsHost001.cfg using below values. for example you windows hosts ip is 192.168.1.10. We also need to define a service with host. So add a ping check service, which will continuously check that host is up.
######################################################### # Windows Host 001 configuration file ######################################################### define host { use windows-server host_name Windows_Host_001 alias Windows Host 001 address 192.168.1.10 register 1 } define service{ host_name Windows_Host_001 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 24x7 check_freshness 1 contact_groups admins notification_interval 2 notification_period 24x7 notifications_enabled 1 register 1 } ######################################################### # END OF FILE #########################################################
Now verify configuration files using following command. If there are no errors found in configuration, restart nagios service.
# nagios -v /usr/local/nagios/etc/nagios.cfg # service nagios restart
Now open your nagios web interface and check for new hosts added in nagios core service. In my case it looks like below.