How to install Nagios local server on Ubuntu OS?

To have reached this question, you should need a software for remote monitoring of electrical or non-electrical quantities, networks, services, etc.

According to Wikipedia – “Nagios, now known as Nagios Core, is a free and open source computer software application that monitors systems, networks, and infrastructure. Nagios offers to monitor and alerting services for servers, switches, applications, and services. It alerts users when things go wrong and alert them a second time when the problem has been resolved.”

In this article will be described how to install Nagios local server – step by step. In the document, the following packages are used – Nagios 4.2.1, Nagios Plugins2.1.2, and Ubuntu 16.04.
It is assumed, that the user is familiar with Linux and already has a workstation with Ubuntu 16.04.

You can continue reading this article or just switch to the updated one “How to install Nagios 4.3.4 local server on Ubuntu 18.04

1. How to install Nagios local server – initial settings

1.1. Run terminal as root to install Nagios local server necessary packages

Installation and configuration of the required packages require administrator rights, so before downloading and installing the following packages put the following command in the console:

sudo su

install-Nagios-local-server-initial-settings
You will be asked for a password, then the console goes into the root mode.

1.2. Packages installation

The following packages should be installed:

sudo apt-get install apache2
sudo apt-get install php7.0-gd
sudo apt-get install libapache2-mod-php7.0
sudo apt-get install build-essential
sudo apt-get install libgd2-xpm-dev

1.3. Creating a new user

It is necessary to create a new user and group to which it belongs. Use the following commands:

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

1.4. Creating a directory for downloading Nagios packages

mkdir ~/downloads
cd ~/downloads
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.2.1.tar.gz
wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz

2. Compiling and installing Nagios

cd ~/downloads
tar zxvf nagios-4.2.1.tar.gz
cd nagios-4.2.1/
./configure –with-nagios-group=nagios –with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
make install-webconf

Depending on system configuration, it is possible to be displayed following error:

install-nagios-local-server-compiling-error-1

This error is caused by Nagios process. It tries to create a configuration file in the directory /etc/httpd.conf/.
But in Ubuntu, this configuration file should be placed in the directory /etc/apache2/sites-enabled/.
The following command should be used:

sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-enabled/nagios.conf
sudo ls -l /etc/apache2/sites-enabled/

The result will be as follows:

install-nagios-local-server-command

3. Changing the e-mail address

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

The address nagios@localhost should be replaced with the desired email address. To save changes, use a keyboard shortcut Ctrl+X. After this choose Y and press Enter. The document remains with the same my name.

install-nagios-local-server-changing-mail

4. Configuring the Web interface, creating a user

After the execution of the following commands, a password for user nagiosadmin will be required.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
a2enmod cgi
sudo service apache2 restart

5. Compiling and installing of Nagios plugins

cd ~/downloads
tar zxvf nagios-plugins-2.1.2.tar.gz
cd nagios-plugins-2.1.2
./configure –with-nagios-user=nagios –with-nagios-group=nagios
make
make install

6. Start Nagios

ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios start

Depending on the configuration of the system, it is possible Nagios process, not to start. In this case, perform the following steps in the terminal:

6.1. nagios.service file creation

cd /etc/systemd/system/
sudo nano nagios.service

In this file, following rows should be inserted:

[Unit]
Description=Nagios
BindTo=network.target

[Install]
WantedBy=multi-user.target

[Service]
User=nagios
Group=nagios
Type=simple
ExecStart=/usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg

To save changes, use a keyboard shortcut Ctrl+X. After this choose Y and press Enter.

6.2. Copy the following configuration file

cp /etc/init.d/skeleton /etc/init.d/nagios

6.3. Edit the configuration file

sudo nano /etc/init.d/nagios

In the end of the file, following rows should be inserted:

DESC=”Nagios”
NAME=nagios
DAEMON=/usr/local/nagios/bin/$NAME
DAEMON_ARGS=”-d/usr/local/nagios/etc/nagios.cfg”
PIDFILE=/usr/local/nagios/var/$NAME.lock

install-Nagios-local-server-6.3

6.4. Saving the file, changing the conditions of access to it

sudo chmod +x /etc/init.d/nagios

6.5. Edit apache2 configuration file

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

Delete the # character from the row “Allow from 127.0.0.1”. This will allow Nagios process to be accessed at 127.0.0.1/nagios or localhost/nagios.

 

install-nagios-local-server-apache2

6.6. Start Nagios service

sudo service nagios start

7. Login into the Nagios via a WEB browser

The user interface is available at:

http://localhost/nagios/

127.0.0.1/nagios

The username: nagiosadmin

The password: as set in step 4

install-nagios-local-server-web`

8. Adding host to Nagios

To be added a host to the system, several configuration files should be changed. Changes are made through an editor in the console. It is recommended to stop Nagios during the changes:

sudo service nagios stop

It is recommended after any change in a file of the system to verify configuration using the following command:

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

So if there is a configuration error, only the last changed file should be checked.

8.1. Change of the main configuration file

The base installation of the system allows monitoring only of the local host (computer). It is necessary to allow to Nagios process access to other hosts – switches, routers or other servers.

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

After this command, an editor will be open.
From the last line #cfg_file=/usr/local/nagios/etc/objects/switch.cfg the character # should be removed.
This will allow Nagios process to access configuration file, where the host data are written.

install-nagios-local-server-web

8.2. Adding an information for the new host in the following configuration file

sudo nano /usr/local/nagios/etc/objects/switch.cfg

In the end of the file, details of the new host (TCW220) should be added

define host{

use generic-switch
host_name TCW220
alias Teracom Ethernet Controller TCW220
address 192.168.1.2
hostgroups switches
}

install-nagios-local-server-web

After saving changes in the configuration file, you need to restart Nagios process.

sudo service nagios restart

The new host is now available through a WEB interface.

install-nagios-local-server-web-interface

The basic installation of Nagios includes service for monitoring the host only. To add additional services should be available a plugin, which performs the service and posts the results in the user interface.

We hope that this article was helpful enough to learn how to install Nagios local server and use it with different hosts.

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.