How to Install Nagios Open Source Monitoring on Ubuntu 20.04 Server

How to Install Nagios Open Source Monitoring on Ubuntu 20.04 Server. In this article we will introduce what Nagios server is with it’s main features and pros and move onto installation phase with using Apache Web Server, PHP and NRPE plugins. Let’s get started!.

What is Nagios

Nagios is a free, open source, and most powerful monitoring software that provides monitoring services for servers, switches, applications and various Linux based devices. With Nagios, you can monitor CPU load, disk space, memory usage and running processes on a remote server. It also sends a warning and critical notifications via email. Nagios works on client server architecture. It uses an NRPE plugin to obtain information from the remote systems.

Nagios core has the ability to monitor remote devices running Linux, Windows and Unix operating systems. It provides an informative and attractive web interface, where you can monitor all remote hosts and services. If you are looking for an open source monitoring solution then Nagios is the best choice for you.

Nagios Features

  • Free, Open source, scalable and secure.
  • Offers monitoring network services (FTP, SMTP, HTTP, SSH and POP3).
  • Detects network issues and server issues by sending alerts and notifications automatically.
  • SSL and SSH monitoring with encrypted tunnels.
  • Monitoring of your business process and network infrastructure. infrastructure and business processes
  • Nagios helps to manage the logs and database systems.
  • It is flexibility tool for the multi user access at the same time.
  • Important feature is failover capability and Nagios continuous monitoring.
  • It also easily integrates with third party applications.

Follow the next steps and we will show you how to install Nagios open source monitoring on Ubuntu 20.04 server.

How to Install Nagios Open Source Monitoring on Ubuntu 20.04 Server

Install Apache, PHP, and Other Components

Firstly, you will need to install the Apache webserver, PHP and other required packages to your server. You can install all of them by running the following command:

				
					apt-get install apache2 php libapache2-mod-php autoconf bc gawk dc build-essential gcc libc6 make wget unzip libgd-dev libmcrypt-dev make libssl-dev snmp libnet-snmp-perl gettext -y
				
			

After installing all the packages, start the Apache service and enable it to start at system reboot:

				
					systemctl start apache2
systemctl enable apache2
				
			

Install Nagios on Ubuntu 20.04

By default, the latest version of the Nagios package is not available in the Ubuntu default repository. So it is recommended to install the Nagios from the source.

So the first step is to download the latest version of Nagios using the following command:

				
					wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.6.tar.gz
				
			

Once the download is completed please extract the downloaded file with the following command:

				
					tar -xvzf nagios-4.4.6.tar.gz
				
			

Next, navigate to the extracted directory and configure it with the following command:

				
					cd nagioscore-nagios-4.4.6
./configure --with-httpd-conf=/etc/apache2/sites-enabled
				
			

You will get the following output:

				
					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.

				
			

Following is to run this command to compile all required programs:

				
					make all
make install-groups-users
				
			

Then add the Nagios user to the Apache group:

				
					usermod -a -G nagios www-data
				
			

Here install Nagios including, web config, command mode and other components using the following command:

				
					make install
make install-daemoninit
make install-commandmode
make install-config
make install-webconf

				
			

Next, enable the Apache rewrite and cgi module with the following command:

				
					a2enmod rewrite cgi
				
			

Finally please restart the Apache service to apply the changes:

				
					systemctl restart apache2
				
			

Create Nagios Admin User

For security purposes, it is recommended to secure the Nagios with password based authentication. You can create a Nagios admin user and set the password using the following command:

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

Set the password as shown below:

				
					New password:
Re-type new password:
Adding password for user admin
				
			

Install Nagios and NRPE Plugins

Next phase is to install the Nagios and NRPE plugins to your system. NRPE allows you to remotely execute Nagios plugins on other Linux machines. This will allows you to monitor remote machine metrics from the command line.

You can install them by running the following command:

				
					apt-get install monitoring-plugins nagios-nrpe-plugin -y
				
			

Once all the required plugins are installed, create a new directory to store remote host machine’s configuration:

				
					mkdir -p /usr/local/nagios/etc/hosts
				
			

Next, edit the Nagios configuration file and define the path of the directory create above:

				
					nano /usr/local/nagios/etc/nagios.cfg
				
			

Change the following line:

				
					cfg_dir=/usr/local/nagios/etc/hosts
				
			

Now you can edit the Nagios resource configuration file and define the path of the Nagios plugins:

				
					nano /usr/local/nagios/etc/resource.cfg
				
			

Change the following line:

				
					$USER1$=/usr/lib/nagios/plugins
				
			

Next is to edit the Nagios commands.cfg file and define the NRPE check command:

				
					nano /usr/local/nagios/etc/objects/commands.cfg
				
			

Add the following lines at the end of the file:

				
					define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
				
			

Save and close the file then start the Nagios service and enable it to start at system reboot:

				
					systemctl start nagios
systemctl enable nagios
				
			

You can also check the Nagios service status with the following command:

				
					systemctl status nagios
				
			

You will get the following output:

				
					● nagios.service - Nagios Core 4.4.6
     Loaded: loaded (/lib/systemd/system/nagios.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-01 12:48:32 UTC; 4s ago
       Docs: https://www.nagios.org/documentation
    Process: 27563 ExecStartPre=/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
    Process: 27564 ExecStart=/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg (code=exited, status=0/SUCCESS)
   Main PID: 27565 (nagios)
      Tasks: 8 (limit: 2348)
     Memory: 2.8M
     CGroup: /system.slice/nagios.service
             ├─27565 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
             ├─27566 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─27567 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─27568 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─27569 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh
             ├─27584 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
             ├─27585 /usr/lib/nagios/plugins/check_ping -H 127.0.0.1 -w 3000.0,80% -c 5000.0,100% -p 5
             └─27586 /bin/ping -4 -n -U -w 30 -c 5 127.0.0.1

				
			

Finally, restart the Apache service to apply all the configuration changes.

				
					systemctl restart apache2
				
			

To check the Apache status, run the following command:

				
					systemctl status apache2
				
			

You will get the following output:

				
					● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-01 12:54:42 UTC; 2min 4s ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 27695 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 27699 (apache2)
      Tasks: 10 (limit: 2348)
     Memory: 14.7M
     CGroup: /system.slice/apache2.service
             ├─27699 /usr/sbin/apache2 -k start
             ├─27700 /usr/sbin/apache2 -k start
             ├─27701 /usr/sbin/apache2 -k start
             ├─27702 /usr/sbin/apache2 -k start
             ├─27703 /usr/sbin/apache2 -k start
             ├─27704 /usr/sbin/apache2 -k start
             ├─27706 /usr/sbin/apache2 -k start
             ├─27708 /usr/sbin/apache2 -k start
             ├─27709 /usr/sbin/apache2 -k start
             └─27710 /usr/sbin/apache2 -k start

Apr 01 12:54:42 ubuntu2004 systemd[1]: Starting The Apache HTTP Server...

				
			

Access Nagios Web Interface

At this point of the tutorial How to Install Nagios Open Source Monitoring on Ubuntu 20.04 Server is that Nagios is installed and configured on your server. You can now access it using the URL http://your-server-ip/nagios. You will be asked to authenticate:

  1. Provide your Nagios admin username, password and click on the Sign in button. Once you are log in, you should see the Nagios dashboard in the following page:

2. Click on the Hosts in the left pane, you should see your local server on the following page:

nagios host page

3. Click on the localhost. You should see your server related information on the following page:

4. Click on the Services in the left pane, you should see the status of all running services on the following page:

Great well done, you have followed all the steps and learned How to Install Nagios Open Source Monitoring on Ubuntu 20.04 Server

How to Install Nagios Open Source Monitoring on Ubuntu 20.04 Server Conclusion

The Nagios monitoring tool is a strong monitoring tool that helps to detect the issues and performance pauses present in the network. The web interface provided by the tool helps to monitor the network and helps to find the issues present in the network component.

 

In the above guide, we explained how to install the latest version of Nagios on Ubuntu 20.04 server. We also explained how to install the Nagios and NRPE plugins and configure them to monitor the server itself. You can now add the remote hosts to the Nagios and start monitoring them from the central location.

Avatar for Hitesh Jethva
Hitesh Jethva

I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.

4 1 vote
Article Rating
Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x