Why Nagios Core?
Nagios Core is an open-source monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes.
Prerequisites
Requirements
- • Ubuntu 22.04 or Debian 12
- • Root or sudo access
- • Minimum 1 GB RAM
- • 20 GB disk space
Optional
- • Domain name for web access
- • SSL certificate
- • Mail server for notifications
- • Additional hosts to monitor
Update Your System
Start by ensuring your system is up to date:
sudo apt update && sudo apt upgrade -yInstall Dependencies
Install Required Packages
Install Apache, PHP, and build tools:
sudo apt install -y apache2 php libapache2-mod-php php-gd \
wget unzip curl openssl libssl-dev build-essential \
libgd-dev libperl-dev daemon autoconf gcc makeCreate Nagios User and Group
Create dedicated user and group for Nagios:
sudo useradd -m -s /bin/bash nagios
sudo groupadd nagcmd
sudo usermod -aG nagcmd nagios
sudo usermod -aG nagcmd www-dataInstall Nagios Core
Download Nagios Core
Download the latest Nagios Core release:
cd /tmp
NAGIOS_VER="4.5.2"
wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-${NAGIOS_VER}/nagios-${NAGIOS_VER}.tar.gz
tar -xzf nagios-${NAGIOS_VER}.tar.gz
cd nagios-${NAGIOS_VER}Compile and Install
Compile and install Nagios:
./configure --with-httpd-conf=/etc/apache2/sites-enabled \
--with-command-group=nagcmd
make all
sudo make install
sudo make install-init
sudo make install-commandmode
sudo make install-config
sudo make install-webconfConfigure Apache
Enable required Apache modules and create admin user:
# Enable required modules
sudo a2enmod rewrite cgi
# Create Nagios admin user for web interface
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# You'll be prompted to enter and confirm a password
# Save this password securely!
# Restart Apache
sudo systemctl restart apache2Install Nagios Plugins
Download and Install Plugins
Install the official Nagios plugins:
cd /tmp
PLUGINS_VER="2.4.10"
wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-${PLUGINS_VER}/nagios-plugins-${PLUGINS_VER}.tar.gz
tar -xzf nagios-plugins-${PLUGINS_VER}.tar.gz
cd nagios-plugins-${PLUGINS_VER}
# Compile and install
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make installInstall Memory Check Plugin
Install a custom memory monitoring plugin:
cd /usr/local/nagios/libexec
sudo wget -O check_mem https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl
sudo chmod +x check_mem
sudo chown nagios:nagios check_mem
# Verify it works
/usr/local/nagios/libexec/check_mem -f -w 80 -c 90Start Nagios
Verify configuration and start Nagios:
# Verify configuration syntax
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# Enable and start Nagios service
sudo systemctl enable nagios
sudo systemctl start nagios
# Check status
sudo systemctl status nagiosCommand Definitions
Define Check Commands
Edit the commands configuration:
sudo nano /usr/local/nagios/etc/objects/commands.cfg# Memory check command
define command {
command_name check_local_mem
command_line $USER1$/check_mem -f -w $ARG1$ -c $ARG2$
}
# Disk check command
define command {
command_name check_local_disk
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
}
# Load check command
define command {
command_name check_local_load
command_line $USER1$/check_load -w $ARG1$ -c $ARG2$
}Monitoring Configuration
Create VPS Configuration
Create a monitoring configuration for your VPS:
sudo nano /usr/local/nagios/etc/objects/ramnode-vps.cfg# Host definition
define host {
use linux-server
host_name ramnode-vps
alias RamNode VPS Server
address 127.0.0.1
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}
# PING check
define service {
use local-service
host_name ramnode-vps
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
# Root partition disk space
define service {
use local-service
host_name ramnode-vps
service_description Disk Space - Root
check_command check_local_disk!20%!10%!/
}
# Memory usage
define service {
use local-service
host_name ramnode-vps
service_description Memory Usage
check_command check_local_mem!80!90
}
# System load
define service {
use local-service
host_name ramnode-vps
service_description System Load
check_command check_local_load!5.0,4.0,3.0!10.0,8.0,6.0
}
# Current users
define service {
use local-service
host_name ramnode-vps
service_description Current Users
check_command check_local_users!20!50
}
# Total processes
define service {
use local-service
host_name ramnode-vps
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}
# SSH service
define service {
use local-service
host_name ramnode-vps
service_description SSH
check_command check_ssh
}
# HTTP service
define service {
use local-service
host_name ramnode-vps
service_description HTTP
check_command check_http
}
# Swap usage
define service {
use local-service
host_name ramnode-vps
service_description Swap Usage
check_command check_local_swap!20%!10%
}Include Configuration
Add the new config to Nagios:
sudo nano /usr/local/nagios/etc/nagios.cfg
# Add this line:
cfg_file=/usr/local/nagios/etc/objects/ramnode-vps.cfg# Verify configuration
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# Restart Nagios
sudo systemctl restart nagiosThreshold Tuning
Recommended Thresholds by VPS Size
| VPS Size | Load Warning | Load Critical | Mem Warn | Mem Crit |
|---|---|---|---|---|
| 1 vCPU | 1.5,1.2,1.0 | 3.0,2.5,2.0 | 80 | 90 |
| 2 vCPU | 3.0,2.5,2.0 | 6.0,5.0,4.0 | 80 | 90 |
| 4 vCPU | 6.0,5.0,4.0 | 12.0,10.0,8.0 | 85 | 95 |
| 8 vCPU | 12.0,10.0,8.0 | 24.0,20.0,16.0 | 85 | 95 |
Load values are: 1-minute, 5-minute, 15-minute averages.
Security
Enable HTTPS with Let's Encrypt
Secure your Nagios installation with SSL:
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache -d nagios.yourdomain.comRestrict Access by IP
Limit access to trusted IPs:
sudo nano /etc/apache2/sites-enabled/nagios.conf<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
<RequireAll>
Require all granted
Require ip 192.168.1.0/24
Require ip your.public.ip.address
</RequireAll>
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>sudo systemctl restart apache2Configure Firewall
Open required ports:
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enableEmail Notifications
Install Mail Utilities
Install mail tools for notifications:
sudo apt install -y mailutils postfix
# During Postfix installation:
# - Select "Internet Site"
# - Enter your server's hostnameConfigure Contacts
Update the Nagios admin contact:
sudo nano /usr/local/nagios/etc/objects/contacts.cfgdefine contact {
contact_name nagiosadmin
use generic-contact
alias Nagios Admin
email your-email@domain.com
}sudo systemctl restart nagiosTesting
Verify Services
Check that all services are running:
sudo systemctl status nagios
sudo systemctl status apache2Test Plugins Manually
Test each plugin from the command line:
# Test disk check
/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
# Test memory check
/usr/local/nagios/libexec/check_mem -f -w 80 -c 90
# Test load check
/usr/local/nagios/libexec/check_load -w 5.0,4.0,3.0 -c 10.0,8.0,6.0
# Test swap check
/usr/local/nagios/libexec/check_swap -w 20% -c 10%Access Web Interface
Navigate to the Nagios dashboard:
http://your-vps-ip/nagiosLog in with the credentials you created earlier. You should see your host and all configured services.
Troubleshooting
Common Issues
Nagios won't start
sudo journalctl -u nagios -f
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgPermission denied errors
sudo chown -R nagios:nagios /usr/local/nagios
sudo chmod -R 755 /usr/local/nagios/libexecWeb interface shows "Forbidden"
sudo a2enmod cgi
sudo systemctl restart apache2Plugins returning unknown status
# Check plugin permissions
ls -la /usr/local/nagios/libexec/
# Test as nagios user
sudo -u nagios /usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /