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 nagios
sudo passwd nagios # 设置nagios用户的密码
sudo groupadd nagios
sudo usermod -a -G nagios nagios4. 下载并安装Nagios Core
Nagios Core现在是Nagios Core Services Platform (CSP)的一部分,我们使用预编译版本简化安装:
# 创建下载目录
cd /tmp
wget https://assets./downloads/nagioscore/releases/nagios-4.4.6.tar.gz
# 解压安装包
tar xvfz nagios-4.4.6.tar.gz
cd nagios-4.4.6
# 编译安装
sudo ./configure --with-command-group=nagios
sudo make all
sudo make install
sudo make install-commandmode
sudo make install-config
sudo make install-init
sudo make install-daemoninit5. 安装Nagios Plugins
Nagios Plugins是Nagios功能的核心扩展:
cd /tmp
wget https:///download/nagios-plugins-2.2.1.tar.gz
tar xvfz nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1
sudo ./configure --with-nagios-user=nagios --with-nagios-group=nagios
sudo make
sudo make install6. 配置Apache
Nagios的Web界面需要Apache支持:
# 在nagios目录下
sudo cp sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
sudo systemctl enable httpd
sudo systemctl start httpd7. 配置Nagios
编辑Nagios配置文件,设置管理员联系信息:
sudo vi /usr/local/nagios/etc/objects/contacts.cfg找到email行,替换为您的电子邮件地址:
email [email protected]8. 启动Nagios服务
sudo systemctl enable nagios
sudo systemctl start nagios9. 设置开机自启
sudo systemctl enable httpd
sudo 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
}