Operations 8 min read

Step‑by‑Step Guide to Installing and Configuring Nagios on CentOS 7

This tutorial walks through preparing a CentOS 7 virtual machine, configuring networking, setting up required packages, compiling and installing Nagios Core, adding the Nagios user and Apache integration, configuring the firewall, and finally installing and enabling Nagios plugins for full monitoring capabilities.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Step‑by‑Step Guide to Installing and Configuring Nagios on CentOS 7

1. Prepare the virtual machine

Create a CentOS 7 VM with 2 CPU cores, 4 GB RAM, NAT networking, LSI Logic SCSI controller and a 50 GB virtual disk. Enable hardware virtualization (Intel VT‑x/EPT or AMD‑V/RVI) in the VM settings.

2. Configure the network interface

vi /etc/sysconfig/network-scripts/ifcfg-ens33

3. Pre‑installation configuration

YUM repository

cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum clean all
yum makecache
yum repolist

Verify external network access

ping www.baidu.com

4. Install Nagios Core (4.4.3)

Disable SELinux

setenforce 0
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
getenforce

Install prerequisite packages

yum install -y gcc glibc glibc-common wget unzip httpd php gd perl postfix

Download and extract the source

cd /tmp
wget -O nagioscore.tar.gz https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.3.tar.gz
tar zxvf nagioscore.tar.gz

Compile and install

cd nagioscore-nagios-4.4.3/
./configure
make all
make install
make install-daemoninit
make install-commandmode
make install-config
make install-webconf

Create Nagios user and group, add Apache user

make install -groups -users
usermod -a -G nagios apache

Configure firewall (allow HTTP port 80)

yum install -y iptables-services
systemctl enable iptables
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
service iptables save
ip6tables -I INPUT -p tcp --dport 80 -j ACCEPT
service ip6tables save

Create web‑interface admin user

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

Start services

service httpd restart
service nagios restart

5. Install Nagios Plugins (2.2.1)

Enable EPEL repository

cd /tmp
wget https://archives.fedoraproject.org/pub/archive/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -ivh epel-release-6-8.noarch.rpm
cd /etc/yum.repos.d/
mv epel.repo epel.repo.backup
mv epel-testing.repo epel-testing.repo.backup
wget -O epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
sed -i 's|^#baseurl=|baseurl=|g' epel.repo
sed -i 's|^metalink|#metalink|g' epel.repo
yum clean all
yum makecache

Install build dependencies

yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils perl-Net-SNMP

Download and extract plugin source

cd /tmp
wget --no-check-certificate -O nagios-plugins.tar.gz https://github.com/nagios-plugins/nagios-plugins/archive/release-2.2.1.tar.gz
tar zxf nagios-plugins.tar.gz

Compile and install plugins

cd nagios-plugins-release-2.2.1/
./tools/setup
./configure
make
make install

Restart services to apply plugins

touch /var/www/html/index.html
service nagios restart
service httpd restart

6. Verify installation

Open a web browser and navigate to http://<em>your‑server</em>/nagios. Log in with the nagiosadmin account created earlier. The Nagios web interface should display the configured services and host status.

Nagios setup diagram
Nagios setup diagram
Nagios web interface
Nagios web interface
Nagios services view
Nagios services view
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

monitoringInstallationSystem AdministrationNagios
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.