在现代IT运维中,对服务器状态进行实时监控至关重要。Nagios 是一款开源、功能强大的网络和系统监控工具,广泛用于 Centos nagios 环境中。本教程将从零开始,详细讲解如何在 CentOS 7/8 系统上安装、配置 Nagios 监控告警系统,即使是运维小白也能轻松上手。
在开始之前,请确保你有一台运行 CentOS 7 或 CentOS 8 的服务器,并具备 root 权限。同时,建议关闭防火墙或开放相应端口(如 80、5666)。
# 关闭防火墙(仅测试环境建议)systemctl stop firewalldsystemctl disable firewalld# 安装基础依赖yum install -y gcc glibc glibc-common wget unzip httpd php gd gd-devel perl postfix
首先,创建一个 nagios 用户和组:
useradd nagiosgroupadd nagcmdusermod -a -G nagcmd nagiosusermod -a -G nagcmd apache
然后下载并编译安装 Nagios 核心:
cd /tmpwget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.13.tar.gztar xzf nagios-*.tar.gzcd nagios-4.4.13./configure --with-command-group=nagcmdmake allmake installmake install-initmake install-configmake install-commandmodemake install-webconf
Nagios 提供基于 Web 的管理界面,我们需要设置一个登录账户:
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
启动 Apache 服务:
systemctl start httpdsystemctl enable httpd
Nagios 核心本身不包含具体的监控脚本,需要通过插件实现对 CPU、内存、磁盘等资源的监控。安装官方插件:
yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils epel-releasewget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.4.2/nagios-plugins-2.4.2.tar.gztar xzf nagios-plugins-*.tar.gzcd nagios-plugins-2.4.2./configure --with-nagios-user=nagios --with-nagios-group=nagiosmakemake install
启动 Nagios 服务:
systemctl start nagiossystemctl enable nagios
现在打开浏览器,访问:http://你的服务器IP/nagios,使用之前设置的用户名 nagiosadmin 和密码登录。
Nagios 默认已监控本机(localhost)。若要添加新主机,编辑配置文件:
vim /usr/local/nagios/etc/servers/your_host.cfg
添加如下内容(以监控另一台 Linux 服务器为例):
define host { use linux-server host_name web-server-01 alias Web Server 01 address 192.168.1.100}define service { use generic-service host_name web-server-01 service_description PING check_command check_ping!100.0,20%!500.0,60%} 保存后,检查配置是否正确:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
无错误即可重启 Nagios 生效:
systemctl restart nagios
通过本教程,你已经成功在 CentOS 系统上部署了 Linux服务器监控 工具 Nagios,并完成了基本的 nagios监控系统 配置。你可以进一步配置邮件告警、短信通知、自定义监控项等高级功能,打造完整的 IT 运维监控体系。
掌握 Centos nagios 不仅能提升你的运维效率,还能在系统出现异常时第一时间收到通知,保障业务连续性。赶快动手试试吧!
本文由主机测评网于2025-12-05发表在主机测评网_免费VPS_免费云服务器_免费独立服务器,如有疑问,请联系我们。
本文链接:https://www.vpshk.cn/2025123122.html