{"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
In this guide, we will provide a step-by-step tutorial on how to install and setup Nagios Core on Ubuntu 20.04. 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 There are two ways in which you can install Nagios on Ubuntu 20.04.<\/p>\n\n\n\n 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 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 releases page<\/a>.<\/p>\n\n\n\n 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 Hence, why we choose installation from the source code.<\/p>\n\n\n\n Ensure that your system packages are up-to-date.<\/p>\n\n\n\n Run the command below to install the required built tools and development libraries.<\/p>\n\n\n\n Navigate to Nagios Core download’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 Once the download completes, extract the source archive;<\/p>\n\n\n\n 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 Configure Nagios Core to use Apache as the web server. Use the 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 If all is well, you should an output similar to;<\/p>\n\n\n\n Next, compile the main Nagios program and CGIs.<\/p>\n\n\n\n Create Nagios Core user and group. Add the user to the Apache web server group.<\/p>\n\n\n\n Install Nagios Core main program, CGIs, and HTML files.<\/p>\n\n\n\n Install Nagios Core startup scripts;<\/p>\n\n\n\n Initialize the init scripts;<\/p>\n\n\n\n Install and configure permissions on the directory for holding the Nagios Core external command file.<\/p>\n\n\n\n Install Nagios Core sample configuration files in Install Apache configuration file for the Nagios web interface<\/p>\n\n\n\n Enable Apache rewrite and CGI modules;<\/p>\n\n\n\n Configure Nagios Core Web Interface basic authentication.<\/p>\n\n\n\n Where If you need to add more users, omit option -c <\/strong>in the command above.<\/p>\n\n\n\n We are almost done setting up Nagios Core on Ubuntu 20.04.<\/p>\n\n\n\n The To check the status;<\/p>\n\n\n\n Restart and enable Apache to run on system reboot;<\/p>\n\n\n\n If firewall is running, allow Apache through.<\/p>\n\n\n\n You can access Nagios Core from web interface via, Enter your basic authentication credentials;<\/p>\n\n\n\n Nagios Core default web interface<\/p>\n\n\n\n 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 This will install a number of plugins under the directory, So for Nagios use the current plugins directory, simply edit the Nagios resource config file and update as follows;<\/p>\n\n\n\n You can as well create a symbolic link instead of making the above changes as follows;<\/p>\n\n\n\n By this, you should have the plugins under the 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 Monitor Linux Hosts using Nagios check_by_ssh Plugin<\/a><\/p>\n\n\n\n Add Hosts to Nagios Server For Monitoring<\/a><\/p>\n\n\n\n How to Install Nagios Plugins From Source RHEL\/CentOS\/Oracle Linux<\/a><\/p>\n\n\n\nInstalling Nagios Core on Ubuntu 20.04<\/h2>\n\n\n\n
\n
apt show nagios4<\/code><\/pre>\n\n\n\n
\nPackage: nagios4\nVersion: 4.3.4-3<\/strong>\nPriority: optional\nSection: universe\/net\nOrigin: Ubuntu\nMaintainer: Ubuntu Developers ubuntu-devel-discuss@lists.ubuntu.com<\/a>\nOriginal-Maintainer: Russell Stuart russell-debian@stuart.id.au<\/a>\nBugs: https:\/\/bugs.launchpad.net\/ubuntu\/+filebug\n<\/code><\/pre>\n\n\n\n
Run System Update<\/h3>\n\n\n\n
apt update<\/code><\/pre>\n\n\n\n
Install Required Nagios build tools and Development Libraries<\/h3>\n\n\n\n
apt install autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php libgd-dev libssl-dev -y<\/code><\/pre>\n\n\n\n
Download Nagios Core Source Code<\/h3>\n\n\n\n
wget https:\/\/assets.nagios.com\/downloads\/nagioscore\/releases\/nagios-4.4.7.tar.gz<\/code><\/pre>\n\n\n\n
Extract Nagios Core Source Code<\/h3>\n\n\n\n
tar xzf nagios-4.4.7.tar.gz<\/code><\/pre>\n\n\n\n
Compile and install Nagios Core<\/h3>\n\n\n\n
cd nagios-4.4.7<\/code><\/pre>\n\n\n\n
--with-httpd-conf<\/code> to specify where to install Nagios Core Apache site configs. Be sure to use
.\/configure --help<\/code> for more options.<\/p>\n\n\n\n
.\/configure --with-httpd-conf=\/etc\/apache2\/sites-enabled<\/code><\/pre>\n\n\n\n
\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
make all<\/code><\/pre>\n\n\n\n
make install-groups-users<\/code><\/pre>\n\n\n\n
usermod -aG nagios www-data<\/code><\/pre>\n\n\n\n
make install<\/code><\/pre>\n\n\n\n
make install-init<\/code><\/pre>\n\n\n\n
make install-daemoninit<\/code><\/pre>\n\n\n\n
make install-commandmode<\/code><\/pre>\n\n\n\n
\/usr\/local\/nagios\/etc<\/code>.<\/p>\n\n\n\n
make install-config<\/code><\/pre>\n\n\n\n
make install-webconf<\/code><\/pre>\n\n\n\n
a2enmod rewrite cgi<\/code><\/pre>\n\n\n\n
htpasswd -c \/usr\/local\/nagios\/etc\/htpasswd.users nagiosadmin<\/code><\/pre>\n\n\n\n
nagiosadmin<\/code><\/strong> – 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
\/usr\/local\/nagios\/etc\/nagios.cfg<\/code> configuration file.<\/p>\n\n\n\n
Running Nagios Core Service<\/h3>\n\n\n\n
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
systemctl enable --now nagios<\/code><\/pre>\n\n\n\n
systemctl status nagios<\/code><\/pre>\n\n\n\n
\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
Accessing Nagios Core Web Interface<\/h3>\n\n\n\n
systemctl restart apache2<\/code><\/pre>\n\n\n\n
systemctl enable --now apache2<\/code><\/pre>\n\n\n\n
ufw allow Apache<\/code><\/pre>\n\n\n\n
http:\/\/Nagios-Server-IP-OR-Hostname\/nagios<\/code><\/strong>.<\/p>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
Install Nagios Plugins on Ubuntu 20.04<\/h3>\n\n\n\n
apt install nagios-plugins<\/code><\/pre>\n\n\n\n
\/usr\/lib\/nagios\/plugins\/<\/code>. By default, Nagios installed from the source expects the plugins to reside under,
\/usr\/local\/nagios\/libexec<\/code> directory.<\/p>\n\n\n\n
vim \/usr\/local\/nagios\/etc\/resource.cfg<\/code><\/pre>\n\n\n\n
...\n#$USER1$=\/usr\/local\/nagios\/libexec<\/strong>\n$USER1$=\/usr\/lib\/nagios\/plugins\n...<\/code><\/pre>\n\n\n\n
ln -s \/usr\/lib\/nagios\/plugins\/* \/usr\/local\/nagios\/libexec<\/code><\/pre>\n\n\n\n
\/usr\/local\/nagios\/libexec <\/code>directory.<\/p>\n\n\n\n
Related Tutorials<\/h3>\n\n\n\n