Nagios is an open source server and network monitoring tool which monitors some services (CPU, HTTP, SMTP, storage disk, temperature, etc) of your servers, network devices and alerts you when a particular service that's being monitored goes wrong. It will also alert you when a service comes back to a normal required state. Nagios is useful for keeping an inventory of your server and making sure your critical services are up and running.
How does nagios work?
Nagios runs in agent-based and agentless configurations. A user-friendly, web-based graphical user interface is provided in some versions of Nagios and from third parties like NagiosQL, or an administrator can choose to work in the command-line interface. It also comes with a dashboard that provides an overview of the critical parameters monitored on assets.
The installation of nagios requires the steps below
- apache and php installed with some other pre-requisites packages which will be listed on the article
- the creation of a nagios user
- the installation and configuration of nagios-core
- the configuration of the nagios web interface
- the installation and configuration of the nagios plugins
- the configuration of the firewall
In another article, we have shown how to install Nagios on centos 7. Now let's explain step to follow in order to install nagios on debian 9 with detailed information
1) Install pre-requisites
To have nagios well working, you need apache2 and php to be installed and correctly configured. If you have not yet these packages installed, you can do it with the command below.
# apt install apache2 apache2-utils php
In this article, the configuration of the above packages will be not detailed. There are some other pre-requisites packages to install as below
# apt install -y build-essential autoconf gcc libc6 make wget unzip libgd2-xpm-dev
2) Create Nagios user and group
You'll need a default user and group on nagios for the system to run under. The default user will be nagios and the default group will be nagcmd.nagios You can turn off logins for this user once everything is installed
# useradd nagios && groupadd nagcmd # usermod -a -G nagcmd nagios && usermod -a -G nagcmd www-data
3) Install and build Nagios 4.3.2 from source code
a) Download nagios
We will download nagios from the official github site. We will create our working directory at /opt/nagios
# mkdir /opt/nagios
# cd /opt/nagios
Now download nagios
# wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.3.2.tar.gz
# tar xzf nagioscore.tar.gz
# cd nagioscore-nagios-4.3.2/
b. Install and configure nagios
Now we will configure, compile and install nagios.
# ./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/
# make all
You can that it helps you by giving you next configurations steps to follow and description. Now we will install the binary files, CGIs, and HTML files
# make install
We will install the service or daemon files and also configure them to start on boot
# make install-init
Now install and configure the external command file
# make install-commandmode
Now install the *SAMPLE* configuration files. These are required as Nagios needs some configuration files to allow it to start.
# make install-config
Then install the Apache web server configuration files and configure the Apache settings.
# make install-webconf
# a2enmod rewrite && a2enmod cgi
4) Configure nagios web interface
The web interface requires login so we will create a nagiosadmin account and record the password that we will assign
# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin New password: Re-type new password:
Notice that you will use this user and password to log into you nagios web interface. Now restart apache service to make modifications to take effect
# systemctl restart apache2.service
5) Download and install nagios plugins 2.2.1
To work properly, nagios core needs plugins to monitor various services. You need to make sure that you have the pre-requisites packages installed
# apt install -y autoconf gcc libc6 libmcrypt-dev make libssl-dev wget bc gawk dc build-essential snmp libnet-snmp-perl gettext
Now we will create our working directory into /opt
directory where we will download the plugins
# mkdir /opt/nagios && cd /opt/nagios
# wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gz
# tar zxf nagios-plugins.tar.gz
# cd nagios-plugins-release-2.2.1
Now we will compile and install the plugins
# ./tools/setup
# ./configure
# make
# make install
6) Start nagios service and access to your nagios server
Before starting nagios, we need to check if the nagios configuration file doesn't have any error
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg ........................ ........................ Total Warnings: 0 Total Errors: 0 Things look okay - No serious problems were detected during the pre-flight check
As it looks fine, now let's make nagios services start on startup
# systemctl enable nagios
# systemctl reload nagios
Now we can start the nagios service
# systemctl start nagios
Note that if you don't start the nagios service, you will have an error message at you nagios homepage.
Now you can access to your web interface at the address http://nagios-ip/nagios via your web browser. If you server has an interface environment, so you can open your web browser and use the link http://localhost/nagios. You will be asked to enter the username and the password. Below are the values that I have configured
- username: nagiosadmin
- password: nagios
Then you will have the following homepage
Now you can go to Hosts or Services menu list to the left side in order to see you server and services monitored.
You can see that the default monitored services of our server.
7) Configure Firewall
If you can not access to your web interface, you should check your firewall configuration.
By default on Debian 9, it seems that ufw is not installed but iptables is installed. So, you will certainly need to allow port 80 inbound traffic on the local firewall to reach the nagios core web interface.
# iptables -I INPUT -p tcp --destination-port 80 -j ACCEPT
# apt install -y iptables-persistent
Save the firewall configuration
# iptables-save
But if you prefer ufw as firewall instead of iptables, use the command below
# ufw allow Apache
# ufw reload
Now restart all service again to check
# systemctl restart nagios
# systemctl restart apache2.service
Conclusion
Now that you monitoring your server and some of its services. Nagios has proven popular among small and large businesses. If you want to be proactive, have peace of mind, and sleep well at night, you should implement a robust system and network monitoring solution for your IT infrastructure.
Merci Alain! You put lotsa effort into it and it works like a charme - what more can I ask for? Nice and detailled Howto that also explains what we do in some sentences. Class!
You are welcome.
I' ve done each instruction on this tutorial but i can't start nagios from my browser. Thank's for the tutorial
Hi Scorpion,
Sorry for the time. What didn't work exactly? have you resolved the issue?
Thanks nice informations.
All successful and working fine at Nagios 4.3.4.
Arigatou from Japan.
Hola amigo ... from venezuela.... hope you're good ... im having problems on the plugins part
after adding this line:
apt install -y autoconf gcc libc6 libmcrypt-dev make libssl
-dev wget bc gawk dc build-essential snmp libnet-snmp-perl gettext
i don't know why ... may be it needs more information ... i mean ... like an individual way of
installing for that part .... please help me ...
Hi,
make sure to write the name of packages correctly such as "libssl-dev" without space instead of what you wrote.
Thanks...
Alternative plug-in installation (... and easy):
# apt install nagios-plugins
# cp /usr/lib/nagios/plugins/check_* /usr/local/nagios/libexec
;)