DebianLinuxTutorials

How To Install Nagios on Debian 9

Install Nagios on Debian 9

In this tutorial, we will show you how to install Nagios on your Debian 9 Stretch. For those of you who didn’t know, Nagios will monitor servers, switches, applications, and services. It alerts the System Administrator when something went wrong and also alerts back when the issues have been rectified. Resources that can be monitored include CPU, memory, and disk space loads, log files, temperature, or hardware errors. It can monitor various parameters and problems for services like HTTP, SMTP, and DNS, and with the help of plugins, it can be highly extended. Nagios core was originally designed to run under Linux, although it should work under most other units as well.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of Nagios open-source monitoring tool on a Debian 9 (Stretch) server.

Prerequisites

  • A server running one of the following operating systems: Debian 9 (Stretch).
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Nagios on Debian 9 Stretch

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt-get commands in the terminal:

sudo apt-get update
sudo apt-get upgrade

Step 2. Install LAMP (Linux, Apache, MariaDB, and PHP) server.

A Debian 9 LAMP server is required. If you do not have LAMP installed, you can follow our guide here. Also, install the dependencies for Nagios:

apt-get install build-essential openssl perl make php-gd libgd2-xpm-dev libapache2-mod-php libperl-dev libssl-dev daemon apache2-utils unzip

Step 3. Create users and groups for Nagios.

Now create a new Nagios user account and set up a password to this account:

useradd nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www-data

Step 4. Installing Nagios and plugins.

The first thing to do is to go to Nagios’s download page and download the latest stable version of Nagios, At the moment of writing this article it is version 4.4.6:

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

Perform the below steps to compile the Nagios from the source code:

./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Next steps, download the latest nagios-plugins source and install using the following commands:

wget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
tar -zxvf /tmp/nagios-plugins-2.2.1.tar.gz
cd /tmp/nagios-plugins-2.2.1/

Compile and install the plugins:

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

Step 5. Configure Nagios.

Edit the /usr/local/nagios/etc/objects/contacts.cfg config file with your favorite editor and change the email address associated with the nagiosadmin contact definition to the address you’d like to use for receiving alerts.

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

Change the email address field to receive the notification:

[...]
define contact{
contact_name nagiosadmin ; Short name of userus
generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of useremail
admin@idroot.us ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
[...]

Step 6. Configure Nagios Web Interface.

Now create Nagios apache2 configuration file:

nano /etc/apache2/sites-enabled/nagios.conf

Edit the following lines if you want to access nagios administrative console from a particular IP series, Here, I want to allow nagios administrative access from 192.168.1.0/24 series only:

[...]
## Comment the following lines ##
#   Order allow,deny
#   Allow from all

## Uncomment and Change lines as shown below ##
Order deny,allow
Deny from all
Allow from 127.0.0.1 192.168.1.0/24
[...]

Enable Apache’s rewrite and cgi modules:

sudo a2enmod rewrite
sudo a2enmod cgi

Configure Apache authentication:

We need to set up the password for the user nagiosadmin. This username will be used to access the web interface so it is important to remember the password that you will input here. Set the password running the following command and enter the password twice:

# sudo htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin

Restart Apache for the changes to take effect:

systemctl restart apache2

Step 7. Verify and Start Nagios service.

Next, we have to make Nagios start at boot time, so first verify that the configuration file has no errors running the following command:

systemctl start nagios
systemctl enable nagios

Step 8. Configure the firewall for Nagios.

Configure the firewall open port 80 to enable access to the Nagios:

firewall-cmd --permanent --add-port=80/tcp
firewall-cmd --reload
systemctl restart firewalld

Step 9. Accessing Nagios.

Nagios will be available on HTTP port 80 by default. Open your favorite browser and navigate to http://yourdomain.com/install.php or http://your-server-ip/install.php and complete the required steps to finish the installation. When prompted for username and password you will introduce the username “nagiosadmin” and the password that you entered in step 6.

Install Nagios on Debian 9

Congratulations! You have successfully installed Nagios. Thanks for using this tutorial for installing the Nagios monitoring tool in Debian 9 (Stretch) systems. For additional help or useful information, we recommend you to check the official Nagios website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

Save

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button