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:
- You need to install Nagios-dependent packages on your server before installing Nagios.
- You can install Nagios on a virtual private server (VPS) or a dedicated server using Apache as your web server software.
- 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.
- You need to verify the sample configuration files for Nagios to ensure that the software starts at boot time.
- 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:
- A server running on Ubuntu 18.04.
- 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>
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.
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;
Download the file.
Once the download is complete, check the availability of the file using the ‘Is’ command:
Next, extract the tar.gz file by typing: tar -zxvf ./nagios-4.4.7.tar.gz;
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/;
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/
Use the make utility (make all) command to process the source code files.
Make all
Now, Install Nagios by running the following command:
$ sudo make install
Run the following command to install configuration files:
$ sudo make install-config
make install-config
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
Next, install the web interface by running the command:
$ sudo make install-webconf
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
tar xzf nagios-plugins-2.4.0.tar.gz
cd nagios-plugins-2.4.0
./configure --with-nagios-user=nagios --with-nagios-group=nagios
Make
Make 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
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
Now, change the section with the email address to receive the notification:
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
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
useradd nagios groupadd nagcmd usermod -a -G nagcmd nagios
Now enable the command below to enable Apache’s rewrite and CGI modules:
a2enmod rewrite a2enmod cgi
Restart Apache by running the following command to apply the changes:
systemctl restart apache2
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
Now, set Nagios to start automatically when the system starts.
systemctl enable nagios
Next, restart the Nagios service:
systemctl start nagios
check if its OK with
systemctl status nagios
If you receive an error like this one:
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
After:
Try to start it again:
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
When prompted, enter the username and password for the nagiosadmin user you created and hit Enter.
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.
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:
- Get the best dedicated server hosting from our list of top 10 dedicated server hosting providers in 2022.
- For the best virtual private server (VPS) hosting, choose from our list of the top 10 best VPS hosting services of 2022.
- Download the latest version of Nagios file from Nagios Core download page and use it to install Nagios on your Ubuntu 22.04 server.
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:
- https://www.edureka.co/blog/nagios-tutorial/
- https://www.techtarget.com/searchitoperations/definition/Nagios
- https://itslinuxfoss.com/install-nagios-ubuntu-22-04/
- https://kifarunix.com/install-and-setup-nagios-on-ubuntu/
- 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.