Thursday, June 27, 2024
HomeOperating SystemsDebianInstall and Configure Nagios 4 on Debian 11 / Debian 10

Install and Configure Nagios 4 on Debian 11 / Debian 10

Preamble

In this guide we will install Nagios 4 on Debian 11 / Debian 10 Linux. Nagios is a powerful monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes. It monitors your entire IT infrastructure to ensure systems, applications, services, and business processes are functioning properly. In the event of a failure, Nagios can alert the technical staff of the problem, allowing them to begin remediation processes before outages affect business processes, end-users, or customers.

Nagios® Core™ is an Open Source system and network monitoring application. It watches hosts and services that you specify, alerting you when things go bad and when they get better.

If you would wish to install Nagios Core on Debian 11 / Debian 10, the following steps will help you rev it up in a few minutes.

Step 1: Update your System

Run the command below to update your server so that we begin from latest software installed

sudo apt update && sudo apt -y full-upgrade
[ -f /var/run/reboot-required ] && sudo reboot -f

If it is a totally new server, follow this guide to update your apt sources file (/etc/apt/sources.list)

Step 2: Install the required packages

The following step will install the pre-requisite packages that Nagios Core needs to run. Please proceed to install them.

sudo apt install vim wget curl build-essential unzip openssl libssl-dev apache2 php libapache2-mod-php php-gd libgd-dev

Step 3: Fetch and extract Nagios Files

We now have to go to the Nagios downloads page to grab the latest release.

cd ~
NAGIOS_VER=$(curl -s https://api.github.com/repos/NagiosEnterprises/nagioscore/releases/latest|grep tag_name | cut -d '"' -f 4)
wget https://github.com/NagiosEnterprises/nagioscore/releases/download/$NAGIOS_VER/$NAGIOS_VER.tar.gz

Extract the tarball

tar xvzf $NAGIOS_VER.tar.gz

Step 4: Compile the extracted files

After Nagios core files have been successfully extracted, navigate into the new directory holding the files and begin the compilation process.

cd $NAGIOS_VER
./configure --with-httpd-conf=/etc/apache2/sites-enabled

You should see the following when the above command ends.

....
Creating sample config files in sample-config/ ...


*** Configuration summary for nagios 4.4.7 2022-04-14 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagios
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  /run/nagios.lock
   Check result directory:  /usr/local/nagios/var/spool/checkresults
           Init directory:  /lib/systemd/system
  Apache conf.d directory:  /etc/apache2/sites-enabled
             Mail program:  /bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

Step 5: Create User And Group

This step ensures that “nagios” user and group are created. The www-data user is also added to the “nagios” group.

sudo make install-groups-users
sudo usermod -a -G nagios www-data

Now let us compile the main Nagios program and associated packages

sudo make all

Install the main program, CGIs, and HTML files

sudo make install

Step 6: Install Daemon

This installs Nagios daemon files and also configures them to start when the system boots.

sudo make install-daemoninit

Step 7: Add Command Mode

This installs and configures the external command file.

sudo make install-commandmode

Step 8: Install Configuration Files

In this step, we install SAMPLE configuration files required as Nagios needs some configuration files to allow it to start.

sudo make install-config

Step 9: Apache Webserver Configuration

We have to configure our Apache to serve Nagios web pages. Nagios developers made it easier to set up Apache. You simply run one command to set up configuration files and then enable specific apache modules. Proceed as below.

This will install config files

sudo make install-webconf

This enables Apache rewrite and CGI modules

sudo a2enmod rewrite cgi

Step 10: Configure Nagios Apache Authentication

In order to create Nagios Web authentication, you need to create a web user for authentication. The “htpasswd” command rises to the occasion for this task. Please note that Nagios uses “nagiosadmin” user by default. Run the command below and input your favorable password.

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

After that, give appropriate permissions to the (/usr/local/nagios/etc/htpasswd.users) file.

sudo chown www-data:www-data /usr/local/nagios/etc/htpasswd.users
sudo chmod 640 /usr/local/nagios/etc/htpasswd.users

Step 11: Install essential Nagios Plugins

Before we finish up setting up our Nagios core monitoring, we need Nagios Plugins that will help us accomplish a lot of stuff including monitoring the localhost. We will thus fetch the latest stable release of plugins, extract and install it in our system. You can find the plugins at Nagios Plugins. Follow along

Fetch and extract the plugins

cd ~
VER=$(curl -s https://api.github.com/repos/nagios-plugins/nagios-plugins/releases/latest|grep tag_name | cut -d '"' -f 4|sed 's/release-//')
wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-$VER/nagios-plugins-$VER.tar.gz
tar xvf nagios-plugins-$VER.tar.gz

Navigate into the new plugins folder then compile and install.

cd nagios-plugins-$VER
./configure --with-nagios-user=nagios --with-nagios-group=nagios

sudo make
sudo make install

Step 12: Allow ports on the firewall and start Nagios

In case you have a firewall running, please allow the necessary ports.

sudo ufw allow 80
sudo ufw reload

Start Nagios and Apache services

sudo systemctl restart apache2
sudo systemctl start nagios.service

Step 13: Log into Nagios Web Interface

After everything has been done well without any errors, let us open up our browser and get to see if the Nagios web interface is accessible. Open your browser and key in the IP of your server or its domain name if you had configured one and the root directory of Nagios.

http://<IP Address/FQDN>/nagios

You will be prompted for a username and password. The username as you may remember is the one we set in Step 10, that is “nagiosadmin

NagiosLogin 1

Provide credentials to access Nagios dashboard.

install nagios 4 ubuntu 02

If you click on the “Hosts” link, you should see that the localhost is up and hence being monitored thanks to the plugins we installed earlier.

NagiosLogin localhost 3

Conclusion

We hope this session was as informative and helpful as possible and we thank you for visiting. You make it all worthwhile. In case you are interested in other monitoring tools, the guides below will be great for you as well.

Nicole Veronica Rubhabha
Nicole Veronica Rubhabha
A highly competent and organized individual DotNet developer with a track record of architecting and developing web client-server applications. Recognized as a personable, dedicated performer who demonstrates innovation, communication, and teamwork to ensure quality and timely project completion. Expertise in C#, ASP.Net, MVC, LINQ, EF 6, Web Services, SQL Server, MySql, Web development,
RELATED ARTICLES

Most Popular

Recent Comments