How to Install Nagios on Ubuntu 22.04 | Holhol24

0
Install Nagios on Ubuntu 22.04

Nagios is one of the best open-source monitoring tools for monitoring the services and applications running on Windows and Linux operating systems.

Nagios can monitor services such as HTTP, FTP, SSH, SMTP, etc., and system metrics such as CPU load, memory, disk usage, logged-in users, running processes, etc.

Here, we will see how to install Nagios on Ubuntu 22.04.

Prerequisites

Though the Nagios package is available in the Ubuntu repository, we will compile it from the source. So, install the below packages for compiling Nagios.

sudo apt update

sudo apt install -y build-essential apache2 php openssl perl make php-gd libgd-dev libapache2-mod-php libperl-dev libssl-dev daemon wget apache2-utils unzip

Create a user and group for Nagios. Then add the nagios and apache user (www-data) to the part of the nagcmd group to execute external commands via Nagios web interface.

sudo useradd nagios

sudo groupadd nagcmd

sudo usermod -a -G nagcmd nagios

sudo usermod -a -G nagcmd www-data

Install Nagios Core on Ubuntu 22.04

First, download the latest version of Nagios core from the official website.

wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz

tar -zxvf nagios-4.4.6.tar.gz

cd nagios-4.4.6/

Then, execute the below commands to compile the Nagios from the source code.

sudo ./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/

sudo make all

sudo make install

sudo make install-init

sudo make install-config

sudo make install-commandmode

You can find Nagios’s configuration files under the /usr/local/nagios/etc directory, and the default configuration should work fine.

Next, install the Nagios web interface with the below command.

sudo make install-webconf

The Nagios web interface is password protected by default and you will need to create a user account (nagiosadmin) to access the Nagios web interface. So, use the below command to create a user account for Nagios web interface.

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

Enable the CGI module using the following command.

sudo a2enmod cgi

Finally, restart the Apache webserver.

sudo systemctl restart apache2

Get Nagios Alerts on Ubuntu 22.04

To get Nagios alerts, edit the /usr/local/nagios/etc/objects/contacts.cfg file and change the email address associated with the nagiosadmin.

sudo nano /usr/local/nagios/etc/objects/contacts.cfg

Change the email address field to receive the alerts.

define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user

        email                           [email protected]      ; 

Install Nagios Plugins on Ubuntu 22.04

To monitor a system, you will need to install Nagios plugins. So, download the Nagios plugins from the official website.

wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz

tar -zxvf nagios-plugins-2.3.3.tar.gz

cd nagios-plugins-2.3.3/

Then, compile and install the Nagios plugins.

sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios

sudo make

sudo make install

Start Nagios Monitoring Tool

Now, it’s time to start the Nagios service. Before starting the service, verify the Nagios configuration files.

sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Output:

Nagios Core 4.4.6
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2020-04-28
License: GPL

Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
        Checked 8 services.
        Checked 1 hosts.
        Checked 1 host groups.
        Checked 0 service groups.
        Checked 1 contacts.
        Checked 1 contact groups.
        Checked 24 commands.
        Checked 5 time periods.
        Checked 0 host escalations.
        Checked 0 service escalations.
Checking for circular paths...
        Checked 1 hosts
        Checked 0 service dependencies
        Checked 0 host dependencies
        Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check

Then, start and enable the Nagios service with the below command

sudo systemctl enable --now nagios

Access Nagios Web Interface

Now access the Nagios web interface by going following URL in your web browser.

http://ip-add-re-ss/nagios/

Enter the username (nagiosadmin) and password of the Nagios account you created earlier.

Upon successful login, you will get Nagios’s home page.

Click on Services in the left pane to see services being monitored by Nagios.

System Monitoring With Nagios How to Install Nagios on Ubuntu 22.04 | Holhol24 How to Install Nagios on Ubuntu 22.04 | Holhol24 svg xml  3Csvg 20xmlns 3D 22http 3A 2F 2Fwww
System Monitoring With Nagios

In the above screenshot, you will only see the localhost, i.e., the Nagios server. To monitor remote machines, you will need to use the NRPE plugin.

READ: How To Monitor Remote Linux Host With Nagios

Conclusion

That’s All. I hope, by now, you have Nagios up and running on your Ubuntu 22.04.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More