Configuring a Nagios monitoring system on Scaleway
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 start
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 Core
-
Update the system and install required packages:
sudo apt update && sudo apt upgrade -y sudo 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 nagios sudo groupadd nagcmd sudo usermod -a -G nagcmd nagios sudo usermod -a -G nagcmd www-data
-
Download and extract Nagios Core:
cd /tmp wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.5.9.tar.gz tar -xzf nagios-4.5.9.tar.gz cd nagios-4.5.9
-
Compile and install Nagios Core:
./configure --with-nagios-group=nagios --with-command-group=nagcmd make all sudo make install sudo make install-commandmode sudo make install-init sudo make install-config
Installing Nagios plugins
Nagios plugins are essential for monitoring various services.
-
Install dependencies:
sudo apt install -y libssl-dev
-
Download and extract Nagios plugins:
cd /tmp wget https://nagios-plugins.org/download/nagios-plugins-2.4.11.tar.gz tar -xzf nagios-plugins-2.4.11.tar.gz cd nagios-plugins-2.4.11
-
Compile and install the plugins:
./configure --with-nagios-user=nagios --with-nagios-group=nagios make sudo make install
Configuring Nagios
-
Configure the Nagios web interface:
sudo make install-webconf sudo a2enmod rewrite sudo a2enmod cgi
-
Create an administrative user for the web interface:
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
You 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.cfg
Ensure there are no errors before proceeding.
-
Enable and start Nagios service:
sudo systemctl enable nagios sudo systemctl start nagios
Accessing the Nagios web interface
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 NCPA
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 /tmp wget https://assets.nagios.com/downloads/ncpa3/ncpa-latest-1.amd64.deb sudo dpkg -i ncpa-latest-1.amd64.deb
Adjust 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_listener sudo systemctl start ncpa_listener
On the Nagios server
-
Download and install the NCPA plugin:
cd /tmp wget 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.gz cd ncpa-3.1.3/plugins sudo 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.cfg
Add the following definition:
define command { command_name check_ncpa command_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.cfg
Add the following:
define host { use linux-server host_name remote_host alias Remote Host address <REMOTE_SERVER_IP> max_check_attempts 5 check_period 24x7 notification_interval 30 notification_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-service host_name remote_host service_description CPU Usage check_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 setup
- 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.
Visit our Help Center and find the answers to your most frequent questions.
Visit Help Center