设为首页 收藏本站
查看: 1237|回复: 0

Nagios的配置文件 ZT

[复制链接]

尚未签到

发表于 2015-9-8 08:19:34 | 显示全部楼层 |阅读模式
    cgi.cfg  # 控制cgi访问的配置文件
  nagios.cfg   # Nagios主配置文件
  resource.cfg  # resource.cfg定义了一些变量,以便被其他文件引用,如$USER1$
  objects   # objects是一个目录,用于定义Nagios对象
  servers  # servers是自己创建的一个目录,Nagios可以加载一个目录下面的所有配置文件(需要在nagios.cfg中配置)
./objects:
commands.cfg  # 命令定义配置文件,里面定义的命令可以被其他文件引用  contacts.cfg   # 联系人和联系人组配置文件
  localhost.cfg  # 监控本地机器的配置文件
  printer.cfg   # 监控打印机的一个事例配置文件(默认未启用)
  switch.cfg   # 监控路由器的一个事例配置文件(默认未启用)
  templates.cfg   # 模板配置文件,在此可以定义模板,在其他文件中引用
  timeperiods.cfg   # 定义监控时间段的配置文件
  windows.cfg # 监控Windows的一个事例配置文件(默认未启用)
  ./servers:
  hostgroup.cfg  # 自己创建的主机群组配置文件
  wiki-l-11.cfg  # 自己创建的监控远程Linux主机的配置文件
  
  配置文件是怎样引用的?

  用nagios主要是监控一台主机的各种信息,包括本机资源以及对外的服务等等.这些在nagios里面都是被定义为一个个的项目(nagios称之为服务,为了与主机提供的服务相区别,我这里用项目这个词),而实现每个监控项目,则需要通过commands.cfg文件中定义的命令。
  为了不必重复定义一些项目,Nagios引入了一个模板配置文件(templates.cfg),将一些共性的属性定义成模板,以便于多次引用。
  我们现在有一个监控项目是监控一台机器的web服务是否正常, 我们需要哪些元素呢?最重要的有下面三点:首先是监控哪台机器,然后是这个监控要用什么命令实现,最后就是出了问题的时候要通知哪个联系人。
  我们首先应该在commands.cfg中定义监控远程服务和资源的命令,以及如何发送邮件的命令。大部分监控远程服务和资源的命令的命令通过/usr/local/nagios/libexec下的脚本实现,如ping命令为check_ping。
  /usr/local/nagios/libexec下的脚本命令的使用发法可以通过-h参数查看,如:
  —————————————————————————————–
  [iyunv@tech ~]# /usr/local/nagios/libexec/check_ping -h
  check_ping v1991 (nagios-plugins 1.4.13)
  Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>
  Copyright (c) 2000-2007 Nagios Plugin Development Team
  <nagiosplug-devel@lists.sourceforge.net>
  Use ping to check connection statistics for a remote host.
  Usage:check_ping -H <host_address> -w <wrta>,<wpl>% -c <crta>,<cpl>%
  [-p packets] [-t timeout] [-4|-6]
  Options:
  -h, &#8211;help
  Print detailed help screen
  -V, &#8211;version
  Print version information
  -4, &#8211;use-ipv4
  Use IPv4 connection
  -6, &#8211;use-ipv6
  Use IPv6 connection
  -H, &#8211;hostname=HOST
  host to ping
  -w, &#8211;warning=THRESHOLD
  warning threshold pair
  -c, &#8211;critical=THRESHOLD
  critical threshold pair
  -p, &#8211;packets=INTEGER
  number of ICMP ECHO packets to send (Default: 5)
  -L, &#8211;link
  show HTML in the plugin output (obsoleted by urlize)
  -t, &#8211;timeout=INTEGER
  Seconds before connection times out (default: 10)
  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
  然后我们在contacts.cfg文件中定义联系人和联系人组,在timeperiods.cfg中定义监控时间段。
  最后我们在服务器监控配置文件中引用前面定义的元素来监控服务器状态。
  =============================================================
  下面引用配置文件中部分配置做说明:
  vi /usr/local/nagios/etc/resource.cfg
  # 定义$USER1$变量,设置插件路径
  $USER1$=/usr/local/nagios/libexec
  vi /usr/local/nagios/etc/objects/commands.cfg
  # 定义check-host-alive命令
  define command{
  command_name  check-host-alive  # 命令名称
  command_line  $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
  }
  # 上面的$USER1$和$HOSTADDRESS$引用自已定义的配置文件。变量不需现定义才能被引用。
  ########################################################################
  #
  # 2008.11.18 add by Stone
  # NRPE COMMAND
  # 自己定义check_nrpe命令,此命令后接必需接一个参数,用于告诉远程服务器上的NRPE daemon需要监控的内容,如check_swap参数为监控远程机器的交换分区。
  ########################################################################
  # &#8216;check_nrpe &#8216; command definition
  define command{
  command_name check_nrpe
  command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
  }
  vi /usr/local/nagios/etc/objects/contacts.cfg
  # 定义联系人
  define contact{
  contact_name  nagiosadmin  ; Short name of user
  use  generic-contact  ; Inherit default values from generic-contact template (defined above)
  alias  Nagios Admin  ; Full name of user
  email  test@gmaile.com  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
  }
  # 上面的generic-contact在templates.cfg中定义。
  # 定义联系人组
  define contactgroup{
  contactgroup_name  admins
  alias  Nagios Administrators
  members  nagiosadmin  #在此可以加入多个联系人,中间用逗号隔开
  }
  
  vi /usr/local/nagios/etc/objects/timeperiods.cfg
  # 定义监控的时间段
  define timeperiod{
  timeperiod_name 24&#215;7  #监控所有时间段(7*24小时)
  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
  }
  
  vi /usr/local/nagios/etc/objects/templates.cfg
  # 定义generic-contact联系人模板,并非真正的联系人,真正的联系人在contacts.cfg中定义
  define contact{
  name  generic-contact  ; The name of this contact template
  service_notification_period  24&#215;7  ; service notifications can be sent anytime
  host_notification_period  24&#215;7 ; host notifications can be sent anytime
  service_notification_options  w,u,c,r,f,s  ; send notifications for all service states, flapping events, and scheduled downtime events
  host_notification_options  d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
  service_notification_commands  notify-service-by-email ; send service notifications via email
  host_notification_commands  notify-host-by-email  ; send host notifications via email
  register  0  ; DONT REGISTER THIS DEFINITION &#8211; ITS NOT A REAL CONTACT, JUST A TEMPLATE!
  }
  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
  service_notification_period  24&#215;7
  服务出了状况通知的时间段,这个时间段就是上面在timeperiods.cfg中定义的.
  
  host_notification_period  24&#215;7
  主机出了状况通知的时间段, 这个时间段就是上面在timeperiods.cfg中定义的
  
  service_notification_options  w,u,c,r
  当服务出现w&#8212;报警(warning),u&#8212;未知(unkown),c&#8212;严重(critical),或者r&#8212;从异常情况恢复正常,在这四种情况下通知联系人.
  
  host_notification_options  d,u,r
  当主机出现d &#8212;当机(down),u&#8212;返回不可达(unreachable),r&#8212;从异常情况恢复正常,在这3种情况下通知联系人
  
  service_notification_commands  notify-service-by-email
  服务出问题通知采用的命令notify-service-by-email,这个命令是在commands.cfg中定义的,作用是给联系人发邮件.
  
  host_notification_commands  notify-host-by-email
  同上,主机出问题时采用的也是发邮件的方式通知联系人
  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
  # 定义generic-host主机模板
  define host{
  name  generic-host  ; The name of this host template
  notifications_enabled  1  ; Host notifications are enabled
  event_handler_enabled  1  ; Host event handler is enabled
  flap_detection_enabled  1  ; Flap detection is enabled
  failure_prediction_enabled  1  ; Failure prediction is enabled
  process_perf_data  1  ; Process performance data
  retain_status_information  1  ; Retain status information across program restarts
  retain_nonstatus_information  1  ; Retain non-status information across program restarts
  notification_period  24&#215;7  ; Send host notifications at any time
  register  0  ; DONT REGISTER THIS DEFINITION &#8211; ITS NOT A REAL HOST, JUST A TEMPLATE!
  }
  # 定义Linux主机模板
  define host{
  name  linux-server  ; The name of this host template
  use  generic-host  ; This template inherits other values from the generic-host template
  check_period  24&#215;7  ; By default, Linux hosts are checked round the clock
  check_interval  5  ; Actively check the host every 5 minutes
  retry_interval  1  ; Schedule host check retries at 1 minute intervals
  max_check_attempts  10  ; Check each Linux host 10 times (max)
  check_command  check-host-alive ; Default command to check Linux hosts
  notification_period  workhours  ; Linux admins hate to be woken up, so we only notify during the day
  ; Note that the notification_period variable is being overridden from
  ; the value that is inherited from the generic-host template!
  notification_interval  120  ; Resend notifications every 2 hours
  notification_options  d,u,r  ; Only send notifications for specific host states
  contact_groups  admins  ; Notifications get sent to the admins by default
  register  0  ; DONT REGISTER THIS DEFINITION &#8211; ITS NOT A REAL HOST, JUST A TEMPLATE!
  }
  # 在nagios.cfg配置文件中开启对/usr/local/nagios/etc/servers/中配置文件的引用。
  cfg_dir=/usr/local/nagios/etc/servers
  # 远程Linux主机监控文件,如果监控多台主机只需简单复制修改即可。
  #我们应该牢记wiki-l-11.cfg用到的命令在commands.cfg中定义,在commands.cfg中定义的命令用到/usr/local/nagios/libexec下的插件(命令)。
  vi /usr/local/nagios/etc/servers/wiki-l-11.cfg
  # 定义主机
  define host{
  use  linux-server  ; Name of host template to use
  ; This host definition will inherit all variables that are defined
  ; in (or inherited by) the linux-server host template definition.
  host_name  wiki
  alias  Docs
  address  192.168.0.11
  }
  # 定义Ping远程Linux主机
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  PING
  check_command  check_ping!100.0,20%!500.0,60%  ;check_ping命令在commands.cfg中定义,后跟两个参数,命令及参数间用!分割。
  }
  #检查远程Linux主机根分区使用情况,check_nrpe命令必须在/usr/local/nagios/etc/objects/commands.cfg中定义(默认未定义)
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  Root Partition
  check_command  check_nrpe!check_disk_root
  }
  # 检查远程Linux主机的登录人数
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  Current Users
  check_command  check_nrpe!check_users
  }
  # 检查远程Linux的主机的负载
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  Current Load
  check_command  check_nrpe!check_load
  }
  # 检查远程Linux主机swap分区使用情况
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  Swap Usage
  check_command  check_nrpe!check_swap
  }
  # 检查远程Linux主机的SSH服务
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  SSH
  check_command  check_ssh
  notifications_enabled  0
  }
  # 检查远程Linux主机的HTTP服务
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  HTTP
  check_command  check_http
  notifications_enabled  0
  }
  vi /usr/local/nagios/etc/servers/hostgroup.cfg
  # 定义主机组(localhost.cfg中有类似的主机组设置,我已将其注释掉,否则可能会有冲突)
  define hostgroup{
  hostgroup_name  linux-servers ; The name of the hostgroup
  alias  Linux Servers ; Long name of the group
  members  localhost,wiki  ; Comma separated list of hosts that belong to this group
  }
  #define hostgroup{
  #  hostgroup_name  windows-servers ; The name of the hostgroup
  #  alias  Windows Servers ; Long name of the group
  #  members  print  ; Comma separated list of hosts that belong to this group
  #  }
  =============================================================
  # 完成监控主机配置文件的配置后使用下面命令检查配置文件的正确性:
  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  # 确定无误后重启Nagios:
  service nagios restart
  =============================================================
  &#9679;check_load的用法及意义
这个插件是用来检测系统当前的cpu负载,使用的方法为
check_load [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15
在unix里面负载的均值通常表示是1分钟,5分钟,15分钟内平均有多少进程处于等待状态.
例如:check_load -w 15,10,5 -c 30,25,20 这个命令的意义如下
当1分钟多于15个进程等待,5分钟多于10个,15分钟多于5个则为warning状态
当1分钟多于30个进程等待,5分钟多于25个,15分钟多于20个则为critical状态

  
  cgi.cfg  # 控制cgi访问的配置文件
  nagios.cfg   # Nagios主配置文件
  resource.cfg  # resource.cfg定义了一些变量,以便被其他文件引用,如$USER1$
  objects   # objects是一个目录,用于定义Nagios对象
  servers  # servers是自己创建的一个目录,Nagios可以加载一个目录下面的所有配置文件(需要在nagios.cfg中配置)
./objects:
commands.cfg  # 命令定义配置文件,里面定义的命令可以被其他文件引用  contacts.cfg   # 联系人和联系人组配置文件
  localhost.cfg  # 监控本地机器的配置文件
  printer.cfg   # 监控打印机的一个事例配置文件(默认未启用)
  switch.cfg   # 监控路由器的一个事例配置文件(默认未启用)
  templates.cfg   # 模板配置文件,在此可以定义模板,在其他文件中引用
  timeperiods.cfg   # 定义监控时间段的配置文件
  windows.cfg # 监控Windows的一个事例配置文件(默认未启用)
  ./servers:
  hostgroup.cfg  # 自己创建的主机群组配置文件
  wiki-l-11.cfg  # 自己创建的监控远程Linux主机的配置文件
  
  配置文件是怎样引用的?

  用nagios主要是监控一台主机的各种信息,包括本机资源以及对外的服务等等.这些在nagios里面都是被定义为一个个的项目(nagios称之为服务,为了与主机提供的服务相区别,我这里用项目这个词),而实现每个监控项目,则需要通过commands.cfg文件中定义的命令。
  为了不必重复定义一些项目,Nagios引入了一个模板配置文件(templates.cfg),将一些共性的属性定义成模板,以便于多次引用。
  我们现在有一个监控项目是监控一台机器的web服务是否正常, 我们需要哪些元素呢?最重要的有下面三点:首先是监控哪台机器,然后是这个监控要用什么命令实现,最后就是出了问题的时候要通知哪个联系人。
  我们首先应该在commands.cfg中定义监控远程服务和资源的命令,以及如何发送邮件的命令。大部分监控远程服务和资源的命令的命令通过/usr/local/nagios/libexec下的脚本实现,如ping命令为check_ping。
  /usr/local/nagios/libexec下的脚本命令的使用发法可以通过-h参数查看,如:
  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
  [iyunv@tech ~]# /usr/local/nagios/libexec/check_ping -h
  check_ping v1991 (nagios-plugins 1.4.13)
  Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>
  Copyright (c) 2000-2007 Nagios Plugin Development Team
  <nagiosplug-devel@lists.sourceforge.net>
  Use ping to check connection statistics for a remote host.
  Usage:check_ping -H <host_address> -w <wrta>,<wpl>% -c <crta>,<cpl>%
  [-p packets] [-t timeout] [-4|-6]
  Options:
  -h, &#8211;help
  Print detailed help screen
  -V, &#8211;version
  Print version information
  -4, &#8211;use-ipv4
  Use IPv4 connection
  -6, &#8211;use-ipv6
  Use IPv6 connection
  -H, &#8211;hostname=HOST
  host to ping
  -w, &#8211;warning=THRESHOLD
  warning threshold pair
  -c, &#8211;critical=THRESHOLD
  critical threshold pair
  -p, &#8211;packets=INTEGER
  number of ICMP ECHO packets to send (Default: 5)
  -L, &#8211;link
  show HTML in the plugin output (obsoleted by urlize)
  -t, &#8211;timeout=INTEGER
  Seconds before connection times out (default: 10)
  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;
  然后我们在contacts.cfg文件中定义联系人和联系人组,在timeperiods.cfg中定义监控时间段。
  最后我们在服务器监控配置文件中引用前面定义的元素来监控服务器状态。
  =============================================================
  下面引用配置文件中部分配置做说明:
  vi /usr/local/nagios/etc/resource.cfg
  # 定义$USER1$变量,设置插件路径
  $USER1$=/usr/local/nagios/libexec
  vi /usr/local/nagios/etc/objects/commands.cfg
  # 定义check-host-alive命令
  define command{
  command_name  check-host-alive  # 命令名称
  command_line  $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
  }
  # 上面的$USER1$和$HOSTADDRESS$引用自已定义的配置文件。变量不需现定义才能被引用。
  ########################################################################
  #
  # 2008.11.18 add by Stone
  # NRPE COMMAND
  # 自己定义check_nrpe命令,此命令后接必需接一个参数,用于告诉远程服务器上的NRPE daemon需要监控的内容,如check_swap参数为监控远程机器的交换分区。
  ########################################################################
  # &#8216;check_nrpe &#8216; command definition
  define command{
  command_name check_nrpe
  command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
  }
  vi /usr/local/nagios/etc/objects/contacts.cfg
  # 定义联系人
  define contact{
  contact_name  nagiosadmin  ; Short name of user
  use  generic-contact  ; Inherit default values from generic-contact template (defined above)
  alias  Nagios Admin  ; Full name of user
  email  test@gmaile.com  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
  }
  # 上面的generic-contact在templates.cfg中定义。
  # 定义联系人组
  define contactgroup{
  contactgroup_name  admins
  alias  Nagios Administrators
  members  nagiosadmin  #在此可以加入多个联系人,中间用逗号隔开
  }
  
  vi /usr/local/nagios/etc/objects/timeperiods.cfg
  # 定义监控的时间段
  define timeperiod{
  timeperiod_name 24&#215;7  #监控所有时间段(7*24小时)
  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
  }
  
  vi /usr/local/nagios/etc/objects/templates.cfg
  # 定义generic-contact联系人模板,并非真正的联系人,真正的联系人在contacts.cfg中定义
  define contact{
  name  generic-contact  ; The name of this contact template
  service_notification_period  24&#215;7  ; service notifications can be sent anytime
  host_notification_period  24&#215;7 ; host notifications can be sent anytime
  service_notification_options  w,u,c,r,f,s  ; send notifications for all service states, flapping events, and scheduled downtime events
  host_notification_options  d,u,r,f,s ; send notifications for all host states, flapping events, and scheduled downtime events
  service_notification_commands  notify-service-by-email ; send service notifications via email
  host_notification_commands  notify-host-by-email  ; send host notifications via email
  register  0  ; DONT REGISTER THIS DEFINITION &#8211; ITS NOT A REAL CONTACT, JUST A TEMPLATE!
  }
  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
  service_notification_period  24&#215;7
  服务出了状况通知的时间段,这个时间段就是上面在timeperiods.cfg中定义的.
  
  host_notification_period  24&#215;7
  主机出了状况通知的时间段, 这个时间段就是上面在timeperiods.cfg中定义的
  
  service_notification_options  w,u,c,r
  当服务出现w&#8212;报警(warning),u&#8212;未知(unkown),c&#8212;严重(critical),或者r&#8212;从异常情况恢复正常,在这四种情况下通知联系人.
  
  host_notification_options  d,u,r
  当主机出现d &#8212;当机(down),u&#8212;返回不可达(unreachable),r&#8212;从异常情况恢复正常,在这3种情况下通知联系人
  
  service_notification_commands  notify-service-by-email
  服务出问题通知采用的命令notify-service-by-email,这个命令是在commands.cfg中定义的,作用是给联系人发邮件.
  
  host_notification_commands  notify-host-by-email
  同上,主机出问题时采用的也是发邮件的方式通知联系人
  &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;
  # 定义generic-host主机模板
  define host{
  name  generic-host  ; The name of this host template
  notifications_enabled  1  ; Host notifications are enabled
  event_handler_enabled  1  ; Host event handler is enabled
  flap_detection_enabled  1  ; Flap detection is enabled
  failure_prediction_enabled  1  ; Failure prediction is enabled
  process_perf_data  1  ; Process performance data
  retain_status_information  1  ; Retain status information across program restarts
  retain_nonstatus_information  1  ; Retain non-status information across program restarts
  notification_period  24&#215;7  ; Send host notifications at any time
  register  0  ; DONT REGISTER THIS DEFINITION &#8211; ITS NOT A REAL HOST, JUST A TEMPLATE!
  }
  # 定义Linux主机模板
  define host{
  name  linux-server  ; The name of this host template
  use  generic-host  ; This template inherits other values from the generic-host template
  check_period  24&#215;7  ; By default, Linux hosts are checked round the clock
  check_interval  5  ; Actively check the host every 5 minutes
  retry_interval  1  ; Schedule host check retries at 1 minute intervals
  max_check_attempts  10  ; Check each Linux host 10 times (max)
  check_command  check-host-alive ; Default command to check Linux hosts
  notification_period  workhours  ; Linux admins hate to be woken up, so we only notify during the day
  ; Note that the notification_period variable is being overridden from
  ; the value that is inherited from the generic-host template!
  notification_interval  120  ; Resend notifications every 2 hours
  notification_options  d,u,r  ; Only send notifications for specific host states
  contact_groups  admins  ; Notifications get sent to the admins by default
  register  0  ; DONT REGISTER THIS DEFINITION &#8211; ITS NOT A REAL HOST, JUST A TEMPLATE!
  }
  # 在nagios.cfg配置文件中开启对/usr/local/nagios/etc/servers/中配置文件的引用。
  cfg_dir=/usr/local/nagios/etc/servers
  # 远程Linux主机监控文件,如果监控多台主机只需简单复制修改即可。
  #我们应该牢记wiki-l-11.cfg用到的命令在commands.cfg中定义,在commands.cfg中定义的命令用到/usr/local/nagios/libexec下的插件(命令)。
  vi /usr/local/nagios/etc/servers/wiki-l-11.cfg
  # 定义主机
  define host{
  use  linux-server  ; Name of host template to use
  ; This host definition will inherit all variables that are defined
  ; in (or inherited by) the linux-server host template definition.
  host_name  wiki
  alias  Docs
  address  192.168.0.11
  }
  # 定义Ping远程Linux主机
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  PING
  check_command  check_ping!100.0,20%!500.0,60%  ;check_ping命令在commands.cfg中定义,后跟两个参数,命令及参数间用!分割。
  }
  #检查远程Linux主机根分区使用情况,check_nrpe命令必须在/usr/local/nagios/etc/objects/commands.cfg中定义(默认未定义)
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  Root Partition
  check_command  check_nrpe!check_disk_root
  }
  # 检查远程Linux主机的登录人数
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  Current Users
  check_command  check_nrpe!check_users
  }
  # 检查远程Linux的主机的负载
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  Current Load
  check_command  check_nrpe!check_load
  }
  # 检查远程Linux主机swap分区使用情况
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  Swap Usage
  check_command  check_nrpe!check_swap
  }
  # 检查远程Linux主机的SSH服务
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  SSH
  check_command  check_ssh
  notifications_enabled  0
  }
  # 检查远程Linux主机的HTTP服务
  define service{
  use  generic-service  ; Name of service template to use
  host_name  wiki
  service_description  HTTP
  check_command  check_http
  notifications_enabled  0
  }
  vi /usr/local/nagios/etc/servers/hostgroup.cfg
  # 定义主机组(localhost.cfg中有类似的主机组设置,我已将其注释掉,否则可能会有冲突)
  define hostgroup{
  hostgroup_name  linux-servers ; The name of the hostgroup
  alias  Linux Servers ; Long name of the group
  members  localhost,wiki  ; Comma separated list of hosts that belong to this group
  }
  #define hostgroup{
  #  hostgroup_name  windows-servers ; The name of the hostgroup
  #  alias  Windows Servers ; Long name of the group
  #  members  print  ; Comma separated list of hosts that belong to this group
  #  }
  =============================================================
  # 完成监控主机配置文件的配置后使用下面命令检查配置文件的正确性:
  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  # 确定无误后重启Nagios:
  service nagios restart
  =============================================================
  &#9679;check_load的用法及意义
这个插件是用来检测系统当前的cpu负载,使用的方法为
check_load [-r] -w WLOAD1,WLOAD5,WLOAD15 -c CLOAD1,CLOAD5,CLOAD15
在unix里面负载的均值通常表示是1分钟,5分钟,15分钟内平均有多少进程处于等待状态.
例如:check_load -w 15,10,5 -c 30,25,20 这个命令的意义如下
当1分钟多于15个进程等待,5分钟多于10个,15分钟多于5个则为warning状态
当1分钟多于30个进程等待,5分钟多于25个,15分钟多于20个则为critical状态
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-110766-1-1.html 上篇帖子: Nagios学习实践系列——产品介绍篇 下篇帖子: redhat--nagios插件--check_traffic.sh
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表