A Brief Guide for Configuring Nagios

By Arslan Ud Din Shafiq, Alibaba Cloud Tech Share Author. Tech Share is Alibaba Cloud’s incentive program to encourage the sharing of technical knowledge and best practices within the cloud community.

Nagios is an open source network monitoring software which was released under the GPL license. With more than 1 million users worldwide, it has an active community that provides free support and hundreds of add-ons developed by this community.

In this tutorial, we will be installing and setting up Nagios on an Alibaba Cloud Elastic Compute Service (ECS) with Ubuntu 16.04 installed.

Prerequisites

  • You must have Alibaba Cloud Elastic Compute Service (ECS) activated and verified your valid payment method. If you are a new user, you can get $300 — $1200 worth in Alibaba Cloud credits for your new account. If you don’t know about how to setup your ECS instance, you can refer to this tutorial or quick-start guide. Your ECS instance must have at least 1GB RAM and 1 Core processor.
  • A domain name registered from Alibaba Cloud. If you have already registered a domain from Alibaba Cloud or any other host, you can update its domain nameserver records.
  • Domain name must be pointed to your Alibaba Cloud ECS’s IP address
  • Access to VNC console in your Alibaba Cloud or SSH client installed in your PC
  • Set up your server’s hostname and create user with root privileges.

Setting Up Your Server

Before proceeding with installation of any kind of package, use the following command to update your Ubuntu system. To execute this command, remember to login from non-root user with sudo privileges.

You will need to install unzip which will be used to unzip the compressed zip folder.

You will need to install libssl-dev on your server.

Install build-essential with the command.

To install and configure libgd2-xpm-dev, execute the command.

You will need to install openssl on your server. To install openssl execute the command.

Install PHP

Nagios requires installation of PHP 5.3 or newer version of PHP. In this tutorial, you will install PHP 7.2. To install PHP 7.2, execute the following steps.

In the first step, you will need to install python software properties and software properties common. To do so, execute the command below.

You will need to add repository for newer versions of PHP. To do so, execute the commands below.

Update the system to refresh the available repositories. To do so, execute the command for updating Ubuntu system.

Install PHP 7.2. To install PHP 7.2, execute the following command.

Nagios requires the following PHP extensions:

  1. php7.2-mbstring
  2. php7.2-mysql
  3. php7.2-curl
  4. libapache2-mod-php

To install the above extensions of PHP, execute the following command.

When you have done installation of the above extensions, apache2 will be installed automatically.

You can execute the following command to check installed PHP version.

Install Nagios

To install Nagios, you will need to follow the steps below.

In the first step, you will create a user group and add a user.

Add user to nagcmd group.

Download Nagios by executing the command below.

In the second step, you will need to extract files from archived folder by using the command below.

In the third step, rename the extracted folder.

Remove the downloaded archived directory.

Navigate to nagios using the command below.

Before building Nagios, you will need to run configure where you will specify username and group you want Nagios to use.

Execute the following command to compile Nagios.

Execute the following commands to install Nagios, default configuration and init scripts.

Install Required Plugins

Nagios monitors remote hosts using Nagios Remote Plugin Extractor. To install it, follow the steps below.

Navigate to home directory.

Download archived folder by using the command below.

Extract archived directory using the command below.

Navigate to nrpe-* extracted directory.

Execute the following commands to configure, compile and install nrpe.

Configure Nagios

You will need to use Apache for serving web interface of Nagios. Execute the following command to copy apache configurations for Nagios to sites-available directory.

To entertain external commands via web interface to Nagios, you will need to add www-data user to nagcmd group.

Open Nagio configuration file using command below.

Find the line shown below and remove # to uncomment it and then save the file.

You will need to create a directory to store configuration file for each server that you will monitor by executing the command below.

Execute the following command to open contacts configuration file and replace email with your own email.

Open the file by executing command below.

Add the following text to the end of opened file and save it.

You will need to enable rewrite mod. You can do so by editing configuration file in apache2 directory or you can simply execute the command below.

You will need to enable cgi mod. You can do so by editing configuration file in apache2 directory or you can simply execute the command below.

To set the password for accesssing admin panel using username nagiosadmin execute the following command.

Execute the command below to disable default site.

You will need to enable the virtual host for Nagios. To do so, execute the command below.

You will have to restart apache server to apply the changes and load the settings by executing command below.

Create a system service for Nagios. Execute the following command to open a file for setting up Nagios service.

Copy and paste the following text in opened file.

Execute the following command to start Nagios service.

You can access your Nagios server via IP address or domain name http://your _domain.tld/nagios

After entering username and password for admin, you will be redirected to Nagios dashboard.

Reference:https://www.alibabacloud.com/blog/a-brief-guide-for-configuring-nagios_594753?spm=a2c41.12842984.0.0

Follow me to keep abreast with the latest technology news, industry insights, and developer trends.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store