Nagios是一个监视系统运行状态和网络信息的监视系统。Nagios能监视所指定的本地或远程主机以及服务,同时提供异常通知功能等,Nagios可运行在Linux/Unix平台之上,同时提供一个可选的基于浏览器的WEB界面以方便系统管理人员查看网络状态,各种系统问题,以及日志等等。
Nagios的主要功能特点:
– 监视网络服务 (SMTP, POP3, HTTP, NNTP, PING等)
– 监视主机资源 (进程, 磁盘等)
– 简单的插件设计可以轻松扩展Nagios的监视功能
– 服务等监视的并发处理
– 错误通知功能 (通过email, pager, 或其他用户自定义方法)
– 可指定自定义的事件处理控制器
– 可选的基于浏览器的WEB界面以方便系统管理人员查看网络状态,各种系统问题,以及日志等等
– 可以通过手机查看系统监控信息
Nagios官网 http://www.nagios.org
1. Nagios安装 – 服务端(10.0.2.4)
Centos6默认的yum源里没有nagios相关的rpm包,但是我们可以安装一个epel的扩展源:
yum install -y epel-release
然后安装nagios相关的包
yum install -y httpd nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe
设置登录nagios后台的用户和密码:
htpasswd -c /etc/nagios/passwd nagiosadmin
Nagios主配置文件:
/etc/nagios/nagios.cfg
检测配置文件
nagios -v /etc/nagios/nagios.cfg
2. Nagios安装 – 客户端(10.0.2.5)
在客户端机器上
yum install -y epel-release yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe
编辑 /etc/nagios/nrpe.cfg
找到 allowed_hosts=127.0.0.1 改为 allowed_hosts=127.0.0.1,10.0.2.4 后面的ip为服务端ip
找到 dont_blame_nrpe=0 改为 dont_blame_nrpe=1
3. 监控中心(10.0.2.4)添加被监控主机(10.0.2.5)
cd /etc/nagios/conf.d/
新建 10.0.2.4.cfg 加入
define host{
use linux-server
host_name 10.0.2.5
alias 0.12
address 10.0.2.5
}
define service{
use generic-service
host_name 10.0.2.5
service_description check_ping
check_command check_ping!100.0,20%!200.0,50%
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 10.0.2.5
service_description check_ssh
check_command check_ssh
max_check_attempts 5
normal_check_interval 1
notification_interval
}
define service{
use generic-service
host_name 10.0.2.5
service_description check_http
check_command check_http
max_check_attempts 5
normal_check_interval 1
}
配置说明:
max_check_attempts 5 // 当nagios检测到问题时,一共尝试检测5次都有问题才会告警,如果该数值为1,那么检测到问题立即告警
normal_check_interval 1 // 重新检测的时间间隔,单位是分钟,默认是3分钟
notification_interval 60 // 在服务出现异常后,故障一直没有解决,nagios再次对使用者发出通知的时间。单位是分钟。如果你认为,所有的事件只需要一次通知就够了,可以把这里的选项设为0。
以上服务不依赖于客户端nrpe服务,我们可以想象,我们在自己电脑上可以使用ping或者telnet探测远程任何一台机器是否存活、是否开启某个端口或服务。 而当我们想要检测客户端上的某个具体服务的情况时,就需要借助于nrpe了,比如想知道客户端机器的负责或磁盘使用情况。
4. 继续添加服务
在服务端
vim /etc/nagios/objects/commands.cfg
增加:
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
继续编辑
vim /etc/nagios/conf.d/10.0.2.5.cfg
增加如下内容:
define service{
use generic-service
host_name 10.0.2.5
service_description check_load
check_command check_nrpe!check_load
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 10.0.2.5
service_description check_disk_sda1
check_command check_nrpe!check_sda1
max_check_attempts 5
normal_check_interval 1
}
说明:
check_nrpe!check_load 这里的check_nrpe就是在commands.cfg刚刚定义的,check_load是远程主机上的一个检测脚本
编辑被控端 /etc/nagios/nrpe.cfg 搜索 check_hda1
把check_hda1 更改为 /dev/sda1
客户端上启动nrpe服务:
service nrpe restart
服务端启动:
service nagios start service httpd start service nrpe start
测试nrpe服务是否正常通信
在主控制端执行
/usr/lib64/nagios/plugins/check_nrpe -H 10.0.2.5
正常情况下会显示nrpe版本号,如果不成功可以先把SELinux和iptables暂时关闭掉
如果显示
CHECK_NRPE: Error - Could not complete SSL handshake.
需要安装openssl-devel
分别在主控制端和被控制端安装
yum install oepnssl-devel
浏览器访问:
http://ip/nagios
5. 配置告警
在主控制端编辑 /etc/nagios/objects/contacts.cfg 增加
define contact{
contact_name xiaoming
use generic-contact
alias xm
email [email protected]
}
define contact{
contact_name xiaohong
use generic-contact
alias xh
email [email protected]
}
define contactgroup{
contactgroup_name it
alias it
members xiaoming,xiaohong
}
配置说明:
contactgroup_name // 定义名为it的联系人组
members // 组员包括 xiaoming和xiaohong
email // 接受告警信息的邮箱
然后在要需要告警的服务里面加上contactgroup
define service{
use generic-service
host_name 10.0.2.5
service_description check_load
check_command check_nrpe!check_load
max_check_attempts 5
normal_check_interval 1
contact_groups it
notifications_enabled 1
notification_period 24x7
notification_options w,u,c,r
}
配置说明:
notifications_enabled 1 // 是否开启提醒功能。1为开启,0为禁用。一般,这个选项会在主配置文件(nagios.cfg)中定义,效果相同。
notification_period 24x7 // 发送提醒的时间段。非常重要的主机(服务)我定义为7×24,一般的主机(服务)就定义为上班时间。如果不在定义的时间段内,无论什么问题发生,都不会发送提醒。
notification_options w,u,c,r // 这个是service的状态。w为waning, u为unknown, c为critical, r为recover(恢复了),类似的还有一个 host对应的状态:d = 状态为DOWN, u = 状态为UNREACHABLE , r = 状态恢复为OK , f = flapping。,n=不发送提醒。
contact_groups: 定义接受提醒的联系人组,如果hosts.cfg文件中所有的条件都符合,那么提醒任务将会继续检查contactgroup.cfg文件。
Leave a Reply
You must be logged in to post a comment.