How to install and configure Nagios on Ubuntu

0
581
How to install and configure Nagios on Ubuntu

Nagios Introduction:

Nagios is an awesome Open Source monitoring tool, its provides you more comprehensive monitoring environment to always keep an eye on your all machines / networks whether you are in a data center or just your small labs.

With Nagios, you can monitor your remote hosts and their services remotely on a single window. It shows warnings and indicates if something goes wrong in your servers which eventually help us to detect some problems before they occur. It helps us to reduce downtime and business losses.

Recently, Nagios released its latest versions Nagios 4.2.0 and its latest stable release of Nagios plugins 2.1.2 on August 01, 2016.

Features:

  • Monitor your entire IT infrastructure.
  • Identify problems before they occur.
  • Know immediately when problems arise.
  • Share availability data with stakeholders, hypothetical question
  • Detect security breaches.
  • Plan and budget for IT upgrades.
  • Reduce downtime and business losses.

 Prerequisites

Before install Nagios please install following pre-requisite packages which required to run Nagios,

Ubuntu 13.x / 14.x / 15.x

# apt-get update
# apt-get install -y autoconf gcc libc6 make wget unzip apache2 apache2-utils php5 libgd2-xpm-dev

Ubuntu 16.x / 17.x

# apt-get update
# apt-get install -y autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php7.0 libgd2-xpm-dev

Downloading Source

# cd nagios
# wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.3.2.tar.gz
Once downloaded unzip the package using 
# tar xzf nagioscore.tar.gz

Compile

# cd /root/nagios/nagioscore-nagios-4.3.2/
# ./configure --with-httpd-conf=/etc/apache2/sites-enabled
# make all

Create User And Group

Create a username called nagios and add the Nagios user to www-data group using following command,

# useradd nagios
 # usermod -a -G nagios www-data

Install Binaries

Install binary files, CGIs, and HTML files be using,

# make install

Install Service / Daemon

Install the service or daemon files and also configures them to start on boot.

# make install-init
# update-rc.d nagios defaults

Install Command Mode

This command installs and configures the external command file.

# make install-commandmode

Install Configuration Files

This command installs the *SAMPLE* configuration files. These are required as Nagios needs some configuration files to allow it to start.

# make install-config

Install Apache Config Files 

This installs the Apache web server configuration files and configures Apache settings.

# make install-webconf
 # a2enmod rewrite
 # a2enmod cgi

Configure Firewall

You need to allow port 80 inbound traffic on the local firewall so you can reach the Nagios Core web interface.

# ufw allow Apache
# ufw reload

Create nagiosadmin User Account 

You’ll need to create an Apache user account to be able to log into Nagios.

The following command will create a user account called nagiosadmin and you will be prompted to provide a password for the account.

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

When adding additional users in the future, you need to remove -c from the above command otherwise it will replace the existing nagiosadmin user (and any other users you may have added).

Start Apache Web Server

===== Ubuntu 13.x / 14.x =====

Restart Apache package if its running already;

# service apache2 restart

===== Ubuntu 15.x / 16.x / 17.x =====

Restart Apache package if its running already;

# systemctl restart apache2.service

Start Service / Daemon

This command starts Nagios Core.

===== Ubuntu 13.x / 14.x =====

# service nagios start

===== Ubuntu 15.x / 16.x / 17.x =====

# systemctl start nagios.service

Test Nagios

Nagios is now running; to confirm this you need to log into the Nagios Web Interface.

Point your web browser to the ip address or FQDN of your Nagios Core server, for example:

http://192.168.0.161/nagios
http://myserver/nagios

You will be prompted for a username and password. The username is nagiosadmin (you created it in a previous step) and the password is what you provided earlier.

Once you have logged in you are presented with the Nagios interface. Congratulations you have installed Nagios Core.

Read More: How to Install and Configure Nagios on RHEL/CentOS

Installing The Nagios Plugins

Nagios Core needs plugins to operate properly. The following steps will walk you through installing Nagios Plugins.

Prerequisites

Make sure that you have the following packages installed.

# apt-get install -y autoconf gcc libc6 libmcrypt-dev make libssl-dev wget bc gawk dc build-essential snmp libnet-snmp-perl gettext

Downloading The Source

# cd /tmp
# 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

Compile + Install

# cd /tmp/nagios-plugins-release-2.2.1/
 # ./tools/setup
 # ./configure
 # make# make install

Test Plugins

Point your web browser to the ip address or FQDN of your Nagios Core server, for example:

http://192.168.0.161/nagios  or
http://myserver/nagios

Go to a host or service object and “Re-schedule the next check” under the Commands menu. The error you previously saw should now disappear and the correct output will be shown on the screen.

Service / Daemon Commands

Different Linux distributions have different methods of starting / stopping / restarting / status Nagios.

===== Ubuntu 13.x / 14.x =====

# service nagios restart | status | stop | start

===== Ubuntu 15.x / 16.x / 17.x =====

# systemctl start nagios.service
# systemctl stop nagios.service
# systemctl restart nagios.service
# systemctl status nagios.service

NO COMMENTS