Nagios Core简介
Nagios Core是全球最受欢迎的开源监控解决方案,被超过100万用户信赖。它能全面监控您的整个IT基础设施环境——包括网站、DNS、服务器、路由器、交换机、服务、工作站等。Nagios Core不仅能够监控网络服务(如SMTP、POP3、HTTP、NNTP、PING等),还能监控主机资源(处理器负载、磁盘使用、系统日志等),并提供灵活的联系人通知机制。当系统或服务出现故障时,Nagios会通过电子邮件或短信通知相关人员,让您第一时间了解问题并采取行动。
安装步骤
1. 更新系统
首先,更新系统软件包:
sudo yum update -y2. 安装必要的依赖
Nagios需要一些依赖包,包括Apache、PHP和开发工具:
sudo yum install -y httpd php gcc glibc glibc-common gd gd-devel make autoconf wget3. 创建Nagios用户和组
Nagios需要一个专用的用户和组:
sudo useradd nagiossudo passwd nagios # 设置nagios用户的密码sudo groupadd nagiossudo usermod -a -G nagios nagios4. 下载并安装Nagios Core
Nagios Core现在是Nagios Core Services Platform (CSP)的一部分,我们使用预编译版本简化安装:
# 创建下载目录cd /tmpwget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.6.tar.gz# 解压安装包tar xvfz nagios-4.4.6.tar.gzcd nagios-4.4.6# 编译安装sudo ./configure --with-command-group=nagiossudo make allsudo make installsudo make install-commandmodesudo make install-configsudo make install-initsudo make install-daemoninit5. 安装Nagios Plugins
Nagios Plugins是Nagios功能的核心扩展:
cd /tmpwget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gztar xvfz nagios-plugins-2.2.1.tar.gzcd nagios-plugins-2.2.1sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagiossudo makesudo make install6. 配置Apache
Nagios的Web界面需要Apache支持:
# 在nagios目录下sudo cp sample-config/httpd.conf /etc/httpd/conf.d/nagios.confsudo systemctl enable httpdsudo systemctl start httpd7. 配置Nagios
编辑Nagios配置文件,设置管理员联系信息:
sudo vi /usr/local/nagios/etc/objects/contacts.cfg找到email行,替换为您的电子邮件地址:
email yourname@example.com8. 启动Nagios服务
sudo systemctl enable nagiossudo systemctl start nagios9. 设置开机自启
sudo systemctl enable httpdsudo systemctl enable nagios验证安装
打开浏览器,访问http://your-server-ip/nagios,您将看到Nagios的登录界面。使用之前设置的nagios账户和密码登录。
首次登录后,您会看到Nagios的仪表盘,显示当前监控状态。默认情况下,Nagios会监控本地主机的基本服务(如HTTP、SSH等)。
基本配置
Nagios的核心配置文件位于/usr/local/nagios/etc/目录下:
- nagios.cfg:主配置文件
- objects/:包含主机、服务、联系人等配置
- cgi.cfg:CGI配置文件
要添加新监控项,例如监控一个远程网站,只需编辑/usr/local/nagios/etc/objects/localhost.cfg文件,添加类似以下内容:
define service { use local-service host_name localhost service_description HTTP check_command check_http}
