Nagios Installation Guide
Nagios® and the Nagios logo are trademarks of Nagios Enterprises, LLC. All trademarks and logos are used for representation purposes only. No prior copyright or trademark authorization has been obtained. This content is for educational purposes only.
Nagios is a powerful open-source monitoring system that enables organizations to identify and resolve IT infrastructure problems before they affect critical business processes.
Installation Methods
Linux Installation (Ubuntu/Debian)
Install Nagios Core from Source
# Install prerequisites
sudo apt-get update
sudo apt-get install -y autoconf gcc libc6 make wget unzip apache2 php libapache2-mod-php7.4 libgd-dev
# Install Nagios Core build dependencies
sudo apt-get install -y libmcrypt-dev make libssl-dev bc gawk dc build-essential snmp libnet-snmp-perl gettext
# Download Nagios Core
cd /tmp
wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.14.tar.gz
tar xzf nagioscore.tar.gz
# Compile Nagios Core
cd /tmp/nagioscore-nagios-4.4.14/
sudo ./configure --with-httpd-conf=/etc/apache2/sites-enabled
sudo make all
# Create user and group
sudo make install-groups-users
sudo usermod -a -G nagios www-data
# Install binaries and files
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
sudo make install-config
sudo make install-webconf
# Enable Apache modules
sudo a2enmod rewrite
sudo a2enmod cgi
# Set up Nagios admin user
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
# Start services
sudo systemctl restart apache2
sudo systemctl start nagios
sudo systemctl enable nagios
Install Nagios via Package Manager (Ubuntu)
# Add repository
sudo add-apt-repository ppa:nagios/nagios
sudo apt-get update
# Install Nagios
sudo apt-get install -y nagios4 nagios-plugins-contrib nagios-nrpe-plugin
# Start service
sudo systemctl start nagios4
sudo systemctl enable nagios4
Install on RHEL/CentOS
# Install EPEL repository
sudo yum install -y epel-release
# Install dependencies
sudo yum install -y gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix
# Download and compile (similar to Ubuntu process above)
cd /tmp
wget https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.14.tar.gz
tar xzf nagios-4.4.14.tar.gz
cd nagioscore-nagios-4.4.14/
sudo ./configure
sudo make all
sudo make install-groups-users
sudo usermod -a -G nagios apache
sudo make install
sudo make install-init
sudo make install-commandmode
sudo make install-config
sudo make install-webconf
# Set SELinux permissions
sudo chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
sudo chcon -R -t httpd_sys_rw_content_t /usr/local/nagios/var/
# Start services
sudo systemctl start nagios
sudo systemctl enable nagios
sudo systemctl restart httpd
Docker Installation
# Pull Nagios Docker image
docker pull jasonrivers/nagios:latest
# Run Nagios container
docker run -d --name nagios4 \
-p 8080:80 \
-v /path/to/nagios/etc:/opt/nagios/etc \
-v /path/to/nagios/var:/opt/nagios/var \
-v /path/to/custom-plugins:/opt/Custom-Nagios-Plugins \
-e NAGIOSADMIN_USER=nagiosadmin \
-e NAGIOSADMIN_PASS=nagiospassword \
jasonrivers/nagios:latest
# Access at http://localhost:8080/nagios
Windows Installation (Using NSClient++)
# Download NSClient++ (Nagios agent for Windows)
# Visit https://nsclient.org/download/ and download the latest version
# Install NSClient++ silently
msiexec /i NSCP-0.5.2.35-x64.msi /quiet
# Configure NSClient++ for Nagios server
# Edit C:\Program Files\NSClient++\nsclient.ini
# Start NSClient++ service
Start-Service nscp
# Set to start automatically
Set-Service -Name nscp -StartupType Automatic
Install Nagios Plugins
# Download Nagios Plugins
cd /tmp
wget https://github.com/nagios-plugins/nagios-plugins/archive/release-2.4.6.tar.gz
tar xzf release-2.4.6.tar.gz
cd nagios-plugins-release-2.4.6/
# Compile and install
sudo ./tools/setup
sudo ./configure
sudo make
sudo make install
Configuration
Main Configuration File
Edit /usr/local/nagios/etc/nagios.cfg:
# Main Nagios configuration
log_file=/usr/local/nagios/var/nagios.log
cfg_dir=/usr/local/nagios/etc/objects
cfg_dir=/usr/local/nagios/etc/servers
object_cache_file=/usr/local/nagios/var/objects.cache
precached_object_file=/usr/local/nagios/var/objects.precache
resource_file=/usr/local/nagios/etc/resource.cfg
status_file=/usr/local/nagios/var/status.dat
status_update_interval=10
nagios_user=nagios
nagios_group=nagios
check_external_commands=1
command_file=/usr/local/nagios/var/rw/nagios.cmd
Define Hosts
Create /usr/local/nagios/etc/objects/myhost.cfg:
define host {
use linux-server
host_name webserver1
alias Production Web Server
address 192.168.1.100
max_check_attempts 5
check_period 24x7
notification_interval 30
notification_period 24x7
}
define service {
use generic-service
host_name webserver1
service_description HTTP
check_command check_http
notifications_enabled 1
}
define service {
use generic-service
host_name webserver1
service_description SSH
check_command check_ssh
notifications_enabled 1
}
Configure Notifications
Edit /usr/local/nagios/etc/objects/contacts.cfg:
define contact {
contact_name admin
alias Nagios Admin
service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email admin@example.com
}
define contactgroup {
contactgroup_name admins
alias Nagios Administrators
members admin
}
NRPE Configuration (Remote Monitoring)
Install NRPE on monitored hosts:
# On Ubuntu/Debian
sudo apt-get install -y nagios-nrpe-server nagios-plugins
# Configure NRPE
sudo nano /etc/nagios/nrpe.cfg
NRPE configuration:
# Allow Nagios server IP
allowed_hosts=127.0.0.1,192.168.1.10
# Define commands
command[check_users]=/usr/lib/nagios/plugins/check_users -w 5 -c 10
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 /
command[check_procs]=/usr/lib/nagios/plugins/check_procs -w 250 -c 400
Restart NRPE:
sudo systemctl restart nagios-nrpe-server
Verification
# Verify Nagios configuration
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# Check Nagios status
sudo systemctl status nagios
# Test plugin execution
/usr/local/nagios/libexec/check_http -H localhost
# Access Web Interface
# Navigate to: http://your-server-ip/nagios
# Login with nagiosadmin credentials
Advanced Configuration
Performance Data and Graphing (PNP4Nagios)
# Install PNP4Nagios for performance graphing
sudo apt-get install -y pnp4nagios
# Enable performance data processing
sudo nano /usr/local/nagios/etc/nagios.cfg
Add these lines:
process_performance_data=1
service_perfdata_command=process-service-perfdata
host_perfdata_command=process-host-perfdata
Monitoring MySQL
# Install MySQL plugin
sudo apt-get install -y nagios-plugins-mysql
# Create MySQL monitoring user
mysql -u root -p
CREATE USER 'nagios'@'localhost' IDENTIFIED BY 'password';
GRANT REPLICATION CLIENT ON *.* TO 'nagios'@'localhost';
FLUSH PRIVILEGES;
Define service:
define service {
use generic-service
host_name dbserver
service_description MySQL
check_command check_mysql!nagios!password
}
API Monitoring
# Monitor REST APIs
/usr/local/nagios/libexec/check_http -H api.example.com \
-u /api/health \
-s "status\":\"healthy" \
-w 2 -c 5
Troubleshooting
Common Issues
Nagios won't start:
# Check configuration
sudo /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
# Check logs
sudo tail -f /usr/local/nagios/var/nagios.log
Web interface not accessible:
# Check Apache configuration
sudo apache2ctl configtest
# Restart Apache
sudo systemctl restart apache2
# Check permissions
sudo chown -R nagios:nagios /usr/local/nagios
Plugins not working:
# Verify plugin path
ls -la /usr/local/nagios/libexec/
# Test plugin manually
sudo -u nagios /usr/local/nagios/libexec/check_ping -H 8.8.8.8 -w 100,20% -c 500,60%
Best Practices
- Organize Configuration Files: Use separate directories for different host groups
- Set Realistic Thresholds: Avoid alert fatigue with appropriate warning/critical levels
- Use Templates: Create host and service templates for consistency
- Enable Notifications: Configure email, SMS, or Slack notifications
- Monitor Nagios Itself: Set up self-monitoring checks
- Regular Backups: Backup
/usr/local/nagios/etc/directory - Performance Tuning: Adjust check intervals based on infrastructure size
- Documentation: Maintain a runbook for common alerts
- Security: Use HTTPS, restrict web interface access, keep plugins updated
- Distributed Monitoring: Use NRPE for remote host monitoring
Integration with Modern Tools
Nagios + Grafana
# Use Nagios data in Grafana
# Install Grafana Nagios datasource plugin
grafana-cli plugins install ibm-apm-datasource
Nagios + PagerDuty
Configure PagerDuty integration in contacts.cfg:
define contact {
contact_name pagerduty
alias PagerDuty
service_notification_commands notify-service-by-pagerduty
host_notification_commands notify-host-by-pagerduty
}
Resources
- Official Documentation: https://www.nagios.org/documentation/
- Nagios Exchange: https://exchange.nagios.org/ (plugins and addons)
- Community Forums: https://support.nagios.com/forum/
- GitHub: https://github.com/NagiosEnterprises/nagioscore
Note: Nagios provides robust monitoring capabilities but requires manual configuration. For more automated, cloud-native monitoring, consider complementing with tools like Prometheus or Datadog.