更多的主机依此格式逐个追加进来。小技巧,如果是连续的ip段,最好自己写个脚本生成hosts.cfg文件,为了以后维护方便,尽可能在文件中使用易读的注释(如本例# Wangjing IDC servers #)。
再一个重量级的配置文件是services.cfg,没有这个文件,什么监控也没用。下面给出一个样式文件:
#service definition
##############################################################
# Wangjing IDC servers service for host-live #
##############################################################
define service {
host_name nagios-server //来源:hosts.cfg
service_description check-host-alive
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup //来源:contactgroups.cfg
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check-host-alive //检查主机是否存活
}
define service {
host_name 74-210
service_description check_tcp 80
check_period 24x7
max_check_attempts 4
normal_check_interval 3
retry_check_interval 2
contact_groups sagroup
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_tcp!80 //检查tcp 80端口服务是否正常
} |
书写时要注意的是,check_tcp与要监控的服务端口之间要用”!”做分隔符。如果服务太多,以应该考虑用脚本来生成。
主机组配置文件hostgroups.cfg,这是一个可选的项目,它建立在文件hosts之上,其格式如下:
define hostgroup {
hostgroup_name sa-servers
alias sa servers
members nagios-server,24-25,24-26 //用逗号间隔多个主机
} |
多个主机组依上面的格式逐个追加上去。后面给一个主机组的截图。
千辛万苦,终于把这些配置给做好保存,现在几乎有点迫不及待了,运行程序/usr/local/nagios –v /usr/local/nagios/etc/nagios.cfg来检查所有配置文件的正确性。如果十分幸运的话,运行完毕将在输出尾部出现:
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
|
这样的情况,大功告成;但我却没有这么幸运,修改了好多个地方才成功。不过值得庆幸的是,这个校验的错误报告时非常有用的(不象有的系统的帮助文档中看不中用)。看我故意设置的一个错误产生的输出: