Nagios的配置过程

运维 系统运维
Nagios的配置过程:Nagios的功能是监控服务和主机,根据配置在服务器异常的时候提供报警功能,并提供友好的WEB界面查看当前的网络状态、通知和故障历史、日志文件…但是他自身并不包括这部分功能的代码,所有的监控、检测功能都是有插件来完成的。本文讲述的是Nagios的配置过程

  Nagios配置过程:

  nagios的主要配置文件包括

  nagios.cfg //主配置文件

  contacts.cfg //联系人配置文件

  contactgroups.cfg //联系人组配置文件

  commands.cfg //命令配置文件

  host.cfg //主机配置文件

  hostgroups.cfg //服务器组文件

  templates.cfg //模板文件

  timeperiods.cfg //监视时段文件

  services.cfg //服务配置文件

  主配置文件 nagios.cfg 需要更改的地方:

  1.   #cfg_file=/usr/local/nagios/etc/objects/localhost.cfg  
  2.  

  interval_length=1 ; 间隔时间基准由 60s 改为 1s

  command_check_interval=10s ; 命令检查时间间隔,-1 表示尽可能频繁的进行检查

  date_format=iso8601 ; 日期格式

  objects/contacts.cfg 用来定义联系人:

  1.   define contact { contact_name sa alias System Administrator service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email email admin@test.com }  
  2.  

  再定义联系人组

  1.   define contactgroup { contactgroup_name admins alias Administrator Group members sa ; 添加其它联系人用 "," 分隔 }  
  2.  

  主机监控的配置

  1.   define host {  
  2.  
  3.   host_name host_name ; 简短的主机名称。  
  4.  
  5.   alias alias ; 别名,可以更详细的说明主机。  
  6.  
  7.   address address ; IP 地址,也可以写主机名。如果不定义这个值, nagio 将会用 host_name 去寻找主机。  
  8.  
  9.   parents host_names ; 上一节点的名称,也就是指从 nagios 服务器到被监控主机之间经过的节点,可以是路由器、交换机、主机等等。  
  10.  
  11.   hostgroups hostgroup_names ; 简短的主机组名称。  
  12.  
  13.   check_command command_name ; 检查命令的简短名称,如果此项留空, nagios 将不会去判断主机是否 alive 。  
  14.  
  15.   max_check_attempts 整数 ; 当检查命令的返回值不是 "OK" 时,重试的次数。  
  16.  
  17.   check_interval 数字 ; 循环检查的间隔时间。  
  18.  
  19.   active_checks_enabled [0/1] ; 是否启用 "active_checks"  
  20.  
  21.   passive_checks_enabled [0/1] ; 是否启用 "passive_checks" ,及“被动检查”  
  22.  
  23.   check_period timeperiod_name ; 检测时间段简短名称,这只是个名称,具体的时间段要写在其他的配置文件中。  
  24.  
  25.   obsess_over_host [0/1] ; 是否启用主机操作系统探测。  
  26.  
  27.   check_freshness [0/1] ; 是否启用 freshness 检查。freshness 检查是对于启用被动检查模式的主机而言的,其作用是定期检查主机报告的状态信息,如果该状态信息已经过期,freshness 将会强制做主机检查。  
  28.  
  29.   freshness_threshold 数字 ; fressness 的临界值,单位为秒。 如果定义为 "0" ,则为自动定义。  
  30.  
  31.   event_handler command_name ; 当主机发生状态改变时,采用的处理命令的简短的名字(可以在 commands.cfg 中对其定义)  
  32.  
  33.   event_handler_enabled [0/1] ; 是否启用 event_handler  
  34.  
  35.   low_flap_threshold 数字 ; 抖动的下限值。抖动,即在一段时间内,主机(或服务)的状态值频繁的发生变化。  
  36.  
  37.   high_flap_threshold 数字 ; 抖动的上限值。  
  38.  
  39.   flap_detection_enabled [0/1] ; 是否启用抖动检查。  
  40.  
  41.   process_perf_data [0/1] ; 是否启用 processing of performance data  
  42.  
  43.   retain_status_information [0/1] ; 程序重启时,是否保持主机状态相关的信息。  
  44.  
  45.   retain_nonstatus_information [0/1] ; 程序重启时,是否保持主机状态无关的信息。  
  46.  
  47.   contact_groups contact_groups ; 联系人组,在此组中的联系人都会收到主机的提醒信息。  
  48.  
  49.   notification_interval 整数 ; 重复发送提醒信息的最短间隔时间。默认间隔时间是 "60" 分钟。如果这个值设置为 "0" ,将不会发送重复提醒。  
  50.  
  51.   notification_period timeperiod_name ; 发送提醒的时间段。非常重要的主机(服务)定义为 24x7 ,一般的主机(服务)就定义为上班时间。如果不在定义的时间段内,无论发生什么问题,都不会发送提醒。  
  52.  
  53.   notification_options [d,u,r,f] ; 发送提醒包括的情况: d = 状态为 DOWN , u = 状态为 UNREACHABLE , r = 状态恢复为 OK , f = flapping 
  54.  
  55.   notifications_enabled [0/1] ; 是否开启提醒功能。"1" 为开启,"0" 为禁用。一般,这个选项会在主配置文件 (nagios.cfg) 中定义,效果相同。  
  56.  
  57.   stalking_options [o,d,u] ; 持续状态检测参数,o = 持续的 UP 状态 , d = 持续的 DOWN 状态 , u = 持续的 UNREACHABLE 状态  
  58.  
  59.   }  
  60.  

  服务监控的配置

  1.   define contact { contact_name sa alias System Administrator service_notification_period 24x7 host_notification_period 24x7 service_notification_options w,u,c,r host_notification_options d,u,r service_notification_commands notify-service-by-email host_notification_commands notify-host-by-email email admin@test.com }  
  2.  

  服务监控的配置和主机监控的配置较为相似,就不一一说明了。

  间隔时间的计算方法为:

  1.   normal_check_interval x interval_length 秒  
  2.  
  3.   retry_check_interval x interval_length 秒  
  4.  
  5.   notification_interval x interval_length 秒  
  6.  

  主机监控配置的例子

  1.   define host { host_name web1 alias web1 address 192.168.0.101 contact_groups admins check_command check-host-alive max_check_attempts 5 notification_interval 0 notification_period 24x7 notification_options d,u,r }  
  2.  

  对主机 web1 进行 24x7 的监控,默认会每 10 秒检查一次状态,累计五次失败就发送提醒,并且不再重复发送提醒。

  服务监控配置的例子

  1.   define service { host_name web1 service_description check_http check_period 24x7 max_check_attempts 3 normal_check_interval 30 contact_groups admins retry_check_interval 15 notification_interval 3600 notification_period 24x7 notification_options w,u,c,r check_command check_http }  
  2.  

  配置解释: 24x7 监控 web1 主机上的 HTTP 服务,检查间隔为 30 秒, 检查失败后每 15 秒再进行一次检查,累计三次失败就认定是故障并发送提醒。

  联系人组是 admins 。提醒后恢复到 30 秒一次的 normal_check_interval 检查。如果服务仍然没有被恢复,每个小时发送一次提醒。

  如果要检测其他服务,例如,要检查 ssh 服务是否开启,更改如下两行:

  1.   service_description check_ssh  
  2.  
  3.   check_command check_ssh  
  4.  

  为方便管理,对配置文件的分布做了如下修改:

  nagios.cfg 中增加了:

  1.   cfg_dir=/usr/local/nagios/etc/hosts  
  2.  
  3.   cfg_dir=/usr/local/nagios/etc/services  
  4.  

  在 hosts 目录中,为不同类型的主机创建了配置文件,如: app.cfg cache.cfg mysql.cfg web.cfg

  并创建了 hostgroup.cfg 文件对主机进行分组,如:

  1.   define hostgroup { hostgroup_name app-hosts alias APP Hosts members app1,app2 }  
  2.  

  在 services 目录中创建了各种服务的配置文件,如: disk.cfg http.cfg load.cfg mysql.cfg

  并创建了 servicegroup.cfg 文件对服务进行分组,如:

  1.   define servicegroup { servicegroup_name disk alias DISK members cache1,check_disk,cache2,check_disk  

【编辑推荐】

使用nagios监控oracle

启动Nagios服务

配置Nagios监控服务器(图)

责任编辑:zhaolei 来源: CSDN
相关推荐

2011-03-21 09:17:06

Nagios

2011-03-28 12:42:26

nagios

2011-03-28 11:03:09

配置Nagios

2010-05-31 11:10:37

Nagios pnp

2011-03-28 13:57:57

2011-03-25 17:13:37

Nagios配置文件

2011-03-25 17:35:12

SuseNagios

2011-03-31 16:05:18

Redhat配置nagios

2011-08-22 12:25:02

nagios

2011-03-22 13:37:29

Nagios安装

2010-05-31 10:00:14

Nagios安装

2011-11-08 21:58:01

Nagios 配置 流

2011-03-25 10:37:17

2011-03-25 16:49:33

nagios服务

2011-03-23 13:29:46

配置Nagios系统

2010-05-31 10:22:31

Nagios pnp

2011-03-28 15:22:00

nagios

2011-03-23 15:13:08

Nagios配置文件

2011-03-24 13:00:30

2010-05-31 12:22:13

Nagios pnp
点赞
收藏

51CTO技术栈公众号