{"id":12567,"date":"2022-05-04T22:26:48","date_gmt":"2022-05-04T19:26:48","guid":{"rendered":"https:\/\/kifarunix.com\/?p=12567"},"modified":"2024-03-09T14:29:33","modified_gmt":"2024-03-09T11:29:33","slug":"install-nagios-nrpe-agents-on-ubuntu-22-04-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-nagios-nrpe-agents-on-ubuntu-22-04-ubuntu-20-04\/","title":{"rendered":"Install Nagios NRPE Agents on Ubuntu 22.04\/Ubuntu 20.04"},"content":{"rendered":"\n
This guide describes how to easily install Nagios NRPE Agents on Ubuntu 22.04\/Ubuntu 20.04. If you want to monitor your Ubuntu hosts using Nagios server, then you need to have the NRPE<\/a> agents installed on these hosts. Nagios Remote Plugin Executor (NRPE) allows you to remotely execute Nagios plugins on other Linux\/Unix machines to query machine metrics such as disk usage, CPU load, etc.<\/p>\n\n\n\n Before you can now start to monitor hosts using Nagios server, you need to add them hosts to Nagios server.<\/p>\n\n\n\n Follow the guide below to add hosts to Nagios server for monitoring.<\/p>\n\n\n\n Add Hosts to Nagios Server For Monitoring<\/a><\/p>\n\n\n\n Nagios NRPE agents:<\/p>\n\n\n\n NRPE agents are available on the default Ubuntu repositories.<\/p>\n\n\n\n NRPE 4.0.3, which is the current stable latest release<\/a> as of this writing is available for installation.<\/p>\n\n\n\n On Ubuntu 20.04, the default repos do not have the latest version of NRPE.<\/p>\n\n\n\n To ensure you install the latest version of Ubuntu 20.04, then you need to build from the source.<\/p>\n\n\n\n You can as well build Nagios NRPE agent from the source code.<\/p>\n\n\n\n To install Nagios NRPE from source code;<\/p>\n\n\n\n Install Required Build Packages<\/p>\n\n\n\n Next, download the current release version of NRPE source code from the releases <\/a>page.<\/p>\n\n\n\n Extract the source archive<\/p>\n\n\n\n Compile the agent;<\/p>\n\n\n\n Sample summary;<\/p>\n\n\n\n Create NRPE nagios user and group;<\/p>\n\n\n\n Install NRPE binary files;<\/p>\n\n\n\n Install NRPE configuration files;<\/p>\n\n\n\n The configs are placed under Update services file to define NRPE service and respective port on which it listens on;<\/p>\n\n\n\n Install NRPE service;<\/p>\n\n\n\n This creates a systemd unit file, Hence you can start and enable NRPE to run on boot;<\/p>\n\n\n\n Download plugins from downloads page<\/a>.<\/p>\n\n\n\n The plugins are installed under When installed from the APT repos, the default Nagios NRPE configuration is When installed from the source, the default configuration file is The configuration files are well commented. This is how the config looks like with no comments;<\/p>\n\n\n\n In most cases, the configs above would suffice to monitor the host agent metrics.<\/p>\n\n\n\n However, there are a few parameters that you might want to update:<\/p>\n\n\n\n Update this parameter to include the IP address of the monitoring server. For example, in my setup, the IP address of the Nagios server is 192.168.56.124. Hence, this parameter is updated such that it looks like;<\/p>\n\n\n\n The others include the commands to check various metrics. Below are my updated commands based on host agent.<\/p>\n\n\n\n The NRPE installed from the APT, the plugins path is set to In general, this is how my configuration is like;<\/p>\n\n\n\n Run the commands below to start and enable nrpe to run on system boot.<\/p>\n\n\n\n To check the status of NRPE agent;<\/p>\n\n\n\n if you installed from the source, then the service name is NRPE uses port TCP 5666 by default. If firewall is running, open this port to allow external checks from Nagios Monitoring server.<\/p>\n\n\n\n If you are using your IP tables;<\/p>\n\n\n\n Check to see if port 5666\/tcp is listening;<\/p>\n\n\n\n If you already added hosts to Nagios and defined the services, then such is the example of how they should look on Nagios dashboard.<\/p>\n\n\n\n Hosts;<\/p>\n\n\n\n Services;<\/p>\n\n\n\nInstall Nagios NRPE Agents on Ubuntu 22.04\/Ubuntu 20.04<\/h2>\n\n\n\n
Install Nagios NRPE Agent From Default Ubuntu Repos<\/h3>\n\n\n\n
On Ubuntu 22.04;<\/h4>\n\n\n\n
apt-cache policy nagios-nrpe-server<\/code><\/pre>\n\n\n\n
nagios-nrpe-server:\n Installed: (none)\n Candidate: 4.0.3-1ubuntu2\n Version table:\n 4.0.3-1ubuntu2 500\n 500 http:\/\/ke.archive.ubuntu.com\/ubuntu jammy\/universe amd64 Packages\n<\/code><\/pre>\n\n\n\n
apt install nagios-nrpe-server<\/code><\/pre>\n\n\n\n
On Ubuntu 20.04<\/h4>\n\n\n\n
apt-cache policy nagios-nrpe-server<\/code><\/pre>\n\n\n\n
nagios-nrpe-server:\n Installed: (none)\n Candidate: 4.0.0-2ubuntu1\n Version table:\n 4.0.0-2ubuntu1 500\n 500 http:\/\/ke.archive.ubuntu.com\/ubuntu focal\/universe amd64 Packages\n<\/code><\/pre>\n\n\n\n
Install Nagios NRPE Agent from Source Code<\/h3>\n\n\n\n
apt update<\/code><\/pre>\n\n\n\n
apt install -y autoconf automake gcc libc6 libmcrypt-dev make libssl-dev wget<\/code><\/pre>\n\n\n\n
Download NRPE Source Archive<\/h4>\n\n\n\n
wget https:\/\/github.com\/NagiosEnterprises\/nrpe\/releases\/download\/nrpe-4.0.3\/nrpe-4.0.3.tar.gz<\/code><\/pre>\n\n\n\n
Install Nagios NRPE Agent from Source Code<\/h4>\n\n\n\n
tar xzf nrpe-4.0.3.tar.gz<\/code><\/pre>\n\n\n\n
cd nrpe-4.0.3\/<\/code><\/pre>\n\n\n\n
.\/configure --enable-command-args<\/code><\/pre>\n\n\n\n
\n*** Configuration summary for nrpe 4.0.3 2020-04-28 ***:\n\n General Options:\n -------------------------\n NRPE port: 5666\n NRPE user: nagios\n NRPE group: nagios\n Nagios user: nagios\n Nagios group: nagios\n\n\nReview the options above for accuracy. If they look okay,\ntype 'make all' to compile the NRPE daemon and client\nor type 'make' to get a list of make options.\n<\/code><\/pre>\n\n\n\n
make all<\/code><\/pre>\n\n\n\n
make install-groups-users<\/code><\/pre>\n\n\n\n
make install<\/code><\/pre>\n\n\n\n
make install-config<\/code><\/pre>\n\n\n\n
\/usr\/local\/nagios\/etc<\/code> directory as
nrpe.cfg<\/code>.<\/p>\n\n\n\n
echo \"nrpe\t\t5666\/tcp\t# Nagios NRPE\" >> \/etc\/services<\/code><\/pre>\n\n\n\n
make install-init<\/code><\/pre>\n\n\n\n
\/lib\/systemd\/system\/nrpe.service<\/strong><\/code>.<\/p>\n\n\n\n
systemctl enable --now nrpe<\/code><\/pre>\n\n\n\n
Install Nagios Plugins on Ubuntu 22.04\/Ubuntu 20.04<\/h3>\n\n\n\n
wget https:\/\/nagios-plugins.org\/download\/nagios-plugins-2.3.3.tar.gz<\/code><\/pre>\n\n\n\n
tar xzf nagios-plugins-2.3.3.tar.gz<\/code><\/pre>\n\n\n\n
cd nagios-plugins-2.3.3\n.\/configure\nmake\nmake install<\/code><\/pre>\n\n\n\n
\/usr\/local\/nagios\/libexec\/<\/code> directory.<\/p>\n\n\n\n
How to Configure NRPE Agent<\/h3>\n\n\n\n
\/etc\/nagios\/nrpe.cfg<\/strong><\/code>.<\/p>\n\n\n\n
\/usr\/local\/nagios\/etc\/nrpe.cfg<\/code>.<\/p>\n\n\n\n
grep -vE \"^.*#|^$\" \/usr\/local\/nagios\/etc\/nrpe.cfg<\/code><\/pre>\n\n\n\n
\nlog_facility=daemon\ndebug=0\npid_file=\/usr\/local\/nagios\/var\/nrpe.pid\nserver_port=5666\nnrpe_user=nagios\nnrpe_group=nagios\nallowed_hosts=127.0.0.1,::1\ndont_blame_nrpe=0\nallow_bash_command_substitution=0\ncommand_timeout=60\nconnection_timeout=300\ndisable_syslog=0\ncommand[check_users]=\/usr\/local\/nagios\/libexec\/check_users -w 5 -c 10\ncommand[check_load]=\/usr\/local\/nagios\/libexec\/check_load -r -w .15,.10,.05 -c .30,.25,.20\ncommand[check_hda1]=\/usr\/local\/nagios\/libexec\/check_disk -w 20% -c 10% -p \/dev\/hda1\ncommand[check_zombie_procs]=\/usr\/local\/nagios\/libexec\/check_procs -w 5 -c 10 -s Z\ncommand[check_total_procs]=\/usr\/local\/nagios\/libexec\/check_procs -w 150 -c 200\n<\/code><\/pre>\n\n\n\n
allowed_hosts=127.0.0.1,::1<\/code><\/pre>\n\n\n\n
allowed_hosts=127.0.0.1,192.168.56.124<\/code><\/pre>\n\n\n\n
command[check_users]=\/usr\/local\/nagios\/libexec\/check_users -w 5 -c 10\ncommand[check_load]=\/usr\/local\/nagios\/libexec\/check_load -r -w 15,10,5 -c 30,25,20\ncommand[check_disk]=\/usr\/local\/nagios\/libexec\/check_disk -w 20% -c 10% -p \/dev\/sda1\ncommand[check_zombie_procs]=\/usr\/local\/nagios\/libexec\/check_procs -w 5 -c 10 -s Z\ncommand[check_total_procs]=\/usr\/local\/nagios\/libexec\/check_procs -w 150 -c 200\n<\/code><\/pre>\n\n\n\n
\/usr\/lib\/nagios\/plugins\/<\/code>. The commands above would look like;<\/p>\n\n\n\n
command[check_users]=\/usr\/lib\/nagios\/plugins\/check_users -w 5 -c 10\ncommand[check_load]=\/usr\/lib\/nagios\/plugins\/check_load -r -w 15,10,5 -c 30,25,20\ncommand[check_disk]=\/usr\/lib\/nagios\/plugins\/check_disk -w 20% -c 10% -p \/dev\/sda1\ncommand[check_zombie_procs]=\/usr\/lib\/nagios\/plugins\/check_procs -w 5 -c 10 -s Z\ncommand[check_total_procs]=\/usr\/lib\/nagios\/plugins\/check_procs -w 150 -c 200\n<\/code><\/pre>\n\n\n\n
log_facility=daemon\ndebug=0\npid_file=\/run\/nagios\/nrpe.pid\nserver_port=5666\nnrpe_user=nagios\nnrpe_group=nagios\nallowed_hosts=127.0.0.1,::1\ndont_blame_nrpe=0\nallow_bash_command_substitution=0\ncommand_timeout=60\nconnection_timeout=300\ndisable_syslog=0\ncommand[check_users]=\/usr\/lib\/nagios\/plugins\/check_users -w 5 -c 10\ncommand[check_load]=\/usr\/lib\/nagios\/plugins\/check_load -r -w 15,10,5 -c 30,25,20\ncommand[check_disk]=\/usr\/lib\/nagios\/plugins\/check_disk -w 20% -c 10% -p \/dev\/sda1\ncommand[check_zombie_procs]=\/usr\/lib\/nagios\/plugins\/check_procs -w 5 -c 10 -s Z\ncommand[check_total_procs]=\/usr\/lib\/nagios\/plugins\/check_procs -w 150 -c 200\ninclude=\/etc\/nagios\/nrpe_local.cfg\ninclude_dir=\/etc\/nagios\/nrpe.d\/\n<\/code><\/pre>\n\n\n\n
Running NRPE on Ubuntu 22.04<\/h4>\n\n\n\n
systemctl enable --now nagios-nrpe-server<\/code><\/pre>\n\n\n\n
systemctl status nagios-nrpe-server<\/code><\/pre>\n\n\n\n
\n\u25cf nagios-nrpe-server.service - Nagios Remote Plugin Executor\n Loaded: loaded (\/lib\/systemd\/system\/nagios-nrpe-server.service; enabled; vendor preset: enabled)\n Active: active (running) since Wed 2022-05-04 19:16:00 UTC; 1s ago\n Docs: http:\/\/www.nagios.org\/documentation\n Main PID: 22049 (nrpe)\n Tasks: 1 (limit: 2241)\n Memory: 1.5M\n CPU: 10ms\n CGroup: \/system.slice\/nagios-nrpe-server.service\n \u2514\u250022049 \/usr\/sbin\/nrpe -c \/etc\/nagios\/nrpe.cfg -f\n\nMay 04 19:16:00 jellyfish systemd[1]: Stopping Nagios Remote Plugin Executor...\nMay 04 19:16:00 jellyfish nrpe[20779]: Daemon shutdown\nMay 04 19:16:00 jellyfish systemd[1]: nagios-nrpe-server.service: Deactivated successfully.\nMay 04 19:16:00 jellyfish nrpe[22049]: Starting up daemon\nMay 04 19:16:00 jellyfish systemd[1]: Stopped Nagios Remote Plugin Executor.\nMay 04 19:16:00 jellyfish nrpe[22049]: Server listening on 0.0.0.0 port 5666.\nMay 04 19:16:00 jellyfish systemd[1]: Started Nagios Remote Plugin Executor.\nMay 04 19:16:00 jellyfish nrpe[22049]: Server listening on :: port 5666.\nMay 04 19:16:00 jellyfish nrpe[22049]: Listening for connections on port 5666\nMay 04 19:16:00 jellyfish nrpe[22049]: Allowing connections from: 127.0.0.1,192.168.56.124\n<\/code><\/pre>\n\n\n\n
nrpe.service<\/code><\/strong>.<\/p>\n\n\n\n
systemctl start nrpe<\/code><\/pre>\n\n\n\n
systemctl status nrpe<\/code><\/pre>\n\n\n\n
\n\u25cf nrpe.service - Nagios Remote Plugin Executor\n Loaded: loaded (\/lib\/systemd\/system\/nrpe.service; enabled; vendor preset: enabled)\n Active: active (running) since Wed 2022-05-04 19:18:41 UTC; 2s ago\n Docs: http:\/\/www.nagios.org\/documentation\n Main PID: 46858 (nrpe)\n Tasks: 1 (limit: 2281)\n Memory: 668.0K\n CGroup: \/system.slice\/nrpe.service\n \u2514\u250046858 \/usr\/local\/nagios\/bin\/nrpe -c \/usr\/local\/nagios\/etc\/nrpe.cfg -f\n\nMay 04 19:18:41 ubuntu20 systemd[1]: Started Nagios Remote Plugin Executor.\nMay 04 19:18:41 ubuntu20 nrpe[46858]: Starting up daemon\nMay 04 19:18:41 ubuntu20 nrpe[46858]: Server listening on 0.0.0.0 port 5666.\nMay 04 19:18:41 ubuntu20 nrpe[46858]: Server listening on :: port 5666.\nMay 04 19:18:41 ubuntu20 nrpe[46858]: Listening for connections on port 5666\nMay 04 19:18:41 ubuntu20 nrpe[46858]: Allowing connections from: 127.0.0.1,192.168.56.124\n<\/code><\/pre>\n\n\n\n
Open NRPE Port on Firewall<\/h4>\n\n\n\n
ufw allow from <NAGIOS_IP> to any port 5666 proto tcp comment \"Allow Connection from Nagios Server for Metrics check\"<\/code><\/pre>\n\n\n\n
apt install iptables-persistent -y<\/code><\/pre>\n\n\n\n
iptables -I INPUT -p tcp -s <NAGIOS_IP> --dport 5666 -j ACCEPT<\/code><\/pre>\n\n\n\n
iptables-save > \/etc\/iptables\/rules.v4<\/code><\/pre>\n\n\n\n
ss -altnp | grep 5666<\/code><\/pre>\n\n\n\n
LISTEN 0 5 0.0.0.0:5666 0.0.0.0:* users:((\"nrpe\",pid=10345,fd=4)) \nLISTEN 0 5 [::]:5666 [::]:* users:((\"nrpe\",pid=10345,fd=5))<\/code><\/pre>\n\n\n\n
<\/figure><\/a><\/div>\n\n\n\n