How to install and configure nagios nrpe client in Ubuntu with apt-get command
A few days back I wrote on how to configure nagios server in Ubuntu 12.04.
In this tutorial we will learn how to monitor the ubuntu machines means we will install nrpe in ubuntu machines so that nagios server can monitor it.
NRPE works on port no. 5666.
Follow the steps to configure nrpe in Ubuntu systems :
note: here # prompt is for root and $ prompt is for non-root user.
Step 1 : Login in to the ubuntu client machine and become a superuser & do “apt-get update”(I prefer to work as root)
$ sudo su - # apt-get update
Step 2 : Now install nrpe,open-ssl and nagios plugins in ubuntu system
# apt-get install openssl nagios-nrpe-server nagios-plugins nagios-plugins-basic nagios-plugins-standard
Step 3: Take the backup of original nrpe.cfg file
# cp -p /etc/nagios/nrpe.cfg /etc/nagios/nrpe.cfg.orig
Step 4 : Now edit the /etc/nagios/nrpe.cfg file and in allowed_hosts give the ip address of Nagios Server from which monitoring will be done.
Below is the reference of my Nagios system’s nrpe.cfg file :
root@webserver:/etc/nagios# egrep -v '^#|^$' nrpe.cfg log_facility=daemon pid_file=/var/run/nagios/nrpe.pid server_port=5666 nrpe_user=nagios nrpe_group=nagios allowed_hosts=127.0.0.1,ip-address-of-nagios-server dont_blame_nrpe=0 debug=0 command_timeout=60 connection_timeout=300 command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10 command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20 command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1 command[check_zombie_procs]=/usr/lib/nagios/plugins/check_procs -w 5 -c 10 -s Z command[check_total_procs]=/usr/lib/nagios/plugins/check_procs -w 150 -c 200 include=/etc/nagios/nrpe_local.cfg include_dir=/etc/nagios/nrpe.d/ root@webserver:/etc/nagios#
Step 5 : Now restart the nagios-nrpe-server service in client machine.
/etc/init.d/nagios-nrpe-server restart
Now the given below steps should be done in Nagios Server
Step 6: Login into Nagios Server and do “sudo su – ” means become superuser
sudo su -
Step 7: Create a new file and give the name which must be relevant with your network.for eg. sharad-ec2-hosts.cfg . And add the hostname and its details which you want to monitor.
By doing this you are adding a server to monitor from Nagios Server.
vi /etc/nagios3/conf.d/sharad-ec2-hosts.cfg define host{ use generic-host; Name of host template to use host_name web.example.com alias Web Server address 10.10.10.23 }
Step 8: Now add the service to monitor for your nagios client (web.example.com).
In same file /etc/nagios3/conf.d/sharad-ec2-hosts.cfg add the below given lines.
Now through nrpe the check_disk plugin will check the disk.
vi /etc/nagios3/conf.d/sharad-ec2-hosts.cfg define service{ use generic-service ; Name of service template to use host_name web.example.com service_description Disk Space check_command check_nrpe!check_disk }
Step 9: Restart the following services
/etc/init.d/nagios3 restart /etc/init.d/apache2 restart
Note:
Question: Why we use check_nrpe!check_disk in check_command ?
answer=> Because check_nrpe is itself a plugin. The symbol ! tells what is the next argument. Here the next argument is check_disk. In nrpe.cfg file in Nagios Client (web.example.com) we are using the given below line and using the command name check_disk
see step 4 (the line command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1)
Hence the nrpe (port no. 5666)from nagios server will communicate to Nagios client at port no. 5666 and will search for argument in /etc/nagios/nrpe.cfg file. Here nrpe found the argumant check_disk.
Similarly you can add other commands to check.
I will recommend you to just explore all config files. Once you understand the concept you can easily play with Nagios server