If you experience any difficulty in accessing content on our website, please contact us at 1-866-333-8917 or email us at support@chicagovps.net and we will make every effort to assist you.

Nick Phillips
By
February 3, 2017

USING NAGIOS TO MONITOR YOUR VIRTUAL PRIVATE SERVERS

 

Monitoring the uptime of your virtual private servers is an essential part of guaranteeing maximum uptime for your web facing assets. As a result, many VPS enthusiasts have exclusively chosen Nagios as their uptime monitoring suite.

Nagios is an open source uptime monitoring app that is used extensively by server administrators all around the world. If a problem is detected on one of your virtual private servers, Nagios can be configured to immediately alert an administrator of the issue.

When it comes to free open-source uptime monitoring software, Nagios is considered the gold standard.  Nagios gives administrators expert insight into services such as:

  • CPU Usage
  • Memory Consumption
  • Disk Performance
  • Log Files
  • HTTP Logs
  • SMTP Monitoring
  • DNS Uptime

Nagios can also be modified using plugins to get the exact uptime metrics of specific services used by your VPS.  In this article, we will setup Nagios on a low end box and use this VPS to remotely monitor other virtual private servers in your fleet.

How to Setup Your First Instance of Nagios

First, let’s setup Nagios on low end VPS and configure it to monitor itself. After this is setup, we can deploy Nagios to other servers that we may want to monitor remotely. Please note that the instructions in this article pertain to the Ubuntu 16.04 operating system.

Here are a few prerequisites for getting started with Nagios:

  • Root access
  • Apache
  • PHP

We will assume that you are logged in the VPS with your root account. If you aren’t, you will need to use all the commands below by prepending ‘sudo’.  Let’s start running the following commands to make sure our system is up to date and that we have all the required modules:

> apt-get update
> apt-get install openssl perl make php5-gd libgd2-xpm-dev libapache2-mod-php5 libperl-dev libssl-dev daemon wget apache2-utils unzip

Next, let’s create a user for Nagios with the following commands:

> useradd nagios

> groupadd nagcmd

> usermod -a -G nagcmd nagios

> usermod -a -G nagcmd www-data

We are now ready to install Nagios.  Let’s download the app and install it using the following commands:

> wget  https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.1.1.tar.gz
> tar -zxvf /tmp/nagios-4.1.1.tar.gz

> cd nagios-4.1.1/

> ./configure --with-nagios-group=nagios --with-command-group=nagcmd --with-httpd_conf=/etc/apache2/sites-enabled/

> make all

> make install

> make install-init

> make install-config

> make install-commandmode

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

If you haven’t encountered any errors, the Nagios Core should be completely installed. We need to execute a few more commands before Nagios is fully functional.

Type the following into an SSH window:

> wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gz

> tar xzf nagios-plugins-2.1.1.tar.gz

> cd nagios-plugins-2.1.1

> ./configure --with-nagios-user=nagios --with-nagios-group=nagios

> make

> make install

The next step is to edit the Nagios configuration file. This is the part where you’ll input your email address so that you can get the alerts generated from the servers.  Use the following command to open the config file.

> vim /usr/local/nagios/etc/objects/contacts.cfg

And change the following line:

> email admin@idroot.net ;

To the address that should receive the alerts.

> email youremail@domain.com;

Now that this is complete, we will need to open this file with your favorite editor:

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

and comment each occurrence the following lines:

AuthName "Nagios Access"

AuthType Basic

AuthUserFile /usr/local/nagios/etc/htpasswd.users

Require valid-user

Don’t forget to enable Apache’s rewrite and CGI modules:

> sudo a2enmod rewrite

> sudo a2enmod cgi

Before restarting the webserver, open the following configuration file:

/usr/local/nagios/etc/cgi.cfg

And change the following line from:

use_authentication=1

to

use_authentication=0

Now it’s time to restart the webserver. This will load the new configuration file. You can restart Apache using the following command:

> systemctl restart apache2

Now that our environment is ready, let’s create a configuration file that helps us monitor services. Use the following command to add the new file to the Nagios configuration:

> echo "cfg_file=/usr/local/nagios/etc/objects/newhost.cfg " >> /usr/local/nagios/etc/nagios.cfg

Create and open the new file with your favorite editor and add the following content changing the X.X.X.X with the IP address of the server you want to monitor:

define host{

use                     linux-server

host_name               newhost

alias                   newhost

address                 X.X.X.X

}

 

define service{

use                             local-service

host_name                       newhost

service_description             PING

check_command                   check_ping!100.0,20%!500.0,60%

}

In this test, we are only performing a basic ping to monitor the server’s response. Be sure to check out Nagio’s configuration file webpage for tips on how to further customize your uptime monitoring services.

We’ll want Nagios load when the system is booted up, therefore we must verify that the configuration file has no errors. Use the following command:

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

And you should get the following 2 lines at the end of the output:

Total Warnings: 0

Total Errors:   0

We are now ready to start Nagios service:

> systemctl start nagios

Nagios will be available on HTTP port 80 by default. Open your favorite browser and navigate to

http://YOURIP/nagios/

Click on the “Services” link located on the left side of the webpage in order to access the list of monitored services. You should be able to monitor the availability of both the local and remote server that we have configured in the steps above.

If they do not appear to be green, give it some time. The service will run regular tests in order to check the availability of the services. Since we just started Nagios for the first time, it will require a bit of time to complete the first check.

Important: Make sure that the remote server has no firewall on the ICMP protocol. Otherwise, the test will fail and you will receive an alert from Nagios that the server is unreachable.

Congratulations! You have installed and configured Nagios on your virtual private server.

Subscribe Email

Top