🔔
Monitoring & Observability

Nagios

Infrastructure monitoring and alerting for hosts and services

🐧 Linux🍎 Mac🪟 Windows
Reviewed: Tested on: Kubernetes 1.29 · Terraform 1.8 · Ubuntu 22.04

What is this?

Nagios watches your servers and sends you an alert when something stops working.

📥

Step 01

Install Nagios

(01)Install Nagios Core

Linux
1# Ubuntu / Debian
2sudo apt-get install -y nagios4 nagios-plugins-contrib apache2
3
4# RHEL / Fedora
5sudo dnf install -y nagios nagios-plugins-all httpd
6
7sudo systemctl enable nagios httpd
8sudo systemctl start nagios httpd
9
10# Default web UI: http://server/nagios
11# Default user: nagiosadmin (set password during install)
⚙️

Step 02

Configure Nagios

(01)Define host and service checks

Linux
1sudo nano /etc/nagios4/conf.d/hosts.cfg
2
3define host {
4 use generic-host
5 host_name webserver1
6 alias Web Server 1
7 address 192.168.1.21
8 max_check_attempts 5
9}
10
11sudo nano /etc/nagios4/conf.d/services.cfg
12
13define service {
14 use generic-service
15 host_name webserver1
16 service_description HTTP
17 check_command check_http
18}
19
20sudo nagios4 -v /etc/nagios4/nagios.cfg
21sudo systemctl restart nagios4

(02)Email alert notifications

Linux
1# Install mail utils
2sudo apt-get install -y mailutils
3
4# Edit contacts and commands:
5sudo nano /etc/nagios4/conf.d/contacts.cfg
6# define contact { contact_name admin; email admin@example.com; ... }
7
8sudo systemctl restart nagios4

Step 03

Verify Nagios

(01)Check config and web UI

Linux
1sudo nagios4 -v /etc/nagios4/nagios.cfg
2sudo systemctl status nagios4
3curl -I http://localhost/nagios4/

Step 04

Manage Nagios

(01)Add hosts and reload

Linux
1# After editing configs:
2sudo nagios4 -v /etc/nagios4/nagios.cfg
3sudo systemctl reload nagios4
4
5# External commands (schedule downtime):
6echo "[$(date +%s)] SCHEDULE_HOST_DOWNTIME;webserver1;$(date +%s);$(($(date +%s)+3600);1;0;0;Admin;Maintenance" | sudo tee /var/lib/nagios4/rw/nagios.cmd
🔧

Step 05

Common Problems

#1Host/service checks showing UNKNOWN

Linux
1sudo systemctl status nagios
2sudo nagios -v /etc/nagios/nagios.cfg
3sudo tail -f /var/log/nagios/nagios.log