Command Palette

Search for a command to run...

Nagios Installation Guide

A comprehensive guide for installing and configuring Nagios monitoring system

Nagios is an industry standard open-source monitoring system that watches hosts and services, alerting users when things go wrong and again when they get better.

Prerequisites

  • A system running Linux (preferably Ubuntu/CentOS)
  • Administrative/sudo privileges
  • Terminal access
  • LAMP stack (Linux, Apache, MySQL, PHP)
  • Development tools and compilers
  • Internet connection for downloading packages

Installation Instructions

Ubuntu/Debian Installation

# Install required dependencies
sudo apt update
sudo apt install -y apache2 php php-gd libapache2-mod-php mysql-server php-mysql \
  build-essential libgd-dev unzip apache2-utils
 
# Create Nagios user and group
sudo useradd nagios
sudo usermod -a -G nagios www-data
 
# Download Nagios Core
cd /tmp
wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.9.tar.gz
tar xzf nagios-*.tar.gz
cd nagioscore-nagios-*
 
# Compile and install Nagios
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
sudo make all
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
sudo make install-config
sudo make install-webconf
 
# Create nagiosadmin user
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
 
# Install Nagios Plugins
cd /tmp
wget https://github.com/nagios-plugins/nagios-plugins/archive/release-2.4.2.tar.gz
tar xzf release-2.4.2.tar.gz
cd nagios-plugins-release-2.4.2
sudo ./tools/setup
sudo ./configure
sudo make
sudo make install
 
# Configure Apache
sudo a2enmod rewrite
sudo a2enmod cgi
 
# Start services
sudo systemctl restart apache2
sudo systemctl start nagios
sudo systemctl enable nagios

Post-Installation Configuration

Basic Configuration Files

  1. Main Configuration (nagios.cfg):
# Main configuration file
log_file=/usr/local/nagios/var/nagios.log
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
  1. Resource Configuration (resource.cfg):
# User-defined macros
$USER1$=/usr/local/nagios/libexec
$USER2$=/usr/local/nagios/etc
  1. Contacts Configuration (contacts.cfg):
define contact {
    contact_name            nagiosadmin
    use                    generic-contact
    alias                  Nagios Admin
    email                  your-email@domain.com
}
 
define contactgroup {
    contactgroup_name      admins
    alias                  Nagios Administrators
    members               nagiosadmin
}

Adding Monitored Hosts

Create a new host configuration file (hosts.cfg):

define host {
    use                    linux-server
    host_name              remote-server
    alias                  Remote Linux Server
    address                192.168.1.100
    max_check_attempts     5
    check_period          24x7
    notification_interval  30
    notification_period    24x7
    notification_options   d,u,r
    contact_groups         admins
}
 
define service {
    use                    generic-service
    host_name              remote-server
    service_description    CPU Load
    check_command         check_nrpe!check_load
    notifications_enabled  1
}

Verification

  1. Verify configuration syntax:
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  1. Access web interface:
http://localhost/nagios/
  1. Check service status:
sudo systemctl status nagios

Common Configuration Options

Setting Up Email Notifications

  1. Install mail server:
# For Ubuntu/Debian
sudo apt-get install postfix mailutils
 
# For CentOS/RHEL
sudo yum install postfix mailx
  1. Configure email command in commands.cfg:
define command {
    command_name    notify-by-email
    command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

Adding NRPE for Remote Monitoring

  1. Install NRPE on monitored host:
# Ubuntu/Debian
sudo apt install nagios-nrpe-server nagios-plugins
 
# CentOS/RHEL
sudo yum install nrpe nagios-plugins-all
  1. Configure NRPE (nrpe.cfg):
allowed_hosts=127.0.0.1,<nagios-server-ip>
command[check_load]=/usr/lib/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_disk]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /

Troubleshooting

Common Issues

  1. Web Interface Not Accessible

    • Check Apache configuration
    • Verify permissions
    • Check firewall settings
    • Validate authentication settings
  2. Service Checks Failing

    • Verify plugin permissions
    • Check command definitions
    • Validate host connectivity
    • Review service configuration
  3. Email Notifications Not Working

    • Check mail server configuration
    • Verify contact settings
    • Test mail delivery manually
    • Check notification commands

Security Considerations

  1. Change default password immediately
  2. Use HTTPS for web interface
  3. Implement access control lists
  4. Regular security updates
  5. Monitor log files
  6. Use secure passwords
  7. Configure firewall rules
  8. Implement SSL/TLS for remote monitoring

Additional Resources