{"id":5707,"date":"2020-05-02T17:22:48","date_gmt":"2020-05-02T14:22:48","guid":{"rendered":"https:\/\/kifarunix.com\/?p=5707"},"modified":"2024-03-14T20:46:33","modified_gmt":"2024-03-14T17:46:33","slug":"install-and-setup-nagios-core-on-ubuntu-20-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/install-and-setup-nagios-core-on-ubuntu-20-04\/","title":{"rendered":"Install and Setup Nagios Core on Ubuntu 20.04"},"content":{"rendered":"\n<p>In this guide, we will provide a step-by-step tutorial on how to install and setup Nagios Core on Ubuntu 20.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<h2 class=\"wp-block-heading\">Installing Nagios Core on Ubuntu 20.04<\/h2>\n\n\n\n<p>There are two ways in which you can install Nagios on Ubuntu 20.04.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Install Nagios from default Ubuntu 20.04 repositories<\/li>\n\n\n\n<li>Build Nagios from Source Code on Ubuntu 20.04 (for latest and stable release versions)<\/li>\n<\/ul>\n\n\n\n<p>In this guide, we will cover the installation of Nagios Core on Ubuntu 20.04 from the source code. We choose this method because it is the surest method to installing latest and stable release version of Nagios.<\/p>\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 20.04 repos, Nagios 4.3.4 is the latest stable release.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>apt show nagios4<\/code><\/pre>\n\n\n\n<pre class=\"scroll-box\"><code>\nPackage: nagios4\n<strong>Version: 4.3.4-3<\/strong>\nPriority: optional\nSection: universe\/net\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers <a href=\"mailto:ubuntu-devel-discuss@lists.ubuntu.com\">ubuntu-devel-discuss@lists.ubuntu.com<\/a>\nOriginal-Maintainer: Russell Stuart <a href=\"mailto:russell-debian@stuart.id.au\">russell-debian@stuart.id.au<\/a>\nBugs: https:\/\/bugs.launchpad.net\/ubuntu\/+filebug\n<\/code><\/pre>\n\n\n\n<p>Hence, why we choose installation from the source code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">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\">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\">Download Nagios Core 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 Core 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-code\"><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\">Extract Nagios Core 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-code\"><code>tar xzf nagios-4.4.7.tar.gz<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Compile and install Nagios Core<\/h3>\n\n\n\n<p>Navigate to Nagios core source directory and run the configure script to adapt Nagios Core to your system while checking for any missing required dependency before the installation;<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cd nagios-4.4.7<\/code><\/pre>\n\n\n\n<p>Configure Nagios Core to use Apache as the web server. Use the <code>--with-httpd-conf<\/code> to specify where to install Nagios Core Apache site configs. Be sure to use <code>.\/configure --help<\/code> for more options.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><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>\n*** 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 Core user and group. Add the user to the Apache web server group.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make install-groups-users<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>usermod -aG nagios www-data<\/code><\/pre>\n\n\n\n<p>Install Nagios Core main program, CGIs, and HTML files.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make install<\/code><\/pre>\n\n\n\n<p>Install Nagios Core startup scripts;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make install-init<\/code><\/pre>\n\n\n\n<p>Initialize the init scripts;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make install-daemoninit<\/code><\/pre>\n\n\n\n<p>Install and configure permissions on the directory for holding the Nagios Core external command file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>make install-commandmode<\/code><\/pre>\n\n\n\n<p>Install Nagios Core sample configuration files in&nbsp;<code>\/usr\/local\/nagios\/etc<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><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 Core Web Interface basic authentication.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>htpasswd -c \/usr\/local\/nagios\/etc\/htpasswd.users nagiosadmin<\/code><\/pre>\n\n\n\n<p>Where <strong><code>nagiosadmin<\/code><\/strong> &#8211; this user is the default admin user for accessing Nagios Core web interface (as specified in the nagios.cfg). You can create or use any other user name and be sure to specify it in the <code>\/usr\/local\/nagios\/etc\/nagios.cfg<\/code> configuration file.<\/p>\n\n\n\n<p>If you need to add more users, <strong>omit option -c <\/strong>in the command above.<\/p>\n\n\n\n<p>We are almost done setting up Nagios Core on Ubuntu 20.04.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Running Nagios Core 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 Core 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>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>\n\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:17:27 UTC; 6s ago\n       Docs: https:\/\/www.nagios.org\/documentation\n    Process: 22698 ExecStartPre=\/usr\/local\/nagios\/bin\/nagios -v \/usr\/local\/nagios\/etc\/nagios.cfg (code=exited, status=0\/SUCCESS)\n    Process: 22708 ExecStart=\/usr\/local\/nagios\/bin\/nagios -d \/usr\/local\/nagios\/etc\/nagios.cfg (code=exited, status=0\/SUCCESS)\n   Main PID: 22709 (nagios)\n      Tasks: 6 (limit: 2281)\n     Memory: 3.9M\n     CGroup: \/system.slice\/nagios.service\n             \u251c\u250022709 \/usr\/local\/nagios\/bin\/nagios -d \/usr\/local\/nagios\/etc\/nagios.cfg\n             \u251c\u250022710 \/usr\/local\/nagios\/bin\/nagios --worker \/usr\/local\/nagios\/var\/rw\/nagios.qh\n             \u251c\u250022711 \/usr\/local\/nagios\/bin\/nagios --worker \/usr\/local\/nagios\/var\/rw\/nagios.qh\n             \u251c\u250022712 \/usr\/local\/nagios\/bin\/nagios --worker \/usr\/local\/nagios\/var\/rw\/nagios.qh\n             \u251c\u250022713 \/usr\/local\/nagios\/bin\/nagios --worker \/usr\/local\/nagios\/var\/rw\/nagios.qh\n             \u2514\u250022720 \/usr\/local\/nagios\/bin\/nagios -d \/usr\/local\/nagios\/etc\/nagios.cfg\n\nMay 04 17:17:27 ubuntu20 nagios[22709]: qh: core query handler registered\nMay 04 17:17:27 ubuntu20 nagios[22709]: qh: echo service query handler registered\nMay 04 17:17:27 ubuntu20 nagios[22709]: qh: help for the query handler registered\nMay 04 17:17:27 ubuntu20 nagios[22709]: wproc: Successfully registered manager as @wproc with query handler\nMay 04 17:17:27 ubuntu20 nagios[22709]: wproc: Registry request: name=Core Worker 22712;pid=22712\nMay 04 17:17:27 ubuntu20 nagios[22709]: wproc: Registry request: name=Core Worker 22713;pid=22713\nMay 04 17:17:27 ubuntu20 nagios[22709]: wproc: Registry request: name=Core Worker 22711;pid=22711\nMay 04 17:17:27 ubuntu20 nagios[22709]: wproc: Registry request: name=Core Worker 22710;pid=22710\nMay 04 17:17:28 ubuntu20 nagios[22709]: Successfully launched command file worker with pid 22720\n...\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Accessing Nagios Core 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 Core 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<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1443\" height=\"544\" src=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-htaccess-login.png\" alt=\"\" class=\"wp-image-12558\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-htaccess-login.png?v=1651685181 1443w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-htaccess-login-768x290.png?v=1651685181 768w\" sizes=\"(max-width: 1443px) 100vw, 1443px\" \/><\/figure>\n\n\n\n<p>Nagios Core default web interface<\/p>\n\n\n\n<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.png\" alt=\"\" class=\"wp-image-12559\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-core-ui-ubuntu.png?v=1651685238 1645w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-core-ui-ubuntu-768x422.png?v=1651685238 768w, https:\/\/kifarunix.com\/wp-content\/uploads\/2022\/05\/nagios-core-ui-ubuntu-1536x844.png?v=1651685238 1536w\" sizes=\"(max-width: 1645px) 100vw, 1645px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Install Nagios Plugins on Ubuntu 20.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-preformatted\"><code>apt install nagios-plugins<\/code><\/pre>\n\n\n\n<p>This will install a number of plugins under the directory, <code>\/usr\/lib\/nagios\/plugins\/<\/code>. 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-preformatted\"><code>...\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\">Related Tutorials<\/h3>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/monitor-linux-hosts-using-nagios-check_by_ssh-plugin\/\" target=\"_blank\" rel=\"noreferrer noopener\">Monitor Linux Hosts using Nagios check_by_ssh Plugin<\/a><\/p>\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 rel=\"noreferrer noopener\" href=\"https:\/\/kifarunix.com\/how-to-install-nagios-plugins-from-source-rhel-centos-oracle-linux\/\" target=\"_blank\">How to Install Nagios Plugins From Source RHEL\/CentOS\/Oracle Linux<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/monitor-ssl-tls-certificates-expiry-with-nagios\/\" target=\"_blank\" rel=\"noreferrer noopener\">Monitor SSL\/TLS Certificates Expiry with Nagios<\/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 Core on Ubuntu 20.04. Nagios, now known as, Nagios<\/p>\n","protected":false},"author":1,"featured_media":12562,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,72,73],"tags":[1560,5024,1561,76,145,1161,1562,1200],"class_list":["post-5707","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-howtos","category-monitoring","category-nagios","tag-install-nagios-core-on-ubuntu-20-04","tag-install-nagios-plugins-ubuntu-20-04","tag-install-nagios-server-ubuntu-20-04","tag-nagios-core","tag-nagios-monitoring","tag-nagios-server","tag-nagios-server-ubuntu-20-04","tag-ubuntu-20-04","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\/5707"}],"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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=5707"}],"version-history":[{"count":7,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/5707\/revisions"}],"predecessor-version":[{"id":21404,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/5707\/revisions\/21404"}],"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=5707"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=5707"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=5707"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}