×
Community Blog A Brief Guide for Configuring Nagios

A Brief Guide for Configuring Nagios

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

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.

# sudo apt update && sudo apt upgrade

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

# sudo apt-get install unzip -y

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

# sudo apt-get install libssl-dev

Install build-essential with the command.

# sudo apt-get install build-essential

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

# sudo apt-get install libgd2-xpm-dev

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

# sudo apt-get install openssl

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.

# sudo apt-get install software-properties-common python-software-properties 

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

# sudo add-apt-repository ppa:ondrej/php

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

# sudo apt update

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

# sudo apt install -y php7.2

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.

# sudo apt install -y php7.2-mysql php7.2-curl php7.2-mbstring libapache2-mod-php

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.

# 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.

# sudo adduser nagios
# sudo groupadd nagcmd

Add user to nagcmd group.

# sudo adduser nagios nagcmd

Download Nagios by executing the command below.

# curl -L -O https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.3.4.tar.gz

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

# tar zxf nagios-4.3.4.tar.gz

In the third step, rename the extracted folder.

# mv nagios-4.3.4 nagios

Remove the downloaded archived directory.

# sudo rm nagios-4.3.4.tar.gz

Navigate to nagios using the command below.

# cd nagios

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

# ./configure --with-nagios-group=nagios --with-command-group=nagcmd

Execute the following command to compile Nagios.

# make all

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

# sudo make install
# sudo make install-commandmode
# sudo make install-init
# sudo make install-config

Install Required Plugins

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

Navigate to home directory.

# cd ~

Download archived folder by using the command below.

# curl -L -O https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz

Extract archived directory using the command below.

# tar zxf nrpe-*.tar.gz

Navigate to nrpe-* extracted directory.

# cd nrpe-*

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

# ./configure
# make check_nrpe
# sudo make install-plugin

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.

# sudo /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/apache2/sites-available/nagios.conf

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

# sudo usermod -G nagcmd www-data

Open Nagio configuration file using command below.

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

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

1

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

# sudo mkdir /usr/local/nagios/etc/servers

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

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

Open the file by executing command below.

# sudo nano /usr/local/nagios/etc/objects/commands.cfg

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

define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

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.

# sudo a2enmod rewrite

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.

# sudo a2enmod cgi

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

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

Execute the command below to disable default site.

# sudo a2dissite 000-default.conf

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

# sudo a2ensite nagios

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

# sudo service apache2 restart

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

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

Copy and paste the following text in opened file.

[Unit]
Description=Nagios
BindTo=network.target

[Install]
WantedBy=multi-user.target

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

Execute the following command to start Nagios service.

# sudo systemctl start Nagios

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.

2

Congratulations! You have successfully installed and configured Nagios server monitoring.

0 0 0
Share on

Alibaba Clouder

2,599 posts | 762 followers

You may also like

Comments