zoukankan      html  css  js  c++  java
  • nagios 安装配置(包含nrpe端)全 (三)

    四、系统的配置:

    1、介绍

    在配置过程中涉及到的几个定义有:主机、主机组,服务、服务组。联系人、联系人组,监控时间。监控命令等。

    最重要的有四点:

    第一:定义监控哪些主机、主机组、服务和服务组;
    第二:定义这个监控要用什么命令实现。
    第三:定义监控的时间段;
    第四:定义主机或服务出现故障时要通知的联系人和联系人组。

    2、几个主要配置文件

    • 创建hosts.cfg文件来定义主机和主机组

    • 创建services.cfg文件来定义服务

    • 用默认的contacts.cfg文件来定义联系人和联系人组

    • 用默认的commands.cfg文件来定义命令

    • 用默认的timeperiods.cfg来定义监控时间段

    • 用默认的templates.cfg文件作为资源引用文件

    3、定义主机:
    定义被监控主机,创建文件hosts.cfg :
    # cd /usr/local/nagios/etc
    # vi hosts.cfg 
    一个主机定义例如以下(举例):
    define host{ 
     host_name remote_host_1         //被监控主机的名称,最好别带空格 
     alias     RemoteHost_1                   //别名 
     address   192.168.20.154    //被监控主机的IP地址 
     check_command    check-host-alive 
     //监控的命令check-host-alive,这个命令来自commands.cfg,用来监控主机是否存活 
     max_check_attempts    5  //检查失败后重试的次数 
     check_period          24x7 
     //检查的时间段24x7,相同来自于我们之前在timeperiods.cfg中定义的 
     contact_groups        admins 
     //联系人组,contacts.cfg中定义的admins 
     notification_interval  10 
     //提醒的间隔,每隔10秒提醒一次 
     notification_period   24x7 
     //提醒的周期, 24x7,相同来自于我们之前在timeperiods.cfg中定义的 
     notification_options            d,u,r 
     //指定什么情况下提醒
     } 
    在监控系统上定义主机例如以下:
    先定义一个主机类
    define host{
              name                  linux-box             ; Name of this template
              use                   generic-host          ; Inherit default values
              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,u,r
              contact_groups        admins
              register              0          ; DONT REGISTER THIS - ITS A TEMPLATE
              }
    使用上面的类定义主机:
    define host{
              use       linux-box     ; 上面定义的主机类
              host_name remotehost_1    ;  被监控主机的名称,最好别带空格
              alias     RemoteHost_1 ; 别名 
              address   192.168.20.154   ; 被监控主机的IP地址 
              }
    
    定义多个主机。可參照上面的这个定义。

    4定义主机组 进入配置文件文件夹: # cd /usr/local/nagios/etc 创建hostgroups.cfg文件: # vi hostgroups.cfg 使用define定义keywordhostgroup表示该定义段内定义的是主机组段。段内的定义请使用两个大括号来包括。

    段内的定义项一行一项。 以下定义了一个主机组: define hostgroup{ hostgroup_name MonitoringHosts /*主机组名称*/ alias Group_1 /*主机组还有一个名称*/ members remote_host_1 /*主机组包括哪些主机,多个主机之间用逗号隔开*/ } 另外,假设要定义多个主机组段的话,那么必需要写多个define hostgroup {} ,參照上面。 5、定义监控服务所需的命令: # cd /usr/local/nagios/etc/objects # vi commands.cfg 比方要使用zccheck_disk监控主机的磁盘使用情况,定义方式例如以下: #'zccheck_disk' command defination define command{ command_name zccheck_disk command_line /usr/local/nagios/libexec/zccheck_disk.pl -w $ARG1$ -c $ARG2$ } 插件能够是自己编写的,也能够是已安装的nagios插件中有的插件。

    定义方式都一样。 6、定义监控服务: services.cfg 中定义。

    # cd /usr/local/nagios/etc # vi services.cfg 服务的定义分两种: 监控机上的服务和远程被监控机上的服务。这里仅仅介绍监控主机上服务的加入,远程被监控主机的服务在以下第二部分中介绍。

    1、使用use generic-service 定义简洁的服务(仅仅是举例) generic-service 是在/usr/local/nagios/etc/objects/templates.cfg 中定义的一个服务模板。引用这个模板能够创建非常简洁的服务,例如以下例: define service{ use generic-service host_name remotehost service_description IMAP4 Response Check check_command check_imap!-t 5 -e "mygreatmailserver.com" } 2、假设想自己定义一个服务,则能够用以下的方式定义(仅仅是举例) # vi services.cfg define service{ host_name nagios //被监控的主机,hosts.cfg中定义的 service_description check-host-alive //这个监控项目的描写叙述,这个会在web页面中出现 check_command check-host-alive //所用的命令,commands.cfg中定义的 max_check_attempts 5 //重试的次数 normal_check_interval 3 //循环检查的间隔时间 retry_check_interval 2 check_period 24x7 //监控的时间段,timeperiods.cfg中定义的 notification_interval 10 notification_period 24x7 //通知的时间段 notification_options w,u,c,r //在监控的结果是wucr时通知联系人 contact_groups sagroup //联系人组,contactgroups.cfg中定义的 } 3、监控系统上服务的定义(实际定义): 能够针对不同的服务定义不同的模板。然后引用这些模板达到简化服务定义的目的。

    1:先定义例如以下的服务模板,假设定义其它的模板能够仅仅改变红色的内容,其它不变: define service{ name zctech-service ; The 'name' of this service template active_checks_enabled 1 ; Active service checks are enabled passive_checks_enabled 1 ; Passive service checks are enabled/accepted parallelize_check 1 ; Active service checks should be parallelized (disabling this can lead to major performance problems) obsess_over_service 1 ; We should obsess over this service (if necessary) check_freshness 0 ; Default is to NOT check service 'freshness' notifications_enabled 1 ; Service notifications are enabled event_handler_enabled 1 ; Service 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 is_volatile 0 ; The service is not volatile check_period 24x7 ; The service can be checked at any time of the day max_check_attempts 5 ; Re-check the service up to 3 times in order to determine its final (hard) state normal_check_interval 5 ; Check the service every 10 minutes under normal conditions retry_check_interval 2 ; Re-check the service every two minutes until a hard state can be determined contact_groups admins ; Notifications get sent out to everyone in the 'admins' group notification_options w,u,c,r ; Send notifications about warning, unknown, critical, and recovery events notification_interval 60 ; Re-notify about service problems every hour notification_period 24x7 ; Notifications can be sent out at any time register 0 ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE! } 监控本机上定义例如以下的服务: 2)定义一个服务的方式例如以下:

    defineservice{

    use zctech-service

    host_namelocalhost

    service_descriptionzccheck-disk

    check_commandzccheck_disk!90!95

    }


    3)使用zccheck_proc_cmd定义的服务,比方监控系统的哪个服务或进程是否正常,则定义方式例如以下:

    比方监控 firefox服务: ps-aux

    1000 3355 1.5 6.9 1060900 280412 ? Sl 08:53 7:56 firefox

    则服务名定义为cmd-firefox就可以。假设有完整路径名和參数等,比方

    mysql 1883 0.1 1.2 311008 50120 ? Sl 08:37 0:47/usr/sbin/mysqld--basedir=/usr --datadir=/var/lib/mysql --user=mysql--pid-file=/var/run/mysqld/mysqld.pid--socket=/var/run/mysqld/mysqld.sock –port=3306

    service_description cmd-mysqld

    defineservice{

    use zctech-service

    host_namelocalhost

    service_descriptioncmd-firefox

    check_commandzccheck_proc_cmd!firefox

    }

    7、改动配置文件:
    # cd /usr/local/nagios/etc
    nagios.cfg 文件里加入以下内容:
    # vi nagios.cfg
    例如以下所看到的指定配置文件的位置:
    cfg_file=/usr/local/nagios/etc/hostgroups.cfg
    cfg_file=/usr/local/nagios/etc/hosts.cfg
    cfg_file=/usr/local/nagios/etc/services.cfg
    8、使加入的监控服务有效:

    检查配置文件有无错误:

    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    
    假设有错误。则检查配置文件的内容(依据提示信息)。
    
    假设没有错误。则重新启动nagios
    # service nagios restart
    在监控系统就能够看到新加的监控服务。(第一次加入之后可能要等几分钟才干显示出来)
    
    
    监控主机上的安装和配置到此完毕。
  • 相关阅读:
    1592:【例 1】国王
    状态压缩类动态规划笔记
    1300:鸡蛋的硬度
    1263:【例9.7】友好城市
    第四部分-并发编程案例分析4:高性能数据库连接池HikariCP
    容器基础3:容器镜像
    第四部分-并发编程案例分析3:高性能队列Disruptor
    容器基础2:隔离与限制
    第四部分-并发编程案例分析1:限流Guava RateLimiter
    容器基础1:进程
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/5254163.html
Copyright © 2011-2022 走看看