Install and configure Nagios Core 4.5 for network and server monitoring with web interface

Beginner 45 min Apr 03, 2026 28 views
Ubuntu 24.04 Ubuntu 22.04 Debian 12 AlmaLinux 9 Rocky Linux 9 Fedora 41

Set up Nagios Core 4.5 monitoring system with Apache web interface to monitor servers, network devices, and services. Configure hosts, services, and email notifications for comprehensive infrastructure monitoring.

Prerequisites

  • Root or sudo access
  • 2GB+ RAM recommended
  • Basic Linux command line knowledge
  • Email server access for notifications

What this solves

Nagios Core provides comprehensive monitoring for your infrastructure by tracking servers, network devices, and services. This tutorial sets up Nagios with a web interface for viewing status dashboards, configuring monitoring checks, and receiving alerts when systems go down or performance degrades.

Step-by-step installation

Update system packages

Update your package manager to ensure you get the latest versions and security patches.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install required dependencies

Install Apache web server, PHP, development tools, and libraries needed to compile Nagios Core from source.

sudo apt install -y apache2 apache2-utils php php-gd libgd-dev
sudo apt install -y build-essential unzip wget openssl libssl-dev
sudo dnf install -y httpd php php-gd gd-devel
sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y unzip wget openssl-devel

Create Nagios user and group

Create dedicated system accounts for Nagios to run securely without root privileges.

sudo useradd -r -s /bin/false nagios
sudo usermod -aG nagios www-data
Note: On Red Hat systems, replace www-data with apache in the usermod command.

Download and compile Nagios Core

Download Nagios Core 4.5 source code and compile it with the necessary configuration options.

cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.5.5.tar.gz
tar -xzf nagios-4.5.5.tar.gz
cd nagios-4.5.5

Configure the build with proper paths and user settings.

./configure --with-httpd-conf=/etc/apache2/sites-enabled \
  --with-nagios-user=nagios \
  --with-nagios-group=nagios \
  --with-command-user=nagios \
  --with-command-group=nagios

Compile and install Nagios Core.

make all
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
sudo make install-config
sudo make install-webconf

Download and install Nagios plugins

Install monitoring plugins that provide the actual check commands for services like HTTP, SSH, disk usage, and load average.

cd /tmp
wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.4.10/nagios-plugins-2.4.10.tar.gz
tar -xzf nagios-plugins-2.4.10.tar.gz
cd nagios-plugins-2.4.10

Configure and compile the plugins.

./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
sudo make install

Configure Apache web server

Enable required Apache modules and configure authentication for the Nagios web interface.

sudo a2enmod rewrite cgi
sudo systemctl restart apache2
sudo systemctl enable httpd
sudo systemctl start httpd

Create Nagios admin user

Set up HTTP basic authentication for accessing the Nagios web interface.

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Enter a strong password when prompted. This account will have full administrative access to Nagios.

Configure file permissions

Set proper ownership and permissions for Nagios files and directories.

sudo chown -R nagios:nagios /usr/local/nagios/
sudo chmod 755 /usr/local/nagios/var/rw
sudo chmod 644 /usr/local/nagios/etc/*.cfg
Never use chmod 777. It gives every user on the system full access to your files. Nagios only needs specific permissions for the web server and nagios user.

Configure Nagios main configuration

Edit the main Nagios configuration file to enable the web interface and set basic monitoring parameters.

# Enable web interface
check_external_commands=1
command_check_interval=10s
command_file=/usr/local/nagios/var/rw/nagios.cmd

Log settings

log_file=/usr/local/nagios/var/nagios.log log_initial_states=1 log_current_states=1

Object configuration files

cfg_file=/usr/local/nagios/etc/objects/commands.cfg cfg_file=/usr/local/nagios/etc/objects/contacts.cfg cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg cfg_file=/usr/local/nagios/etc/objects/templates.cfg cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

Configure email notifications

Set up email alerts by editing the contacts configuration file.

define contact {
    contact_name                    nagiosadmin
    use                            generic-contact
    alias                          Nagios Admin
    email                          admin@example.com
    service_notification_period    24x7
    host_notification_period       24x7
    service_notification_options   w,u,c,r,f,s
    host_notification_options      d,u,r,f,s
    service_notification_commands  notify-service-by-email
    host_notification_commands     notify-host-by-email
}

define contactgroup {
    contactgroup_name       admins
    alias                   Nagios Administrators
    members                 nagiosadmin
}

Create host monitoring configuration

Configure monitoring for additional servers by creating a hosts configuration file.

define host {
    use                     linux-server
    host_name               web-server-01
    alias                   Web Server 01
    address                 203.0.113.10
    max_check_attempts      3
    check_period           24x7
    notification_interval   30
    notification_period     24x7
    contact_groups          admins
}

define service {
    use                     generic-service
    host_name               web-server-01
    service_description     HTTP
    check_command           check_http
    max_check_attempts      3
    normal_check_interval   5
    retry_check_interval    2
    contact_groups          admins
}

define service {
    use                     generic-service
    host_name               web-server-01
    service_description     SSH
    check_command           check_ssh
    max_check_attempts      3
    normal_check_interval   5
    retry_check_interval    2
    contact_groups          admins
}

Add this file to the main configuration by editing nagios.cfg.

sudo bash -c 'echo "cfg_file=/usr/local/nagios/etc/objects/servers.cfg" >> /usr/local/nagios/etc/nagios.cfg'

Install and configure email system

Install a mail transfer agent to send notification emails.

sudo apt install -y mailutils postfix
sudo dnf install -y mailx postfix
sudo systemctl enable postfix
sudo systemctl start postfix

During postfix installation, select "Internet Site" and enter your domain name.

Start and enable Nagios services

Enable Nagios to start automatically on boot and start the monitoring service.

sudo systemctl enable nagios
sudo systemctl start nagios
sudo systemctl enable apache2
sudo systemctl restart apache2

For Red Hat systems, use httpd instead of apache2.

Configure firewall access

Allow HTTP traffic through firewall

Configure your firewall to allow web traffic to the Nagios interface.

sudo ufw allow 'Apache Full'
sudo ufw reload
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Verify your setup

Check that Nagios is running correctly and accessible through the web interface.

sudo systemctl status nagios
sudo systemctl status apache2
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Open your web browser and navigate to http://your-server-ip/nagios. Log in with the nagiosadmin username and password you created earlier. You should see the Nagios Core dashboard with monitoring status for localhost and any additional hosts you configured.

Common issues

Symptom Cause Fix
Web interface shows "Forbidden" Apache authentication not configured Verify htpasswd.users file exists and Apache config is correct
"Configuration Error" in web interface Syntax error in configuration files Run sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Services show "PENDING" status Nagios hasn't run checks yet Wait 5-10 minutes or restart nagios service
Email notifications not working Mail system not configured Test with echo "test" | mail -s "Test" admin@example.com
Permission denied errors in logs Incorrect file ownership Run sudo chown -R nagios:nagios /usr/local/nagios/

Next steps

Automated install script

Run this to automate the entire setup

#nagios #monitoring #apache #notifications #infrastructure

Need help?

Don't want to manage this yourself?

We handle infrastructure for businesses that depend on uptime. From initial setup to ongoing operations.

Talk to an engineer