Search for a command to run...
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.
# 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
# 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
# User-defined macros
$USER1$=/usr/local/nagios/libexec
$USER2$=/usr/local/nagios/etc
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
}
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
}
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
http://localhost/nagios/
sudo systemctl status nagios
# For Ubuntu/Debian
sudo apt-get install postfix mailutils
# For CentOS/RHEL
sudo yum install postfix mailx
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$
}
# Ubuntu/Debian
sudo apt install nagios-nrpe-server nagios-plugins
# CentOS/RHEL
sudo yum install nrpe nagios-plugins-all
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 /
Web Interface Not Accessible
Service Checks Failing
Email Notifications Not Working