Install Nagios and NRPE On CentOS 6 and Monitoring Windows with Nagios
This next step is where you get to specify any manual commands that Monitoring server can send via NRPE to these client hosts.
Make sure to change allowed_hosts to your own values.
Edit /etc/nagios/nrpe.cfg
Look for these lines and add them if they’re missing:
Restart the NSClient++ service:
Back on our Monitoring server, we will have to create config files for each of our client servers:
In this tutorial we will learn How to install and configure nagios server and install nrpe on client pc's. We will also do some configuration changes in nagios server so that we could monitor the servers.
In this scenario we will add a server to monitor.
Operating System : CentOS 6.3
Nagios Server : hostname: nagios-server , ip-address: 192.168.18.1
Nagios Client : hostname: linuxw-server-1 , ip-address: 192.168.18.128
Nagios Client : hostname : windows-server-1, ip-address: 192.168.18.129
First the install the prerequisites for Nagios Server(192.168.18.1)
[root@thelinuxwiki ~]# yum install -y gd gd-devel httpd php gcc glibc glibc-common
By default nagios is not found in CentOS official repository, so add the EPEL repository to install nagios.
[root@thelinuxwiki ~]# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
[root@thelinuxwiki ~]# rpm -ivh epel-release-6-8.noarch.rpm
Now install nagios in 192.168.18.1 Server
[root@thelinuxwiki ~]# yum install -y nagios*
Nagios Server : hostname: nagios-server , ip-address: 192.168.18.1
Nagios Client : hostname : windows-server-1, ip-address: 192.168.18.129
Configure Nagios
Add the admin mail address in the nagios contact file to receive alerts from nagios server.
[root@thelinuxwiki]# vi /etc/nagios/objects/contacts.cfg
### Line 35 - Edit the mail id ###
email admin@thelinuxwiki.in ;
[root@thelinuxwiki]# egrep -v '^#|^$' /etc/nagios/objects/contacts.cfg define contact{ contact_name nagiosadmin ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of user email UREMAILID@gmail.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } define contact{ contact_name naveencontact ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias Nagios Admin ; Full name of user email naveen@thelinuxwiki.in ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** } define contactgroup{ contactgroup_name admins alias Nagios Administrators members nagiosadmin,naveencontact }
Edit the following lines in nagios config file
[root@thelinuxwiki]#vi /etc/httpd/conf.d/nagios.conf
## Comment Lines 15 & 16 ##
# Order allow,deny
# Allow from all
## Uncomment and Change lines 17,18 & 19 as shown below ##
Order deny,allow
Deny from all
Allow from 127.0.0.1 192.168.1.0/24
Set nagiosadmin password
[root@server ~]# htpasswd /etc/nagios/passwd nagiosadmin New password: Re-type new password: Updating password for user nagiosadmin
Start nagios and httpd services and let them to start automatically on every boot.
[root@thelinuxwiki]#/etc/init.d/nagios start Starting nagios: done. [root@thelinuxwiki]# /etc/init.d/httpd start Starting httpd: [ OK ] [root@thelinuxwiki]#chkconfig nagios on [root@thelinuxwiki]#chkconfig httpd onOpen nagios administrator console and enter the nagiosadmin password as created before
Adding clients to Nagios server
Now we should add our hosts that will be monitored by Nagios. For example, we will use linux-server-1 (198.168.18.128) and windows-server-1 (198.168.18.129).
From public ports, we can monitor ping, any open ports such as webserver, e-mail server, etc.
For internal services that are listening on localhost, such as MySQL, memcached, system services, we will need to use NRPE.
From public ports, we can monitor ping, any open ports such as webserver, e-mail server, etc.
For internal services that are listening on localhost, such as MySQL, memcached, system services, we will need to use NRPE.
Install NRPE on Clients-192.168.18.128
[root@thelinuxwiki ~] # rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm [root@thelinuxwiki ~] # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm [root@thelinuxwiki ~] # yum -y install nagios-plugins-all nrpe openssl [root@thelinuxwiki ~] # chkconfig nrpe on
This next step is where you get to specify any manual commands that Monitoring server can send via NRPE to these client hosts.
Make sure to change allowed_hosts to your own values.
Edit /etc/nagios/nrpe.cfg
log_facility=daemon pid_file=/var/run/nrpe/nrpe.pid server_port=5666 nrpe_user=nrpe nrpe_group=nrpe allowed_hosts=192.168.18.1 # This is the Nagios Server IP address dont_blame_nrpe=1 debug=0 command_timeout=60 connection_timeout=300 include_dir=/etc/nrpe.d/ command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10 command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20 command[check_disk]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1 command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200 command[check_procs]=/usr/lib64/nagios/plugins/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
Note: In above block you can see command are already defined. for eg. command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
just keep a note of it.The nrpe will use only these commands or plugins in nagios client which are defined in nrpe.cfg file. If you want to add any other command or plugin you have to edit the nrpe.cfg file in same manner.
for eg. command[check_pluginName]=/usr/lib/nagios/plugins/check_pluginName -w <value> -c <value>
In check_disk above, the partition being checked is /dev/sda1 - make sure your droplet has the same partition by running df -h /
You can also modify when to trigger warnings or critical alerts - above configuration sets Warning at 20% free disk space remaining, and Critical alert at 10% free space remaining.
If you want change any arguments you can change as per your requirement, but follow
the same syntax while editing or creating new rule.
Now you can start NRPE on all of your client hosts:
[root@thelinuxwiki]# service nrpe start
Install NRPE on Clients-192.168.18.129(Windows-Server-1)
Windows configuration
Install NSClient++ on the Windows host.
Install NSClient++ on the Windows host.
Download and install.
Also if you want to check for a newer version. Here’s the full list: http://nsclient.org/nscp/downloads
Also if you want to check for a newer version. Here’s the full list: http://nsclient.org/nscp/downloads
Here’s a screenshot of one part of the installation.
Those are the features that I chose. Enable at least common check plugins and nsclient server.
Look for these lines and add them if they’re missing:
allowed hosts = 192.168.18.1
password =
port = 12489
Restart the NSClient++ service:
Start > Administrative tools > Services
Configuration in windows server has been completed
Now goto Nagios Server and Add the Two Clients(Linux-192.168.18.128 and Windows-192. 168.18.129) in nagios configuration file
Add Server Configurations on Monitoring Server
Back on our Monitoring server, we will have to create config files for each of our client servers:
[root@thelinuxwiki]# echo "cfg_dir=/etc/nagios/servers" >> /etc/nagios/nagios.cfg [root@thelinuxwiki]# cd /etc/nagios/servers [root@thelinuxwiki]# touch linux-server-1.cfg [root@thelinuxwiki]# touch windows-server-1.cfg
Edit each client's configuration file and define which services you would like monitored.
First We will configure linux-server-1(192.168.18.128)
[root@linux-servers]# vi /etc/nagios/servers/linux-server-1.cfg
[root@thelinuxwiki]# vi /etc/nagios/servers/windows-server-1.cfg[root@thelinuxwiki]# egrep -v '^#|^$' /etc/nagios/servers/linux-server-1.cfg define host { use linux-server host_name linux-server-1 alias server1 address 192.168.18.128 max_check_attempts 5 check_period 24x7 notification_interval 30 notification_period 24x7 } define service { use generic-service host_name server1 service_description PING check_command check_ping!100.0,20%!500.0,60% } define service { use generic-service host_name server1 service_description SSH check_command check_ssh notifications_enabled 0 } define service { use generic-service host_name server1 service_description CPU Load check_command check_nrpe!check_load } define service { use generic-service host_name server1 service_description login users check_command check_nrpe!check_users } define service { use generic-service host_name server1 service_description hard disk space check_command check_nrpe!check_sda3 } [root@thelinuxwiki]#
[root@thelinuxwiki]# egrep -v '^#|^$' /etc/nagios/servers/windows-server-1.cfg define host{ use windows-server ; Inherit default values from a template host_name windows-server-1 ; The name we're giving to this host alias My Windows Server ; A longer name associated with the host address 192.168.18.129 ; IP address of the host } define hostgroup{ hostgroup_name windows-servers ; The name of the hostgroup alias Windows Servers ; Long name of the group } define service{ use generic-service host_name windows-server-1 service_description NSClient++ Version check_command check_nt!CLIENTVERSION } define service{ use generic-service host_name windows-server-1 service_description Uptime check_command check_nt!UPTIME } define service{ use generic-service host_name windows-server-1 service_description CPU Load check_command check_nt!CPULOAD!-l 5,80,90 } define service{ use generic-service host_name windows-server-1 service_description Memory Usage check_command check_nt!MEMUSE!-w 80 -c 90 } define service{ use generic-service host_name windows-server-1 service_description C:\ Drive Space check_command check_nt!USEDDISKSPACE!-l c -w 85 -c 90 } define service{ use generic-service host_name windows-server-1 service_description W3SVC check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC } define service{ use generic-service host_name windows-server-1 service_description Explorer check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe } [root@thelinuxwiki]#Finally, after you are done adding all the client configurations, you should set folder permissions correctly and restart Nagios on your Monitoring Server:chown -R nagios. /etc/nagios service nagios restartLet’s see what our nagios web page tells us:http://192.168.18.1/nagiosGo to the Services on left hand menu and you should see something similiar to this:
Note: You have to add following into commands.cfg of your nagios server[root@thelinuxwiki.in]# vi /etc/nagios/objects/commands.cfg# 'check_nt' command definition # This is for Windows Clients define command{ command_name check_nt command_line $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -v $ARG1$ $ARG2$ } # 'check_nrpe' command definition # This is for Linux Clients define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$