您的位置:首页 > 移动开发 > IOS开发

监控软件nagios之配置文件详解

2015-04-01 16:02 555 查看
1.nagios根目录
[root@tong1 nagios-4.0.8]# ll
total 28
drwxrwxr-x. 2 nagios nagios 4096 Apr 1 14:50 bin --二进制文件
drwxrwxr-x. 3 nagios nagios 4096 Apr 1 15:27 etc --配置文件
drwxr-xr-x. 2 root root 4096 Apr 1 15:23 include --包含文件
drwxrwxr-x. 2 nagios nagios 4096 Apr 1 15:23 libexec --插件文件
drwxrwxr-x. 2 nagios nagios 4096 Apr 1 15:03 sbin --cgi文件
drwxrwxr-x. 11 nagios nagios 4096 Apr 1 15:23 share --网页文件和文档
drwxrwxr-x. 5 nagios nagios 4096 Apr 1 15:34 var --锁文件和日志文件
[root@tong1 nagios-4.0.8]#

2.templates.cfg配置文件(定义监控中重复的参数)
[root@tong1 nagios-4.0.8]# cd etc/
[root@tong1 etc]# ll
total 68
-rw-rw-r--. 1 nagios nagios 12027 Apr 1 14:53 cgi.cfg --cgi配置文件
-rw-r--r--. 1 nagios ngios 19 Apr 1 14:52 htpasswd --认证文件
-rw-rw-r--. 1 nagios nagios 44637 Apr 1 14:50 nagios.cfg --主配置文件
drwxrwxr-x. 2 nagios nagios 4096 Apr 1 15:27 objects --主机定义文件
-rw-rw----. 1 nagios nagios 1324 Apr 1 14:50 resource.cfg --资源管理文件
[root@tong1 etc]# ll objects/
total 48
-rw-rw-r--. 1 nagios nagios 7700 Apr 1 14:50 commands.cfg --定义命令文件
-rw-rw-r--. 1 nagios nagios 2138 Apr 1 14:50 contacts.cfg --定义联系人和联系人组
-rw-rw-r--. 1 nagios nagios 5375 Apr 1 14:50 localhost.cfg --本地主机的监控文件
-rw-rw-r--. 1 nagios nagios 3096 Apr 1 14:50 printer.cfg --监控打印文件模板
-rw-rw-r--. 1 nagios nagios 3265 Apr 1 14:50 switch.cfg --监控交换机文件模板
-rw-rw-r--. 1 nagios nagios 10621 Apr 1 14:50 templates.cfg --作为资源引用文件
-rw-rw-r--. 1 nagios nagios 3180 Apr 1 14:50 timeperiods.cfg --定义监控时间段
-rw-rw-r--. 1 nagios nagios 3991 Apr 1 14:50 windows.cfg --监控windows主机模板[root@tong1 etc]# cd objects/
[root@tong1 objects]# vim templates.cfg --此文件是固定的,是所有文件中的相同配置(定义后可以不在其它配置文件中一一定义了)
define contact{
name generic-contact --定义 联系人
service_notification_period 24x7 --服务出现异常通知联系人
host_notification_period 24x7 --主机出现异常通知联系人
service_notification_options w,u,c,r,f,s --服务器级别,w即warn表示警告状态,u即unknown,表示不明状态,c即criticle表示紧急状态,r即recover,表示恢复态
host_notification_options d,u,r,f,s --主机故障级别
service_notification_commands notify-service-by-email --服务发现故障用邮件报警(notify-service-by-email在commands.cfg文件中定义)
host_notification_commands notify-host-by-email --主机发现故障用邮件报警
register 0
}
define host{
name generic-host --主机名,不是真实主机名,是在nagios页面显示的主机名
notifications_enabled 1
event_handler_enabled 1
flap_detection_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
notification_period 24x7
register 0
}
define host{
name linux-server --监控linux主机
use generic-host --引用其它主机的配置
check_period 24x7 --监控主机的时间段
check_interval 5 --检查时间间隔
retry_interval 1 --重试检查时间间隔
max_check_attempts 10 --检查多少次才认为是宕机
check_command check-host-alive --检查主机状态的命令(check-host-alive在commands.cfg文件中定义)
notification_period 24X7 --主机故障时报警时间
notification_interval 120 --当主机一直故障每隔120分钟发送一次报警
notification_options d,u,r --定义主机在什么状态时被定为宕机
contact_groups admins --指定联系人组
register 0
}
define host{
name windows-server --监控windows主机
use generic-host
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,r
contact_groups admins
hostgroups windows-servers
register 0
}
define host{
name generic-printer --监控打印
use generic-host
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period workhours
notification_interval 30
notification_options d,r
contact_groups admins
register 0
}
define host{
name generic-switch --监控交换机
use generic-host
check_period 24x7
check_interval 5
retry_interval 1
max_check_attempts 10
check_command check-host-alive
notification_period 24x7
notification_interval 30
notification_options d,r
contact_groups admins
register 0
}
define service{
name generic-service --监控服务
active_checks_enabled 1
passive_checks_enabled 1
parallelize_check 1
obsess_over_service 1
check_freshness 0
notifications_enabled 1
event_handler_enabled 1
flap_detection_enabled 1
process_perf_data 1
retain_status_information 1
retain_nonstatus_information 1
is_volatile 0
check_period 24x7
max_check_attempts 3
normal_check_interval 10
retry_check_interval 2
contact_groups admins
notification_options w,u,c,r
notification_interval 60
notification_period 24x7
register 0
}

3.resource.cfg配置文件(变量定义文件)
[root@tong1 objects]# vim ../resource.cfg
$USER1$=/usr/local/nagios-4.0.8/libexec --插件的路径

4.commands.cfg配置文件(加入新的监控命令)
[root@tong1 objects]# vim commands.cfg
define command{
command_name check_local_disk --定义命令名
command_line $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$ --监控脚本
}

5.host.cfg配置文件(默认不存在,被监控主机地址和信息)
[root@tong1 objects]# vim host.cfg
define host {

use linux-server #引用主机linux-server的属性信息,linux-server主机在templates.cfg文件中进行了定义.
host_name Nagios-Linux #主机名

alias Nagios-Linux #主机别名

address 192.168.1.111 #被监控的主机地址,这个地址可以是ip,也可以是域名.
}
#定义一个主机组
define hostgroup {

hostgroup_name bsmart-servers #主机组名称,可以随意指定.

alias bsmart servers #主机组别名

members Nagios-Linux #主机组成员,其中“Nagios-Linux”就是上面定义的主机
}

6.services.cfg配置文件(默认不存在,主要定义主机资源和服务)
[root@tong1 objects]# vim services.cfg
define service {

use local-service #引用local-service服务的属性值,local-service在templates.cfg文件中进行了定义.

host_name Nagios-Linux #指定要监控哪个主机上的服务,“Nagios-Server”在hosts.cfg文件中进行了定义.
service_description check-host-alive #对监控服务内容的描述,以供维护人员参考.

check_command check-host-alive #指定检查的命令.
}

7.contacts.cfg配置文件(定义联系人和联系组)
[root@tong1 objects]# vim contacts.cfg
define contact {
contact_name David #联系人的名称,这个地方不要有空格
use generic-contact #引用generic-contact的属性信息,其中“generic-contact”在templates.cfg文件中进行定义
alias Nagios Admin
email david.tang@bsmart.cn
}
define contactgroup{
contactgroup_name ts #联系人组的名称,同样不能空格
alias Technical Support #联系人组描述
members David #联系人组成员,其中“david”就是上面定义的联系人,如果有多个联系人则以逗号相隔
}

8.timeperiods.cfg配置文件(定义监控时间段)
[root@tong1 objects]# vim timeperiods.cfg
define timeperiod{
timeperiod_name 24x7
alias 24 Hours A Day, 7 Days A Week
sunday 00:00-24:00
monday 00:00-24:00
tuesday 00:00-24:00
wednesday 00:00-24:00
thursday 00:00-24:00
friday 00:00-24:00
saturday 00:00-24:00
}

# 'workhours' timeperiod definition
define timeperiod{
timeperiod_name workhours
alias Normal Work Hours
monday 09:00-17:00
tuesday 09:00-17:00
wednesday 09:00-17:00
thursday 09:00-17:00
friday 09:00-17:00
}

9.nagios.cfg配置文件(核心配置文件,所有的配置文件必须要在这个配置文件中引用进来)
[root@tong1 objects]# vim ../nagios.cfg
cfg_file=/usr/local/nagios-4.0.8/etc/objects/commands.cfg
cfg_file=/usr/local/nagios-4.0.8/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios-4.0.8/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios-4.0.8/etc/objects/templates.cfg

10.检查配置文件是否有异常
[root@tong1 objects]# /usr/local/nagios-4.0.8/bin/nagios -v /usr/local/nagios-4.0.8/etc/objects/localhost.cfg

本文出自 “一起走过的日子” 博客,请务必保留此出处http://tongcheng.blog.51cto.com/6214144/1627349
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: