Step-by-step Guide to Installing Nagios on CentOS 7 for Reliable System Monitoring
Efficient system monitoring is crucial for maintaining the health of any IT infrastructure. Installing Nagios on CentOS 7 empowers administrators with robust alerting and real-time visibility into server performance and network health, helping prevent downtime before it escalates.
Many administrators overcomplicate their monitoring setup or rely on bloated tools. This guide cuts through the noise by showing a lean, focused approach to installing Nagios — the widely respected open-source monitoring system — on CentOS 7. By the end, you’ll have a clean, functional Nagios installation providing precise insights without unnecessary overhead.
Why Nagios?
Nagios is a veteran monitoring solution known for its flexibility and powerful alerting capabilities. It monitors hosts, services, network devices, and more — raising alerts on downtime or performance issues so you can act before problems impact users.
Prerequisites
Before we get started:
- You should be logged in as a user with
sudo
privileges. - Your system should be CentOS 7 installed and updated.
- Basic familiarity with command-line interface.
Step 1: Update Your System
Make sure your OS is up to date:
sudo yum update -y
Step 2: Install Required Dependencies
Nagios needs some packages to compile from source and run properly.
sudo yum install -y gcc httpd php wget unzip vim perl-Net-SNMP
sudo yum install -y gd gd-devel fontconfig-devel freetype-devel
Enable and start Apache web server (Nagios’ web GUI relies on it):
sudo systemctl enable httpd.service
sudo systemctl start httpd.service
Firewall: If you’re running firewalld, allow HTTP traffic:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --reload
Step 3: Create Nagios User and Group
Create a nagios
user and group which will own Nagios processes:
sudo useradd nagios
sudo groupadd nagcmd
sudo usermod -a -G nagcmd nagios
sudo usermod -a -G nagcmd apache
Step 4: Download Nagios Core Source Files
Head to the Nagios download page for the latest stable version or use wget to grab it directly.
For example, as of this writing:
cd /tmp
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.8.tar.gz
tar zxvf nagios-4.4.8.tar.gz
cd nagios-4.4.8/
Step 5: Compile and Install Nagios
Configure Nagios with appropriate options:
./configure --with-command-group=nagcmd
Compile source code:
make all
Install binaries, init script, sample config files, and set permissions:
sudo make install
sudo make install-commandmode
sudo make install-config
sudo make install-init
Install Apache config for Nagios web interface:
sudo make install-webconf
Step 6: Configure Apache for Nagios
Enable Apache CGI module for plugin execution:
sudo sed -i 's/^#\(cgi_module.*\)/\1/' /etc/httpd/conf.modules.d/00-mpm.conf || true # Just in case CGI module is not enabled; if missing check mods-enabled dir.
Create an admin user to access the Nagios web interface (set your own password):
sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
Reload Apache to apply changes:
sudo systemctl restart httpd.service
Step 7: Install Nagios Plugins
Nagios plugins perform actual checks (CPU load, disk usage, etc.). Download plugins separately from nagios-plugins.
Example:
cd /tmp/
wget https://nagios-plugins.org/download/nagios-plugins-2.3.3.tar.gz
tar zxvf nagios-plugins-2.3.3.tar.gz
cd nagios-plugins-2.3.3/
./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
make
sudo make install
Step 8: Start and Enable Nagios Service
Enable and start Nagios daemon:
sudo systemctl enable nagios.service
sudo systemctl start nagios.service
Verify service status:
systemctl status nagios.service
Step 9: Access the Nagios Web Interface
Open your browser and navigate to:
http://<Your_Server_IP>/nagios/
Log in with username nagiosadmin
(or what you created) and the password you set earlier.
You should see a basic overview of your monitored hosts (initially just localhost), services, performance data, etc.
Additional Tips & Next Steps
-
Add Hosts/Services: Edit
/usr/local/nagios/etc/objects/localhost.cfg
or create new config files under/usr/local/nagios/etc/objects/
defining hosts/services you want to monitor. -
Restart Nagios after config changes:
sudo systemctl restart nagios.service
-
Configure notifications via email by editing
/usr/local/nagios/etc/contacts.cfg
. -
Secure your installation by enabling SSL on Apache and restricting web access if exposed publicly.
Conclusion
You now have a lean but powerful Nagios setup running on CentOS 7 that provides clear visibility into your server’s state without overwhelming resource overhead or complexity. This foundation lets you expand monitoring by adding hosts and services tailored to your infrastructure — catching issues early so headaches never reach users.
Happy monitoring! If you run into any issues during installation or want tips on configuring specific checks, drop a comment below!