Search for a command to run...
Install Nagios Core 4.5.14 and the Nagios Plugins on Linux, configure hosts and services, and verify the checks that keep your infrastructure honest.
Nagios Core is the original open-source monitoring system. It runs checks on a schedule, shows the current state of every host and service, and alerts you when something breaks — and again when it is fixed.
Nagios Core 4.5.14 · Nagios Plugins 2.5.x · Apache 2.x or Nginx · PHP 7.0 or newer · Ubuntu 20.04/22.04/24.04 LTS, Debian 10/11/12, RHEL 7/8/9
Nagios Core is free and text-configured. Nagios XI is the commercial edition built on the same engine, with a web-based setup wizard, dashboards, reporting and role-based access control. If you want the GUI, use XI; if you want full control and no licence cost, stay on Core.
Nagios Core is distributed as source, so it is compiled and installed on the host.
# Install the dependencies
sudo apt update
sudo apt install -y autoconf automake gcc libc6-dev make libgd-dev libssl-dev \
libtool pkg-config libxml2-dev libxslt1-dev libcurl4-openssl-dev \
libltdl-dev libperl-dev libmysqlclient-dev \
apache2 apache2-utils libapache2-mod-php php php-cli php-gd php-mysql \
mysql-server unzip wget
# Create the nagios user and group
sudo groupadd -r nagios
sudo useradd -r -g nagios -s /sbin/nologin -d /usr/local/nagios nagios
sudo usermod -aG nagios www-data
# Download Nagios Core 4.5.14
cd /tmp
curl -LO https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.5.14.tar.gz
tar xzf nagios-4.5.14.tar.gz
cd nagioscore-nagios-4.5.14
# Compile and install
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled --with-httpd-user=www-data
sudo make all
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
sudo make install-config
sudo make install-webconf
# Install the Nagios Plugins
cd /tmp
curl -LO https://github.com/nagios-plugins/nagios-plugins/archive/release-2.5.tar.gz
tar xzf release-2.5.tar.gz
cd nagios-plugins-release-2.5
sudo ./tools/setup
sudo ./configure
sudo make
sudo make install
# Create the web interface user
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# Enable the Apache modules
sudo a2enmod rewrite
sudo a2enmod cgi
sudo a2enmod php
# Start the services
sudo systemctl restart apache2
sudo systemctl enable --now nagiosCreate /usr/local/nagios/etc/objects/hosts.cfg:
define host {
use linux-server
host_name web1
alias Web Server 1
address 192.168.1.10
check_command check-host-alive
max_check_attempts 5
check_period 24x7
notification_period 24x7
notification_options d,u,r
contact nagiosadmin
}Create /usr/local/nagios/etc/objects/services.cfg:
define service {
host_name web1
service_description HTTP
check_command check_http
max_check_attempts 3
check_interval 5
retry_interval 1
check_period 24x7
notification_period 24x7
notification_options w,u,c,r
contact nagiosadmin
}
define service {
host_name web1
service_description SSH
check_command check_ssh
check_interval 5
retry_interval 1
max_check_attempts 3
}/usr/local/nagios/etc/objects/templates.cfg:
define host {
name linux-server
use generic-host
check_command check-host-alive
check_period 24x7
notification_period 24x7
notification_options d,u,r
contact nagiosadmin
register 0
}
define host {
name generic-host
notifications_enabled 1
event_handler_enabled 1
flap_detection_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
notification_period 24x7
register 0
}# Validate the configuration
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# Reload after a change (no downtime)
sudo systemctl reload nagios# The service is running
sudo systemctl status nagios
# The plugins work
sudo /usr/local/nagios/libexec/check_dns -H localhost -v
sudo /usr/local/nagios/libexec/check_http -H localhost -v
# The daemon is scheduling checks
ps aux | grep nagiosOpen http://<server>/nagios and sign in with nagiosadmin and the password you set.
# /usr/local/nagios/etc/objects/contacts.cfg
define contact {
use generic-contact
alias Nagios Administrator
email admin@example.com
}define contact {
use generic-contact
alias Slack Notifier
email slack-notifier@example.com
}# Install a notification command
sudo wget -O /usr/local/nagios/libexec/slack_notifier.py \
https://raw.githubusercontent.com/slagSHOT/slack_notifier/master/slack_notifier.py
sudo chmod +x /usr/local/nagios/libexec/slack_notifier.py# /usr/local/nagios/etc/commands.cfg
define command {
command_name check_slack
command_line /usr/local/nagios/libexec/slack_notifier.py -c /etc/nagios/slack_channel -t "$NOTIFICATIONTYPE$ - $SERVICESTATE$ - $SERVICEDESC$" -m "$SERVICEOUTPUT$"
}nagios -v.notification_options deliberately — d,u,r sends down, unreachable and
recovery notifications.max_check_attempts above 1 for services so a single blip does not page
anyone.check_by_ssh or NRPE for checks that must run on the target host, so you
do not open a network port to every machine.nagios --prune so the database does not grow
without bound.Install Grafana 13.2 on Linux, Windows, macOS, Docker and Kubernetes, connect Prometheus as a data source, and size the deployment for production.
Install the Elastic Stack 9.5 — Elasticsearch, Logstash and Kibana — from the official apt and rpm repositories, enable TLS security and ship your first logs.