Linux

How to Install and Configure Nagios on Ubuntu

Feature-image-nagios

Nagios is an open-source monitoring system that is widely used. It maintains track of your servers and monitors them so you can be certain that your mission-critical services are up and functioning. Any production environment should employ a monitoring system like Nagios, since by monitoring uptime, CPU consumption, and disk space, you may prevent problems before they happen or before your users call you. In this article, you’ll learn how to install Nagios 4 and configure it so that you may use the web interface to monitor host resources. You’ll also install the Nagios Remote Plugin Executor (NRPE), an agent that runs on remote systems and allows you to monitor their resources. Other articles can be found here: How to Install and Configure Postfix as a Send-Only SMTP Server/, How to implement SAMBA (SMB) file shares for Servers and Clients/, also How to Configure Advanced PAM in Linux/ and How to Install LAMP Stack on Ubuntu 18.04 / and How to install MariaDB on Ubuntu

Install the required packages

Make sure you’ve installed the following packages on your Ubuntu installation before continuing.

  • Apache 2
  • PHP
  • GCC compiler and development libraries
  • GD development libraries

You can use apt-get to install these packages by running the following commands:

sudo apt-get install apache2 libapache2-mod-php5 build-essential libgd-dev
2022-03-20_14h37_23
required packages

The other steps required for the successful installation of Nagios are as shown below

Step 1: Create a user account

To create a new account and a password, kindly use the command below.

/usr/sbin/useradd -m -s /bin/bash nagios
passwd nagios
userandpasswd
user & passwd created

Create a new nagcmd group for allowing external commands to be submitted through the web interface. Add both the Nagios user and the apache user to the group.

/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd www-data

Step2: Download Nagios together with its plugin

Make a separate directory where the downloaded packages will be kept.

mkdir ~/downloads
cd ~/downloads

Download the source code tarballs of both Nagios Core and the Nagios plugins

wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.2.1.tar.gz
wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
nagios
nagios

The Plugin

nagios-plugin
nagios plugin

Step3: Compile and Install Nagios Core

Extract the Nagios Core source code tarball.

cd ~/downloads
tar xzf nagios-4.2.1.tar.gz
cd nagios-4.2.1

Run the Nagios configure script as follows, using the name of the group you defined previously as a parameter:

./configure --with-command-group=nagcmd
config-option-for-nagios
config options for nagios

Compile the Nagios Core source code.

make all
makeall-receipt

Set permissions on the external command directory and install binaries, an init script, and example config files.

make install
make install-init
make install-config
make install-commandmode
boom
external command directory

Step 4: Customize Configuration

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

vi /usr/local/nagios/etc/objects/contacts.cfg
email
i changed to my email

Step 5: Set up the Web User Interface

Install the Nagios Core web config file in the Apache conf.d directory.

make install-webconf

Possible Error

/usr/bin/install: regular file cannot be created 'etc/apache2/sites-enabled/nagios.conf': File or directory doesn't exist
Makefile:298: failure in the instructions for objective 'install-webconf'
make: *** [install-webconf] Error 1

Resolved by running:

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-enabled/nagios.conf
./configure --with-httpd-conf=/etc/apache2/sites-enabled
instll-mkeconf
fixed

To use the Nagios Core web interface, create a nagiosadmin account. Remember the password you choose for this account; you’ll need it in the future.

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

Restart Apache to make the new settings take effect.

/etc/init.d/apache2 reload

Step 6:  Compile and Install the Nagios Plugins

Extract the Nagios plugins source code tarball.

cd ~/downloads
tar xzf nagios-plugins-2.3.3.tar.gz
cd nagios-plugins-2.3.3

Compile and install the plugins.

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

Step7 : Start Nagios Core

Configure Nagios Core to automatically start when the system boots.

ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios

Verify the sample Nagios Core configuration files.

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
check
verify

If there are no errors, start Nagios Core.

/etc/init.d/nagios start
startnagios

Step 8: Login to the Web Interface

Type the command below in your VM or environment’s browser. You’ll be prompted for the username (nagiosadmin) and password you specified earlier

http://localhost/nagios/
login
web interface
nagios-login
logged in

Step 9: Additional Modifications:

If you want to receive email notifications for Nagios Core alerts, you need to install the mailx (Postfix) package.

sudo apt-get install mailx
sudo apt-get install postfix
posfixconfig
postfix
sudo /etc/init.d/nagios restart
postfix

Summary

We installed Nagios by following the series of steps shown above. Kindly refer to this guide on how to monitor Windows hosts via Nagios

I hope you found this blog post helpful. If you have any questions, please let me know in the comment session.

Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x