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.
Related Posts:
- Have you ever visited the web’s busiest hosting forum? LowEndTalk awaits. - September 27, 2022
- Grab the deals first by subscribing to our new deal alerts - September 16, 2022
- LowEndBox is on Instagram and TikTok! - August 5, 2022
No explanation for each row in .cfg?
Just 2 remarks:
1. Nagios is good and proven solution, no doubt about it. I just think it might be a little overkill, especially for LEB-market VPS. There are some lightweight monitoring solutions too.
2. After known controversy with Nagios Enterprises kicking out the whole nagios-plugins team and rather stagnating “restricted” development, Nagios is not exactly my personal choice for monitoring. If anything similar, I’d recommend icinga. Not only is it more modern and up-to-date, even installation is more “ubuntu-like” (add repository and use apt-get install).
If you’re looking for something more cloud-based, free and less resource intensive, you can try UptimeTrack.com which offers free uptime monitoring. It definitely isn’t intended as a Nagios replacement but again, its free and less resource intensive.
Jon, looking for to get in contact with you but have no contact details, please send me an email with your email address. Thanks
We’re big fans of UptimeRobot, basic uptime monitoring is free, they just added the ability to have a public page with all of your monitors. It’s great.
Thanks for sharing your experience with us.