{"id":12556,"date":"2022-05-04T20:52:29","date_gmt":"2022-05-04T17:52:29","guid":{"rendered":"https:\/\/kifarunix.com\/?p=12556"},"modified":"2024-05-08T22:30:47","modified_gmt":"2024-05-08T19:30:47","slug":"install-and-setup-nagios-on-ubuntu-22-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-setup-nagios-on-ubuntu-22-04\/","title":{"rendered":"Install and Setup Nagios on Ubuntu 22.04"},"content":{"rendered":"\n<p>In this guide, we will provide a step-by-step tutorial on how to install and setup Nagios on Ubuntu 22.04. <a href=\"https:\/\/www.nagios.org\/about\/\" target=\"_blank\" rel=\"noreferrer noopener\">Nagios<\/a>, now known as, Nagios Core, is an enterprise-class Open Source IT monitoring, network monitoring, server and applications monitoring solution.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#install-and-setup-nagios-on-ubuntu-22-04\">Install and Setup Nagios on Ubuntu 22.04<\/a><ul><li><a href=\"#install-nagios-from-apt-on-ubuntu\">Install Nagios from APT on Ubuntu<\/a><\/li><li><a href=\"#install-nagios-from-source-on-ubuntu-22-04\">Install Nagios from Source on Ubuntu 22.04<\/a><\/li><li><a href=\"#run-system-update\">Run System Update<\/a><\/li><li><a href=\"#install-required-nagios-build-tools-and-development-libraries\">Install Required Nagios build tools and Development Libraries<\/a><\/li><li><a href=\"#download-nagios-source-code\">Download Nagios Source Code<\/a><\/li><li><a href=\"#extract-nagios-source-code\">Extract Nagios Source Code<\/a><\/li><li><a href=\"#compile-and-install-nagios-on-ubuntu-22-04\">Compile and Install Nagios on Ubuntu 22.04<\/a><\/li><li><a href=\"#running-nagios-service\">Running Nagios Service<\/a><\/li><li><a href=\"#accessing-nagios-web-interface\">Accessing Nagios Web Interface<\/a><\/li><li><a href=\"#install-nagios-plugins-on-ubuntu-22-04\">Install Nagios Plugins on Ubuntu 22.04<\/a><\/li><li><a href=\"#related-tutorials\">Related Tutorials<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"install-and-setup-nagios-on-ubuntu-22-04\">Install and Setup Nagios on Ubuntu 22.04<\/h2>\n\n\n\n<p>There are two ways in which you can install Nagios on Ubuntu 22.04.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"#install-nagios-from-apt\">Install Nagios from default Ubuntu 22.04 repositories<\/a><\/li>\n\n\n\n<li><a href=\"#build-nagios-from-source\">Build Nagios from Source Code on Ubuntu 22.04 (for latest and stable release versions)<\/a><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-nagios-from-apt-on-ubuntu\">Install Nagios from APT on Ubuntu<\/h3>\n\n\n\n<p>As much it is easier to install Nagios from Ubuntu repos, sometimes the repos do not provide the latest stable release versions of Nagios. Take for example, Nagios 4.x is the current versions of Nagios with Nagios 4.4.7 release being the latest stable version as per the <a href=\"https:\/\/www.nagios.org\/projects\/nagios-core\/history\/4x\/\" target=\"_blank\" rel=\"noreferrer noopener\">releases page<\/a>.<\/p>\n\n\n\n<p>If you check the available versions on Ubuntu 22.04 repos, Nagios 4.4.6 is the latest stable release.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt-cache policy nagios4<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>nagios4:\n  Installed: (none)\n  Candidate: 4.4.6-4\n  Version table:\n     4.4.6-4 500\n        500 http:\/\/us.archive.ubuntu.com\/ubuntu jammy\/universe amd64 Packages\n<\/code><\/pre>\n\n\n\n<p>You can check similar installation here;<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-nagios-on-debian-11\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Nagios on Debian 11<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-nagios-from-source-on-ubuntu-22-04\">Install Nagios from Source on Ubuntu 22.04<\/h3>\n\n\n\n<p>This is the only way to ensure that you install the current and latest stable release version of Nagios.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"run-system-update\">Run System Update<\/h3>\n\n\n\n<p>Ensure that your system packages are up-to-date.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt update<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-required-nagios-build-tools-and-development-libraries\">Install Required Nagios build tools and Development Libraries<\/h3>\n\n\n\n<p>Run the command below to install the required built tools and development libraries.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt install autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php libgd-dev libssl-dev -y<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"download-nagios-source-code\">Download Nagios Source Code<\/h3>\n\n\n\n<p>Navigate to <a rel=\"noreferrer noopener\" href=\"https:\/\/www.nagios.org\/downloads\/nagios-core\/thanks\/?skip=1&amp;product_download=nagioscore-source\" target=\"_blank\">Nagios download&#8217;s page<\/a> and grab the latest and stable release Nagios source tarball. Simply grab the link and optionally pull it using wget command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>wget https:\/\/assets.nagios.com\/downloads\/nagioscore\/releases\/nagios-4.4.7.tar.gz<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"extract-nagios-source-code\">Extract Nagios Source Code<\/h3>\n\n\n\n<p>Once the download completes, extract the source archive;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>tar xzf nagios-4.4.7.tar.gz<\/code><\/pre>\n\n\n\n<p>You should now have Nagios source directory in the current working directory;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ls<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code><strong>nagios-4.4.7<\/strong> nagios-4.4.7.tar.gz<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"compile-and-install-nagios-on-ubuntu-22-04\">Compile and Install Nagios on Ubuntu 22.04<\/h3>\n\n\n\n<p>Navigate to Nagios source directory and run the configure script to adapt Nagios to your system while checking for any missing required dependency before the installation;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>cd <strong>nagios-4.4.7<\/strong><\/code><\/pre>\n\n\n\n<p>Configure Nagios to use Apache as the web server. Use the <code>--with-httpd-conf<\/code> to specify where to install Nagios Apache site configs. Be sure to use <code>.\/configure --help<\/code> for more options.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>.\/configure --with-httpd-conf=\/etc\/apache2\/sites-enabled<\/code><\/pre>\n\n\n\n<p>Pay attention to the output of this command just in case there is any error that needs to be fixed before you can proceed.<\/p>\n\n\n\n<p>If all is well, you should an output similar to;<\/p>\n\n\n\n<pre class=\"scroll-box\"><code>*** Configuration summary for nagios 4.4.7 2022-04-14 ***:\n\n General Options:\n -------------------------\n        Nagios executable:  nagios\n        Nagios user\/group:  nagios,nagios\n       Command user\/group:  nagios,nagios\n             Event Broker:  yes\n        Install ${prefix}:  \/usr\/local\/nagios\n    Install ${includedir}:  \/usr\/local\/nagios\/include\/nagios\n                Lock file:  \/run\/nagios.lock\n   Check result directory:  \/usr\/local\/nagios\/var\/spool\/checkresults\n           Init directory:  \/lib\/systemd\/system\n  Apache conf.d directory:  \/etc\/apache2\/sites-enabled\n             Mail program:  \/bin\/mail\n                  Host OS:  linux-gnu\n          IOBroker Method:  epoll\n\n Web Interface Options:\n ------------------------\n                 HTML URL:  http:\/\/localhost\/nagios\/\n                  CGI URL:  http:\/\/localhost\/nagios\/cgi-bin\/\n Traceroute (used by WAP):  \n\n\nReview the options above for accuracy.  If they look okay,\ntype 'make all' to compile the main program and CGIs.\n<\/code><\/pre>\n\n\n\n<p>Next, compile the main Nagios program and CGIs.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make all<\/code><\/pre>\n\n\n\n<p>Create Nagios user and group. Add the user to the Apache web server group.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make install-groups-users<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>usermod -aG nagios www-data<\/code><\/pre>\n\n\n\n<p>Install Nagios main program, CGIs, and HTML files.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make install<\/code><\/pre>\n\n\n\n<p>Install Nagios startup scripts;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make install-init<\/code><\/pre>\n\n\n\n<p>Initialize the init scripts;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make install-daemoninit<\/code><\/pre>\n\n\n\n<p>Install and configure permissions on the directory for holding the Nagios external command file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make install-commandmode<\/code><\/pre>\n\n\n\n<p>Install Nagios sample configuration files in&nbsp;<code>\/usr\/local\/nagios\/etc<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>make install-config<\/code><\/pre>\n\n\n\n<p>Install Apache configuration file for the Nagios web interface<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make install-webconf<\/code><\/pre>\n\n\n\n<p>Enable Apache rewrite and CGI modules;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>a2enmod rewrite cgi<\/code><\/pre>\n\n\n\n<p>Configure Nagios Web Interface basic authentication.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>htpasswd -c \/usr\/local\/nagios\/etc\/htpasswd.users nagiosadmin<\/code><\/pre>\n\n\n\n<p>Where <strong><code>nagiosadmin<\/code><\/strong> is the default admin user for accessing Nagios web interface (as specified in the cgi.cfg). You can create or use any other user name and be sure to specify it in the <code>\/usr\/local\/nagios\/etc\/cgi.cfg<\/code> configuration file.<\/p>\n\n\n\n<p>If you need to add more users, <strong>omit <\/strong>option<strong> -c <\/strong>in the command above.<\/p>\n\n\n\n<p>We are almost done setting up Nagios on Ubuntu 22.04.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"running-nagios-service\">Running Nagios Service<\/h3>\n\n\n\n<p>The <code><strong>make install-init<\/strong><\/code> command, install systemd service units for Nagios Core. You can start and enable Nagios to run on system boot by running the command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now nagios<\/code><\/pre>\n\n\n\n<p>If it was already running, then restart it;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart nagios<\/code><\/pre>\n\n\n\n<p>To check the status;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl status nagios<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\u25cf nagios.service - Nagios Core 4.4.7\n     Loaded: loaded (\/lib\/systemd\/system\/nagios.service; enabled; vendor preset: enabled)\n     Active: active (running) since Wed 2022-05-04 17:18:52 UTC; 1s ago\n       Docs: https:\/\/www.nagios.org\/documentation\n    Process: 15854 ExecStartPre=\/usr\/local\/nagios\/bin\/nagios -v \/usr\/local\/nagios\/etc\/nagios.cfg (code=exited, status=0\/SUCCESS)\n    Process: 15855 ExecStart=\/usr\/local\/nagios\/bin\/nagios -d \/usr\/local\/nagios\/etc\/nagios.cfg (code=exited, status=0\/SUCCESS)\n   Main PID: 15856 (nagios)\n      Tasks: 6 (limit: 2241)\n     Memory: 5.2M\n        CPU: 355ms\n     CGroup: \/system.slice\/nagios.service\n             \u251c\u250015856 \/usr\/local\/nagios\/bin\/nagios -d \/usr\/local\/nagios\/etc\/nagios.cfg\n             \u251c\u250015857 \/usr\/local\/nagios\/bin\/nagios --worker \/usr\/local\/nagios\/var\/rw\/nagios.qh\n             \u251c\u250015858 \/usr\/local\/nagios\/bin\/nagios --worker \/usr\/local\/nagios\/var\/rw\/nagios.qh\n             \u251c\u250015859 \/usr\/local\/nagios\/bin\/nagios --worker \/usr\/local\/nagios\/var\/rw\/nagios.qh\n             \u251c\u250015860 \/usr\/local\/nagios\/bin\/nagios --worker \/usr\/local\/nagios\/var\/rw\/nagios.qh\n             \u2514\u250015861 \/usr\/local\/nagios\/bin\/nagios -d \/usr\/local\/nagios\/etc\/nagios.cfg\n\nMay 04 17:18:52 jellyfish nagios[15856]: qh: core query handler registered\nMay 04 17:18:52 jellyfish nagios[15856]: qh: echo service query handler registered\nMay 04 17:18:52 jellyfish nagios[15856]: qh: help for the query handler registered\nMay 04 17:18:52 jellyfish nagios[15856]: wproc: Successfully registered manager as @wproc with query handler\nMay 04 17:18:52 jellyfish nagios[15856]: wproc: Registry request: name=Core Worker 15858;pid=15858\nMay 04 17:18:52 jellyfish nagios[15856]: wproc: Registry request: name=Core Worker 15857;pid=15857\nMay 04 17:18:52 jellyfish nagios[15856]: wproc: Registry request: name=Core Worker 15860;pid=15860\nMay 04 17:18:52 jellyfish nagios[15856]: wproc: Registry request: name=Core Worker 15859;pid=15859\nMay 04 17:18:53 jellyfish nagios[15856]: Successfully launched command file worker with pid 15861\nMay 04 17:18:53 jellyfish nagios[15856]: HOST ALERT: localhost;DOWN;SOFT;1;(No output on stdout)\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"accessing-nagios-web-interface\">Accessing Nagios Web Interface<\/h3>\n\n\n\n<p>Restart and enable Apache to run on system reboot;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl restart apache2<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>systemctl enable --now apache2<\/code><\/pre>\n\n\n\n<p>If firewall is running, allow Apache through.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ufw allow Apache<\/code><\/pre>\n\n\n\n<p>You can access Nagios from web interface via, <strong><code>http:\/\/Nagios-Server-IP-OR-Hostname\/nagios<\/code><\/strong>.<\/p>\n\n\n\n<p>Enter your basic authentication credentials;<\/p>\n\n\n\n<div><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-basic-auth.png\" class=\"td-modal-image\"><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1418\" height=\"452\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-basic-auth.png\" alt=\"Install and Setup Nagios on Ubuntu 22.04\" class=\"wp-image-12563\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-basic-auth.png?v=1651686023 1418w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-basic-auth-768x245.png?v=1651686023 768w\" sizes=\"(max-width: 1418px) 100vw, 1418px\" \/><\/figure><\/a><\/div>\n\n\n\n<p>Nagios default web interface<\/p>\n\n\n\n<div><a href=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-core-ui-ubuntu-1.png\" class=\"td-modal-image\"><figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1645\" height=\"904\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-core-ui-ubuntu-1.png\" alt=\"Install and Setup Nagios on Ubuntu 22.04\" class=\"wp-image-12564\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-core-ui-ubuntu-1.png?v=1651686116 1645w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-core-ui-ubuntu-1-768x422.png?v=1651686116 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-core-ui-ubuntu-1-1536x844.png?v=1651686116 1536w\" sizes=\"(max-width: 1645px) 100vw, 1645px\" \/><\/figure><\/a><\/div>\n\n\n\n<p>Nagios server is now running on Ubuntu 22.04<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"install-nagios-plugins-on-ubuntu-22-04\">Install Nagios Plugins on Ubuntu 22.04<\/h3>\n\n\n\n<p id=\"installnrpeagent\"><a href=\"#installnrpeagent\">In order for Nagios to start monitoring hosts, you need to install Nagios plugins and NRPE agents.<\/a> You can simply install plugins as follows;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>apt install monitoring-plugins<\/code><\/pre>\n\n\n\n<p>This will install a number of plugins under the directory, <code>\/usr\/lib\/nagios\/plugins\/<\/code>.<\/p>\n\n\n\n<p>By default, Nagios installed from the source expects the plugins to reside under, <code>\/usr\/local\/nagios\/libexec<\/code> directory.<\/p>\n\n\n\n<p>So for Nagios use the current plugins directory, simply edit the Nagios resource config file and update as follows;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>vim \/usr\/local\/nagios\/etc\/resource.cfg<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>...\n# Sets $USER1$ to be the path to the plugins\n<strong>#$USER1$=\/usr\/local\/nagios\/libexec<\/strong>\n$USER1$=\/usr\/lib\/nagios\/plugins\n...<\/code><\/pre>\n\n\n\n<p>You can as well create a symbolic link instead of making the above changes as follows;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>ln -s \/usr\/lib\/nagios\/plugins\/* \/usr\/local\/nagios\/libexec<\/code><\/pre>\n\n\n\n<p>By this, you should have the plugins under the <code>\/usr\/local\/nagios\/libexec <\/code>directory.<\/p>\n\n\n\n<p>Follow the links below to learn how to add hosts for monitoring as well as installing plugins and NRPE agents on other systems.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"related-tutorials\">Related Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/add-hosts-to-nagios-server-for-monitoring\/\" target=\"_blank\" rel=\"noreferrer noopener\">Add Hosts to Nagios Server For Monitoring<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/install-nagios-nrpe-agents-on-debian-11-debian-10\/\" target=\"_blank\" rel=\"noreferrer noopener\">Install Nagios NRPE Agents on Debian 11\/Debian 10<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we will provide a step-by-step tutorial on how to install and setup Nagios on Ubuntu 22.04. Nagios, now known as, Nagios Core,<\/p>\n","protected":false},"author":2,"featured_media":12562,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[72,73],"tags":[5028,5025,76,5026,4412,5027],"class_list":["post-12556","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-monitoring","category-nagios","tag-install-nagios-core-ubuntu-22-04","tag-install-nagios-on-ubuntu-22-04","tag-nagios-core","tag-nagios-ubuntu-22-04","tag-ubuntu-22-04","tag-ubuntu-22-04-nagios","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50","resize-featured-image"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12556"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=12556"}],"version-history":[{"count":8,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12556\/revisions"}],"predecessor-version":[{"id":22476,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/12556\/revisions\/22476"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media\/12562"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=12556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=12556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=12556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}