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.
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-ens333. 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 repolistVerify external network access
ping www.baidu.com4. Install Nagios Core (4.4.3)
Disable SELinux
setenforce 0
sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config
getenforceInstall prerequisite packages
yum install -y gcc glibc glibc-common wget unzip httpd php gd perl postfixDownload 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.gzCompile and install
cd nagioscore-nagios-4.4.3/
./configure
make all
make install
make install-daemoninit
make install-commandmode
make install-config
make install-webconfCreate Nagios user and group, add Apache user
make install -groups -users
usermod -a -G nagios apacheConfigure 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 saveCreate web‑interface admin user
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadminStart services
service httpd restart
service nagios restart5. 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 makecacheInstall build dependencies
yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils perl-Net-SNMPDownload 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.gzCompile and install plugins
cd nagios-plugins-release-2.2.1/
./tools/setup
./configure
make
make installRestart services to apply plugins
touch /var/www/html/index.html
service nagios restart
service httpd restart6. 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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
