The commands in this guide are intended for a Debian-based system. Adjust package manager commands accordingly if you’re using a different Linux distribution.
Configuring a Nagios monitoring system on Scaleway
- Nagios
- monitoring
- Apache
Monitoring your resources is an indispensable building block for the success of your SaaS or e-commerce application. An unnoticed system failure can have serious financial consequences and negatively impact your image. Therefore, you will learn by following this tutorial how to install and configure a Nagios monitoring application with an Apache web server to monitor your servers. It is an open-source monitoring system that can automatically alert you in case of a server dysfunction.
Before you startLink to this anchor
To complete the actions presented below, you must have:
- A Scaleway account logged into the console
- Owner status or IAM permissions allowing you to perform actions in the intended Organization
- An SSH key
- At least 2 Instances or 2 Elastic Metal servers
Installing Nagios CoreLink to this anchor
-
Update the system and install required packages:
sudo apt update && sudo apt upgrade -ysudo apt install -y wget build-essential apache2 php libapache2-mod-php php-gd libgd-dev unzip -
Create a user and group for Nagios:
sudo useradd nagiossudo groupadd nagcmdsudo usermod -a -G nagcmd nagiossudo usermod -a -G nagcmd www-data -
Download and extract Nagios Core:
cd /tmpwget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.5.9.tar.gztar -xzf nagios-4.5.9.tar.gzcd nagios-4.5.9 -
Compile and install Nagios Core:
./configure --with-nagios-group=nagios --with-command-group=nagcmdmake allsudo make installsudo make install-commandmodesudo make install-initsudo make install-config
Installing Nagios pluginsLink to this anchor
Nagios plugins are essential for monitoring various services.
-
Install dependencies:
sudo apt install -y libssl-dev -
Download and extract Nagios plugins:
cd /tmpwget https://nagios-plugins.org/download/nagios-plugins-2.4.11.tar.gztar -xzf nagios-plugins-2.4.11.tar.gzcd nagios-plugins-2.4.11 -
Compile and install the plugins:
./configure --with-nagios-user=nagios --with-nagios-group=nagiosmakesudo make install
Configuring NagiosLink to this anchor
-
Configure the Nagios web interface:
sudo make install-webconfsudo a2enmod rewritesudo a2enmod cgi -
Create an administrative user for the web interface:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminYou will be prompted to set a password for the
nagiosadmin
user. -
Restart Apache to apply changes:
sudo systemctl restart apache2 -
Verify the Nagios configuration:
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgEnsure there are no errors before proceeding.
-
Enable and start Nagios service:
sudo systemctl enable nagiossudo systemctl start nagios
Accessing the Nagios web interfaceLink to this anchor
You can now access the Nagios web interface by navigating to http://your.server.ip.address/nagios
in your web browser. Log in with the nagiosadmin
user and the password you set earlier.
Monitoring remote servers with NCPALink to this anchor
The Nagios Cross-Platform Agent (NCPA) is a versatile agent that allows you to monitor remote systems. It’s a modern alternative to NRPE and supports various platforms.
On the remote server:
-
Download and install NCPA:
cd /tmpwget https://assets.nagios.com/downloads/ncpa3/ncpa-latest-1.amd64.debsudo dpkg -i ncpa-latest-1.amd64.debAdjust the download link and installation command based on your operating system. Refer to the NCPA documentation for details.
-
Edit the NCPA configuration file (typically located at
/usr/local/ncpa/etc/ncpa.cfg
) to set theapi_token
and configure allowed hosts. -
Start and enable NCPA service:
sudo systemctl enable ncpa_listenersudo systemctl start ncpa_listener
On the Nagios serverLink to this anchor
-
Download and install the NCPA plugin:
cd /tmpwget https://github.com/NagiosEnterprises/ncpa/archive/v3.1.3 -
Extract the plugin and move it to the plugins directory:
tar -xzf v3.1.3.tar.gzcd ncpa-3.1.3/pluginssudo cp check_ncpa.py /usr/local/nagios/libexec/ -
Modify permissions:
sudo chmod +x /usr/local/nagios/libexec/check_ncpa.py -
Define a new command in Nagios to use the NCPA plugin. Open the Nagios command configuration file:
sudo nano /usr/local/nagios/etc/objects/commands.cfgAdd the following definition:
define command {command_name check_ncpacommand_line $USER1$/check_ncpa.py -H $HOSTADDRESS$ -t '<API_TOKEN>' -M $ARG1$}Replace
<API_TOKEN>
with the actual API token configured in the NCPA agent on the remote server. -
Create a host definition for the remote server. Open the Nagios host configuration file:
sudo nano /usr/local/nagios/etc/servers/remote_host.cfgAdd the following:
define host {use linux-serverhost_name remote_hostalias Remote Hostaddress <REMOTE_SERVER_IP>max_check_attempts 5check_period 24x7notification_interval 30notification_period 24x7}Replace
<REMOTE_SERVER_IP>
with the actual IP address of the remote server. -
Define a service to monitor CPU usage on the remote server using NCPA. In the same
remote_host.cfg
file, add:define service {use generic-servicehost_name remote_hostservice_description CPU Usagecheck_command check_ncpa!cpu/percent}You can add more services like memory usage (
memory/virtual
), disk usage (disk/logical/|/percent
), etc. -
Restart Nagios to apply the changes
sudo systemctl restart nagios
Verify the setupLink to this anchor
- Go to the Nagios web interface (
http://your.server.ip.address/nagios
) - Check under Hosts to see if the remote server is listed.
- Check under Services to verify if CPU usage monitoring is working.