[root@www ~]# vim /etc/nagios/conf.d/192.168.1.251.cfg
......
#check_nrpe
define service{
use generic-service
host_name 192.168.1.251
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 192.168.1.251
service_description check_disk_sda1
check_command check_nrpe!check_hda1 #check_nrpe为前面自定义的模块名称,check_hda1为被监控主机/etc/nagios/nrpe.cfg文件里定义的脚本名称
max_check_attempts 5
normal_check_interval 1
}
#define service{ #可以添加多块磁盘监控
# use generic-service
# host_name 192.168.1.251
# service_description check_disk_hda2
# check_command check_nrpe!check_hda2
# max_check_attempts 5
# normal_check_interval 1
#}[root@www ~]# nagios -v /etc/nagios/nagios.cfg
.......
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
3、被监控主机通过nrpe.cfg文件定义的脚本命令
[root@sh ~]# vim /etc/nagios/nrpe.cfg
# The following examples use hardcoded command arguments...
command[check_users]=/usr/lib64/nagios/plugins/check_users -w 5 -c 10
command[check_load]=/usr/lib64/nagios/plugins/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1
#command[check_hda2]=/usr/lib64/nagios/plugins/check_disk -w 20% -c 10% -p /dev/hda2
command[check_zombie_procs]=/usr/lib64/nagios/plugins/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/lib64/nagios/plugins/check_procs -w 150 -c 200
4、重启服务
[root@www ~]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.[root@sh ~]# /etc/init.d/nrpe restart
Shutting down nrpe: [ OK ]
Starting nrpe: [ OK ] 5、web页面查看结果
6、查看nagios日志文件
[root@www ~]# ls /var/log/nagios/
archives nagios.log objects.cache retention.dat spool status.dat[root@www ~]# cat /var/log/nagios/nagios.log
[1449405095] Nagios 3.5.1 starting... (PID=1319)
[1449405095] Local time is Sun Dec 06 20:31:35 CST 2015
[1449405095] LOG VERSION: 2.0
[1449405095] Finished daemonizing... (New PID=1320)
[1449405217] SERVICE ALERT: localhost;HTTP;WARNING;SOFT;1;HTTP WARNING: HTTP/1.1 403 Forbidden - 5159 bytes in 0.001 second response time
[1449405277] SERVICE ALERT: localhost;HTTP;WARNING;SOFT;2;HTTP WARNING: HTTP/1.1 403 Forbidden - 5159 bytes in 0.001 second response time
[1449405337] SERVICE ALERT: localhost;HTTP;WARNING;SOFT;3;HTTP WARNING: HTTP/1.1 403 Forbidden - 5159 bytes in 0.001 second response time
[1449405397] SERVICE ALERT: localhost;HTTP;WARNING;HARD;4;HTTP WARNING: HTTP/1.1 403 Forbidden - 5159 bytes in 0.001 second response time
[1449405683] Caught SIGTERM, shutting down...
[1449405683] Successfully shutdown... (PID=1320)
[1449405684] Nagios 3.5.1 starting... (PID=1474)
[1449405684] Local time is Sun Dec 06 20:41:24 CST 2015
[1449405684] LOG VERSION: 2.0
[1449405684] Finished daemonizing... (New PID=1475)
[1449408863] Caught SIGTERM, shutting down...
[1449408863] Successfully shutdown... (PID=1475)
[1449408863] Nagios 3.5.1 starting... (PID=1833)
[1449408863] Local time is Sun Dec 06 21:34:23 CST 2015
[1449408863] LOG VERSION: 2.0
[1449408863] Finished daemonizing... (New PID=1834)
[1449408913] SERVICE ALERT: 192.168.1.251;check_http;CRITICAL;SOFT;1;connect to address 192.168.1.251 and port 80: Connection refused
[1449409033] SERVICE ALERT: 192.168.1.251;check_http;CRITICAL;SOFT;2;connect to address 192.168.1.251 and port 80: Connection refused
[1449409153] SERVICE ALERT: 192.168.1.251;check_http;CRITICAL;SOFT;3;connect to address 192.168.1.251 and port 80: Connection refused
[1449409273] SERVICE ALERT: 192.168.1.251;check_http;CRITICAL;SOFT;4;connect to address 192.168.1.251 and port 80: Connection refused
[1449409393] SERVICE ALERT: 192.168.1.251;check_http;CRITICAL;HARD;5;connect to address 192.168.1.251 and port 80: Connection refused
[1449409393] SERVICE NOTIFICATION: nagiosadmin;192.168.1.251;check_http;CRITICAL;notify-service-by-email;connect to address 192.168.1.251 and port 80: Connection refused
[1449410874] Caught SIGTERM, shutting down...
[1449410874] Successfully shutdown... (PID=1834)
[1449410874] Nagios 3.5.1 starting... (PID=2330)
[1449410874] Local time is Sun Dec 06 22:07:54 CST 2015
[1449410874] LOG VERSION: 2.0
[1449410874] Finished daemonizing... (New PID=2331)
[1449411134] SERVICE ALERT: 192.168.1.251;check_http;OK;HARD;5;HTTP OK: HTTP/1.1 200 OK - 3910 bytes in 0.001 second response time
[1449411134] SERVICE NOTIFICATION: nagiosadmin;192.168.1.251;check_http;OK;notify-service-by-email;HTTP OK: HTTP/1.1 200 OK - 3910 bytes in 0.001 second response time
[1449411714] Caught SIGTERM, shutting down...
[1449411714] Successfully shutdown... (PID=2331)
[1449411714] Nagios 3.5.1 starting... (PID=2614)
[1449411714] Local time is Sun Dec 06 22:21:54 CST 2015
[1449411714] LOG VERSION: 2.0
[1449411714] Finished daemonizing... (New PID=2615)
九、Nagios配置邮件警告
1、增加define contact和define contactgroup配置
[root@www ~]# vim /etc/nagios/objects/contacts.cfg
# We only have one contact in this simple configuration file, so there is
# no need to create more than one contact group.
define contactgroup{
contactgroup_name admins
alias Nagios Administrators
members nagiosadmin
}
# add mail addressee
define contact{
contact_name admin
use generic-contact
alias administrator
email 741616710@qq.com
}
define contact{
contact_name ming
use generic-contact
alias HM
email root@huangmingming.cn
}
define contactgroup{
contactgroup_name common
alias common
members admin,ming
} 2、修改define service,增加相应配置
[root@www ~]# vim /etc/nagios/conf.d/192.168.1.251.cfg define service{
use generic-service
host_name 192.168.1.251
service_description check_http
check_command check_http
max_check_attempts 5
normal_check_interval 1
contact_groups common
notifications_enabled 1
notification_period 24x7
notification_options w,u,c,r
}
[root@www ~]# nagios -v /etc/nagios/nagios.cfg