Nagios Core is free & open source monitoring tool or software which can monitor the resources like servers, network equipment like firewall, network switches and printers etc. Nagios core also provides alerting services, using which nagios informs administrators about issue that has occurred & then trigger alerts again when the issue has been resolved.
Nagios provides information like CPU utilization, Disk utilization, Memory utilization & also has support for a number of networking protocols like SMTP, HTTP, POP3, SNMP, ICMP, FTP, SSH etc. Nagios shows all the information regarding all the servers on a single screen using its web-interface.
Recently, Nagios core released 4.3.2 version of nagios core & 2.2.1 version of nagios plugins. In this tutorial, we are going to install & configure the latest version of Nagios server on CentOS 7 / RHEL 7 & then will add a windows machine for monitoring. So let’s start with installation
Step:1 Installing essential packages
We need to install some essential packages like apache, php & packages required for building the source packages, use below command to install these pakages
[root@linuxtechi ~]# yum install httpd php gcc glibc glibc-comman gd gd-devel make net-snmp unzip -y
Step:2 Downloading and extracting the Nagios packages
Next thing to do is to download & extract the nagios & its plugins files. The download links are mentioned below
[root@linuxtechi ~]# wget https://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.3.2/nagios-4.3.2.tar.gz [root@linuxtechi ~]# wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
To extract the packages, run following commands
[root@linuxtechi ~]# tar -zxvf nagios-4.3.2.tar.gz [root@linuxtechi ~]# tar -zxpvf nagios-plugins-2.2.1.tar.gz
Step:3 Create user and group for Nagios
Next step is to create a user named ‘nagios‘ & a group named ‘nagcmd‘ for running nagios,
[root@linuxtechi ~]# useradd nagios [root@linuxtechi ~]# passwd nagios [root@linuxtechi ~]# groupadd nagcmd
Once the user & group has been added, we will now add the user nagios & apache user to the created group i.e. nagcmd
[root@linuxtechi ~]# usermod -G nagcmd nagios [root@linuxtechi ~]# usermod -G nagcmd apache
Step:4 Installing Nagios core
We are now ready to install the nagios on our server, so go to the folder with extracted nagios core files & compile the extracted files
[root@linuxtechi ~]# cd nagios-4.3.2 [root@linuxtechi nagios-4.3.2]# ./configure --with-command-group=nagcmd
Next we will install the compiled nagios package by running,
[root@linuxtechi nagios-4.3.2]# make all [root@linuxtechi nagios-4.3.2]# make install
After running these, we need to install init scripts, command mode (to make nagios work from CLI) & also need to install some sample Nagios files
[root@linuxtechi nagios-4.3.2]# make install-init [root@linuxtechi nagios-4.3.2]# make install-commandmode [root@linuxtechi nagios-4.3.2]# make install-config
Step:5 Configuring Nagios Core Web-Interface
We will now install the web interface for the nagios, as we will be using web interface for monitoring the resources of the client systems. To install web interface, run
[root@linuxtechi nagios-4.3.2]# make install-webconf
Web interface will be installed with a default user by the name ‘nagiosadmin‘ but there will be no default password for the user. We will create default password for user by issuing the following command,
[root@linuxtechi nagios-4.3.2]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password: Adding password for user nagiosadmin [root@linuxtechi nagios-4.3.2]#
Step:6 Configuring email alerts
Though this is an optional step but consider doing it. By configuring an email to receive alerts on nagios, you will remain informed of all the server activities 24/7. To configure an email, open
[root@linuxtechi ~]# vi /usr/local/nagios/etc/objects/contacts.cfg
and enter an email address.
Next, restart apache server for changes to take effect.
[root@linuxtechi ~]# systemctl restart httpd
Step:7 Installing the Nagios Plugins
We have now completed installation for nagios core but we need to install plugins as without them we can’t monitor the resources. So open the directory with nagios plugin files & then we will compile & install the plugins
[root@linuxtechi ~]# cd nagios-plugins-2.2.1/ [root@linuxtechi nagios-plugins-2.2.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios [root@linuxtechi nagios-plugins-2.2.1]# make [root@linuxtechi nagios-plugins-2.2.1]# make install
Installation of nagios plugins is also complete.
Step:7 Verify Nagios files
Last step is now to verify Nagios configuration file against a sample configuration file
[root@linuxtechi ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Output will be something like below
This will ensure that all the settings made to nagios configuration file are correct & if there is any issue with file, it will report that as well. After making sure that config file is error less, we will restart the nagios & apache service to implement the changes.
[root@linuxtechi ~]# systemctl restart nagios [root@linuxtechi ~]# systemctl restart httpd
Also make sure that these services restart after a reboot,
[root@linuxtechi ~]# systemctl enable nagios [root@linuxtechi ~]# systemctl enable httpd
Note: In Case OS firewall in enabled on your Nagios server then allow 80 port using beneath commands
[root@linuxtechi ~]# firewall-cmd --permanent --add-port=80/tcp success [root@linuxtechi ~]# firewall-cmd --reload success [root@linuxtechi ~]#
Step:8 Logging into Nagios Web-interface
Now to check the status of the services, login to the nagios web interface by using the ip address of the nagios server followed by /nagios
You will now be asked to provide the credentials, Use nagiosadmin as user name and password that we set in above steps. Once authenticated we can access the home page of nagios server. Below mentioned are the screenshots of various pages available on the interface.
But as you can see Nagios is only showing services that are from Localhost i.e. system on which has been installed. We will now add a windows machine to be monitored by Nagios server.
Adding a Windows host to Nagios Monitoring Server
We will firstly setup the client machine & then will make changes to nagios server. For adding a windows host for monitoring on Nagios, we will need a software called NSClient++. We can download it from https://sourceforge.net/projects/nscplus/files/latest/download, once downloaded we will start the setup by double clicking the downloaded .msi file.
1- Hit ‘Next’ on the first screen, once the installation starts
2- Now, accept the license agreement & hit ‘Next’
3- On the next screen, click on ‘Typical’
4- Leave the following screen as it is & hit ‘Next’
5- Here on this screen, enter the IP address of Nagios server (for us it’s 192.168.0.20) & press ‘Next’
6- Click on ‘Install’ & wait for the installation to complete. Once its complete, hit ‘Finish’
Changes on Nagios server
Once the settings on the client side are complete, we need to make changes to configuration file of nagios. Open the file /usr/local/nagios/etc/nagios.cfg
[root@linuxtechi ~]# vi /usr/local/nagios/etc/nagios.cfg
Uncomment the following line
Save file and exit. Next open the file /usr/local/nagios/etc/objects/windows.cfg
[root@linuxtechi ~]# vi /usr/local/nagios/etc/objects/windows.cfg
This file contains a host definition which can be used as a reference to create the host definition for our window client machine. Edit the hostname & IP address to match your own windows machine, below the host definition are some Service Definitions, here we can add more services definition. Make sure that hostname is changed to your windows client name in all the services. Once done making changes, save file & exit.
Now restart your nagios server & check if the windows host has been added or not to nagios for monitoring, by browsing to ‘HOSTS‘ under current status.
Our host has been successfully added to nagios for monitoring. Similarly we can add more servers in nagios for monitoring & once any service is affected, nagios will show the status on web console & will also send an alert notification to email the address mentioned in contacts.cfg file.