How to Install Nagios on an Ubuntu 22.04 VPS or Dedicated Server

How to Install Nagios on an Ubuntu 22.04 VPS or Dedicated Server

nagios ubuntu install

Nagios is an open-source monitoring software that helps you monitor your servers and complete infrastructure, including your critical services, applications, operating systems, and network protocols. It can send you alerts via email or SMS whenever it detects any issue with the monitored services.

This article will show you how to install Nagios on an Ubuntu 22.04 VPS. We’ll also show you how to add a basic monitoring configuration for your local system so you can start using Nagios immediately after installation.

 

How to Install Nagios on Ubuntu 22.04 VPS

To install Nagios on Ubuntu 22.04, you first need to install the required Nagio dependencies. Update the system’s repository cache, then use “sudo apt-get update -y” to update the entire package. Use the “wget” command along with the path to download the Nagios setup zip file. Uncompress and untar the file, then install it using the “$ sudo make install” command.

After installation, enable Firewall and allow Apache services. Restart Apache to effect the changes, then access the Nagios dashboard via  http://ip-address/nagios/. Key in your username and password to begin adding hosts and services to monitor.

 

Key Takeaways

Here are the key takeaways from this guide on how to install Nagios on Ubuntu 22.04:

  1. You need to install Nagios-dependent packages on your server before installing Nagios.
  2. You can install Nagios on a virtual private server (VPS) or a dedicated server using Apache as your web server software.
  3. To access Nagios, you need to create a user account (nagioadmin) and have the username and password to log into and administer the Nagios dashboard.
  4. You need to verify the sample configuration files for Nagios to ensure that the software starts at boot time.
  5. After installing and configuring Nagios, you need your IP address to access the Nagios dashboard on http://ip-address/nagios/.

 

Installing Nagios on Ubuntu: Step-by-Step Guide

Before you begin following this guide, you’ll need the following:

  1. A server running on Ubuntu 18.04.
  2. A non-root user with sudo privileges configured on your server.

Step 1: Installing Nagios

Before installing Nagios on Ubuntu, you will must install Nagios-dependent packages so you can install the software from there.

First, update the system’s repository cache by running the following command <sudo wget -O /etc/apt/sources.list.d/nagios-stable.list>

After adding the repository, you’ll need to update your package list so that apt knows about the new packages available.

Update the entire package list by running the command:

<sudo apt-get update -y>

 

nagios ubuntu install

You can install PHP, apache, OpenSSL, and other relevant dependencies separately or using a single command.

<sudo apt install build-essential apache2 php libgd-dev unzip>

When prompted, select YES when asked if you want to continue with the installation.

nagios ubuntu install

nagios ubuntu install

With all of the required dependencies now installed, we can move on and download the Nagios Core files.

Next, you need to download and build the Nagios source. To do so, go to the Nagios Core download page and download the latest version of Nagios. The version is 4.4.7 at the time of writing this article.

You can always check for newer versions by visiting the official Nagios downloads page. To download it directly to your server, type:

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

nagios ubuntu install

Download the file.

nagios ubuntu install

Once the download is complete, check the availability of the file using the ‘Is’ command: nagios ubuntu install

Next, extract the tar.gz file by typing: tar -zxvf ./nagios-4.4.7.tar.gz; 

nagios ubuntu install

This step is necessary to uncompress and untar the file since we are doing a manual installation.

Change the path (working directory) to the Nagios folder and start building the installation files.

cd ./nagios-4.4.7/;

nagios ubuntu install

Step 2: Compiling and Installing Nagios

After downloading the Nagios file, it’s time to compile, install and configure it to ensure it uses the user and group you have already created.

While inside the Nagios directory, run the command ./configure to start the compilation process.

$ sudo ./configure

Now, you can start compiling Nagios from the source code.

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

nagios ubuntu install

nagios ubuntu install

Use the make utility (make all) command to process the source code files.

Make all

nagios ubuntu install

nagios ubuntu install

nagios ubuntu install

Now, Install Nagios by running the following command:

$ sudo make install

nagios ubuntu install

nagios ubuntu install

Run the following command to install configuration files:

$ sudo make install-config
make install-config

nagios ubuntu install

You’ll need these configuration files to start up and set up Nagios to begin functioning.

Run the following command to install the external command file:

$ sudo make install-commandmode

nagios ubuntu install

Next, install the web interface by running the command:

$ sudo make install-webconf

nagios ubuntu install

Now, download the latest Nagios-plugins source (2.4.0 at the time of writing this article), then install it using the commands below:

wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.4.0/nagios-plugins-2.4.0.tar.gz

nagios ubuntu install

tar xzf nagios-plugins-2.4.0.tar.gz

nagios ubuntu install

cd nagios-plugins-2.4.0

nagios ubuntu install

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

nagios ubuntu install

nagios ubuntu install

Make

nagios ubuntu install

nagios ubuntu install

nagios ubuntu install

Make install

nagios ubuntu install

nagios ubuntu install

After installing everything, you’ll need to start the Nagios service and enable it to start automatically at boot time.

Step 3 – Configuring Nagios

Now that Nagios is up and running, it’s time to configure it so you can start monitoring your systems.

Configuration will be pretty easy since you already installed the configuration files.

At this point, the installer has placed the configuration files in the directory named /usr/local/nagios/etc.

Let’s see them by running this code:

ls -ltra /usr/local/nagios/etc

nagios ubuntu install

These configuration files need to work appropriately with Nagios. But you must make a few changes before proceeding to the next step.

Locate the file /usr/local/nagios/etc/objects/contacts.cfg and edit it, then change the associated email address with the nagioaadmin contact definition.

Include the email address where you want to be receiving monitoringn alerts.

vi /usr/local/nagios/etc/objects/contacts.cfg

nagios ubuntu install

Now, change the section with the email address to receive the notification:

nagios ubuntu install

Or do it in one line with the following command, replacing “myemail” with your email:

sed -i 's/nagios@localhost/myemail/' /usr/local/nagios/etc/objects/contacts.cfg

Example (and afterward, we check it with grep)

sed -i ‘s/nagios@localhost/something@mydomain.com/’ /usr/local/nagios/etc/objects/contacts.cfg

nagios ubuntu install

Step 4 – Configuring Nagios Web Interface

The next step is to create a user account (nagioadmin) to allow the user to log into and administer the Nagios dashboard.

You’ll also need to create Nagios users and a nagcmd group to allow the external commands to run through the web interface.

You can create a user account by running the following command:

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

nagios ubuntu install

useradd nagios

groupadd nagcmd

usermod -a -G nagcmd nagios

nagios ubuntu install

Now enable the command below to enable Apache’s rewrite and CGI modules:

a2enmod rewrite

a2enmod cgi

nagios ubuntu install

Restart Apache by running the following command to apply the changes:

systemctl restart apache2

nagios ubuntu install

Next, you have to ensure Nagios starts at boot time. To do so, you need to verify the sample configuration files for Nagios. You can verify this by running the command below:

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

nagios ubuntu install

Now, set Nagios to start automatically when the system starts.

systemctl enable nagios

nagios ubuntu install

Next, restart the Nagios service:

systemctl start nagios

check if its OK with

systemctl status nagios

If you receive an error like this one:

nagios ubuntu install

Edit the config file:

vi /usr/local/nagios/etc/nagios.cfg

And replace the 1 with a 0 in the check_for_updates line:

Before

nagios ubuntu install

After:

nagios ubuntu install

Try to start it again:

nagios ubuntu install

Step 5 – Accessing Nagios

After installing and configuring Nagios, the next step is to access the Nagios dashboard.

Access the dashboard via the URL: http://ip-address/nagios/ and replace the ‘IP address’ part with your server’s IP address.

You can obtain your server’s IP by running the following command:

hostname –I

nagios ubuntu install

When prompted, enter the username and password for the nagiosadmin user you created and hit Enter.

nagios ubuntu install

After login in successfully, you should now see the Nagios homepage and the dashboard from where you can begin adding your hosts and the services you want to monitor.

nagios ubuntu install

When you click on “Hosts” in the left-hand sidebar, and then “All Hosts,”  it will take you to a page where you can see the hosts currently being monitored by Nagios (as you can see, there are already a few hosts being monitored by default).

If you click on one of these hosts, you can see more information about it, including the services being monitored for that host.

If everything looks good, then congratulations! You’ve successfully installed and configured Nagios on your Ubuntu 22.04 server!

 

Conclusion

Now that you’ve come to the end of this article, you know how to install Nagios on your Ubuntu 22.04 server.

You can use this step-by-step guide to install Nagios on a virtual private server (VPS) or a dedicated server using Apache as your web server software and PHP for processing dynamic content from your pages.

You also know how to securely access the web interface so that you can begin monitoring your systems and applications immediately after installing Nagios.

You can also read how to install Nagios on Ubuntu 18.04 VPS if you’re using the 18.04 server.

 

Next Steps: What Now?

Here are some practical steps you can take from this article:

 

Further Reading:

Here are more valuable resources you can read to learn about Nagios and how to install and use it to monitor your server:

  1. https://www.edureka.co/blog/nagios-tutorial/
  2. https://www.techtarget.com/searchitoperations/definition/Nagios
  3. https://itslinuxfoss.com/install-nagios-ubuntu-22-04/
  4. https://kifarunix.com/install-and-setup-nagios-on-ubuntu/
  5. https://www.rosehosting.com/blog/how-to-install-nagios-4-and-monitor-your-servers-on-ubuntu-20-04/

 

FAQs

What is Nagios for, and Is It Free to Use?

Nagios is an open-source monitoring software that monitors servers and infrastructure, including critical services, applications, operating systems, and network protocols. The software is freely available at nagio.org to download, use and modify as you want.

What are the Prerequisites for Installing Nagios?

Before installing Nagios software, you need to have a server (either VPS or a dedicated server) running on Ubuntu 18.04. You must also have a non-root user configured with sudo privileges on your server.

How Do I Find My Nagios Server IP?

To find your Nagios server IP and check settings. In hardware, go to the network adapter. Change the network connection to NAT. Click Ok and start your VM. The server IP address should appear.

How To Set up a VSFTPD Server on a CentOS 7 VPS or Dedicated Server

Brief Description FTP is usually insecure exposing clear-text passwords, userna
2 min read
Avi Ilinsky
Avi Ilinsky
Hosting Expert

How To Set up a VSFTPD Server on an Ubuntu 16.04 VPS or Dedicated Server

Brief Description FTP data is usually insecure since information (usernames, pa
2 min read
Eliran Ouzan
Eliran Ouzan
Web Designer & Hosting Expert

How to use phpMyAdmin to develop a website (without MySQL experience)

Brief description A web developer who is not well versed into coding websites f
2 min read
Idan Cohen
Idan Cohen
Marketing Expert

How to Install MySQL on a Windows Web Server Running Apache

This tutorial will show you how to install the MySQL database on a Windows serve
3 min read
Michael Levanduski
Michael Levanduski
Expert Hosting Writer & Tester
HostAdvice.com provides professional web hosting reviews fully independent of any other entity. Our reviews are unbiased, honest, and apply the same evaluation standards to all those reviewed. While monetary compensation is received from a few of the companies listed on this site, compensation of services and products have no influence on the direction or conclusions of our reviews. Nor does the compensation influence our rankings for certain host companies. This compensation covers account purchasing costs, testing costs and royalties paid to reviewers.
Click to go to the top of the page
Go To Top