zoukankan      html  css  js  c++  java
  • 09linux基础服务-nagios

    Nagios 是一款免费的开源 IT 基础设施监控系统,功能强大,灵活性强,能有效监控 Windows、Linux、VMware 和 Unix 主机状态,交换机、路由器等网络设置等。一旦主机或服务状态出现异常时,会发出邮件或短信报警第一时间通知 IT 运营人员,在恢复后发出正常的邮件或短信。Nagios 结构简单,可维护性强,提供一个可选的基于浏览器的 Web 界面,方便管理人员查看系统的运行状态,网络状态、服务状态、日志信息,以及其它异常现象。

    一、nagios运行模式和优点

    1、运行模式:数据收集是C/S模式,用户查看监控信息是B/S模式

    2、优点: 

    1:监控网路服务状态(HTTPD,FTP,SSH,MySql……)

    2:监控主机资源(处理器符合,硬盘利用率……)

    3:拓展,根据自己的需求实现拓展检测功能(插件开发)

    4:自动日志回滚

    5:能够定义网络主机的层次,允许逐级检查,就是从父主机开始向下检查

    6:警告,基于状态的警告:OK,Warning(警告),critical(关键),unknown(未知)

    7:可以支持并实现对主机的冗余监控

    8:Web界面可以查看当前网络状态,通知,问题历史,日志文件等

    二、nagios运行原理

    Nagios的功能是监控服务和主机,但是他自身并不包括这部分功能,所有的监控、检测功能都是通过各种插件来完成的。

    启动Nagios后,它会周期性的自动调用插件去检测服务器状态,同时Nagios会维持一个队列,所有插件返回来的状态信息都进入队列,Nagios每次都从队首开始读取信息,并进行处理后,把状态结果通过web显示出来。

    Nagios提供了许多插件,利用这些插件可以方便的监控很多服务状态。安装完成后,在nagios主目录下的/libexec里放有nagios自带的可以使用的所有插件,如,check_disk是检查磁盘空间的插件,check_load是检查CPU负载的,等等。每一个插件可以通过运行./check_xxx –h 来查看其使用方法和功能

    三、nagios所需要的软件

    LAP环境,不需要mysql

    nagios-3.5.1.tar.gz                         #Nagios核心文件,Nagios服务文件,不建议用最新,很多插件没做好

    nagios-plugins-2.1.1.tar.gz                #Nagios插件,用于存放脚本和命令

    NSCP-0.5.0                             #也就是Nsclient++,用来监控Windows,分为64位、32位版本

    nrpe-2.15.tar.gz                          #代理服务,用于监控非Nagios服务器的服务器本地私有信息代理

    vautour_style.zip                          #主题包

    四、部署nagios监控服务器

    在部署之前,需要做好最基本的环境,包括lap环境的构建(这里直接使用yum方式安装即可,在做zabbix的时候我们需要使用我们编译的LNMP环境来做)

    1、解决依赖和安装lap环境

    [root@localhost ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

    [root@localhost ~]# yum clean all && yum list     

    [root@localhost ~]# yum install -y gcc glibc glibc-common php gd gd-devel libpng libmng libjpeg zlib

    [root@localhost ~]# yum install -y httpd ; systemctl start httpd                

    2、添加nagios运行用户

    [root@localhost ~]# useradd nagios  注意这里不能使用nologin的shell,nagios会用到此用户

    [root@localhost ~]# groupadd nagcmd  建立一个组

    [root@localhost ~]# usermod -G nagcmd nagios  将nagios和Apache用户分都加入nagcmd组中

    [root@localhost ~]# usermod -G nagcmd apache

    3、nagios核心安装

    [root@localhost ~]# mkdir nagios  建立一个文件夹,把nagios所有相关的软件都放到此目录下

    [root@localhost nagios]# ls

    nagios-3.5.1.tar.gz nagios-plugins-2.1.1.tar.gz

    nagios-4.2.4.tar.gz nrpe-2.15.tar.gz

    [root@localhost nagios]# tar xvf nagios-3.5.1.tar.gz -C /usr/local/src/

    [root@localhost nagios]# cd /usr/local/src/nagios/

    [root@localhost nagios]# cd /usr/local/src/nagios/  指定nagios运行用户组,在编译完成之后会有如下的信息显示

    General Options:
    -------------------------
    Nagios executable: nagios
    Nagios user/group: nagios,nagios    #运行用户
    Command user/group: nagios,nagcmd  #运行用户组
    Embedded Perl: no
    Event Broker: yes
    Install ${prefix}: /usr/local/nagios    #默认安装到了/usr/local/nagios
    Lock file: ${prefix}/var/nagios.lock
    Check result directory: ${prefix}/var/spool/checkresults
    Init directory: /etc/rc.d/init.d
    Apache conf.d directory: /etc/httpd/conf.d  #apache的conf.d配置文件目录
    Mail program: /bin/mail
    Host OS: linux-gnu

    Web Interface Options:
    ------------------------
    HTML URL: http://localhost/nagios/  #登录地址
    CGI URL: http://localhost/nagios/cgi-bin/
    Traceroute (used by WAP):


    Review the options above for accuracy. If they look okay,
    type 'make all' to compile the main program and CGIs.

    [root@localhost nagios]# make all  这里执行完成之后如果没有错误,就会退市安装那些东西

    [root@localhost nagios]# make install && make install-init && make install-commandmode && make install-config && make install-webconf 

    安装参数解释:

    //make install  #安装生成/usr/local/nagios 其中/usr/local/nagios/share即nagiosweb  访问解密的站点目录

    //make install-init  #安装生成/etc/rc.d/init.d/nagios启动脚本

    //make install-config  #安装生成/usr/local/nagios/etc下的nagios相关配置文件

    //make install-commandmode  #设定相应nagios工作目录的权限

    //make install-webconf  #安装nagios的web配置文件到Apache的conf.d目录下       

    到此时,安装过程就结束了       

    4、生成文件介绍

    在安装的时候,make install生成share这个目录,这个目录是访问界面目录:

    [root@localhost nagios]# ls /usr/local/nagios/share/

    config.inc.php  images     js        robots.txt        side.php

    contexthelp     includes   main.php  rss-corefeed.php  ssi

    docs            index.php  media     rss-newsfeed.php  stylesheets

    make install-init的时候,生成启动脚本

    [root@localhost Nagios]# ls /etc/init.d/nagios

    /etc/init.d/nagios      #其实就是在/etc/rc.d/init.d/nagios

    make install-config的时候,生成了Nagios的相关配置文件

    [root@localhost Nagios]# ls /usr/local/nagios/etc/

    cgi.cfg  nagios.cfg  objects  resource.cfg

    #包括以后安装了plugin等软件后,配置文件也会放入此目录

    resource.cfg:定义了很多资源变量的调用

    make install-webconf的时候,已经把web-conf的配置文件放入了/etc/httpd/conf.d/下面

    [root@localhost Nagios]# ls /etc/httpd/conf.d/nagios.conf

    /etc/httpd/conf.d/nagios.conf       #里面配置了一个别名,直接引用了

    /usr/local/nagios/share目录

    5、nagios主目录介绍

     

    [root@localhost nagios]# ll /usr/local/nagios/
    总用量 4
    drwxrwxr-x. 2 nagios nagios 38 8月 9 10:24 bin  #nagios执行程序所在目录
    drwxrwxr-x. 3 nagios nagios 130 8月 9 10:25 etc  #nagios配置文件所在目录,初始安装只有几个*.cfg文件
    drwxrwxr-x. 2 nagios nagios 6 8月 9 10:17 libexec  #监控所有命令,需要安装了nagios-plugins插件才会有,检查命令,不装是空的
    drwxrwxr-x. 2 nagios nagios 4096 8月 9 10:24 sbin  #nagios的CGI文件所在目录,外部命令所需要的文件存放目录
    drwxrwxr-x. 10 nagios nagios 257 8月 9 10:24 share  #Nagios前端页面
    drwxrwxr-x. 5 nagios nagios 45 8月 9 10:17 var  #日志文件,pid文件等

    6、认识nagios的配置文件

    [root@localhost nagios]# vim /usr/local/nagios/etc/nagios.cfg

    og_file=/var/log/nagios/nagios.log                        #日志位置

    cfg_file=/etc/nagios/objects/commands.cfg          #这个文件定义了很多命令

    cfg_file=/etc/nagios/objects/contacts.cfg                   #定义联系人,怎么联系

    cfg_file=/etc/nagios/objects/timeperiods.cfg                #定义了时间段

    cfg_file=/etc/nagios/objects/templates.cfg                  #模板(联系人,主机,时间)

    cfg_file=/etc/nagios/objects/localhost.cfg                  #监控本机相关配置文件

    #cfg_file=/etc/nagios/objects/windows.cfg                   #windows,默认不监控

    #cfg_file=/etc/nagios/objects/switch.cfg                    #交换机路由器监控,默认不监控

    #cfg_file=/etc/nagios/objects/printer.cfg                   #打印机监控,默认不监控

    #cfg_dir=/etc/nagios/servers                                #定义了服务合集(多个使用)

    #cfg_dir=/etc/nagios/printers                               #定义了打印机合集(多个使用)

    #cfg_dir=/etc/nagios/switches                               #定义了交换合集(多个使用)

    #cfg_dir=/etc/nagios/routers                                #定义了路由合集(多个使用) 

    resource_file=/etc/nagios/private/resource.cfg 资源变量配置文件,包括$USER1$变量(一个路径)等

    status_update_interval=10                                   #状态更新时间,单位s

    log_rotation_method=d                                       #日志滚动,默认天

    service_check_timeout=60                                    #服务检查超时时间

    host_check_timeout=30                                   #主机检查超时时间

    event_handler_timeout=30                               

    notification_timeout=30

    ocsp_timeout=5

    perfdata_timeout=5

    [root@localhost nagios]# vim /usr/local/nagios/etc/cgi.cfg   #此配置文件的优先级比nagios.cfg优先级高

    main_config_file= /usr/local/nagios/etc/nagios.cfg             #主配置文件

    physical_html_path= /usr/local/nagios/share          #物理路径

    url_html_path=/nagios                               #URL后面加上/nagios才能访问

    use_authentication=1                                #使用认证

    use_ssl_authentication=0                          #不使用ssl

    authorized_for_system_information=nagiosadmin       #认证用户

    6、测试访问,重启Apache,然后访问IP/nagios

    [root@localhost nagios]# systemctl restart httpd

    打开会有提示输入用户名和密码的弹窗

    需要用户名和密码,查看vim /etc/httpd/conf.d/nagios.conf配置文件

    [root@localhost nagios]# vim /etc/httpd/conf.d/nagios.conf

    Directory字段里面有Auth这三个字段,那么就可以使用htpasswd来生成用户名和密码

    [root@localhost nagios]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin  #-c表示创建,二次添加用户,不能使用-c参数
    New password:
    Re-type new password:
    Adding password for user nagiosadmin

    注意:nagios 默认使用nagiosadmin来管理,如果使用其他用户名,对应的配置文件也要修改

    [root@localhost nagios]# systemctl restart httpd   重启Apache

    检查配置文件

    nagios的目录下,bin目录下有一个nagios命令,这个命令可以帮助我们对配置文件的检查工作以及指定相关配置文件

    [root@localhost Nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

     -v=--verify-config 验证配置文件是否有误,着重看到下图亮点就没问题

    Total Warnings:0

    Total Errors:   0 

    指定配置文件,以守护进程方式启动

    [root@localhost Nagios]# /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

    但是现在还没有做任何深入配置,所以现在只是可以登录而已!

    五、安装nagios-plugins插件

    为了后面的实验要求,我们点吧mysql客户端安装了

    [root@localhost nagios]# yum -y install mysql mysql-devel

    Nagios-plugins含有丰富的检测命令插件,安装完成之后放在了/usr/local/Nagios/libexec下面

    [root@localhost nagios]# tar -zxvf nagios-plugins-2.1.1.tar.gz -C /usr/local/src/

    [root@localhost nagios]# cd /usr/local/src/nagios-plugins-2.1.1/

    [root@localhost nagios-plugins-2.1.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd

    [root@localhost nagios-plugins-2.1.1]# make && make install

    [root@localhost nagios-plugins-2.1.1]# ls /usr/local/nagios/libexec/  #可以看到该目录下一句有很多check的命令了
    check_apt check_flexlm check_load check_nt check_real check_time
    check_breeze check_ftp check_log check_ntp check_rpc check_udp
    check_by_ssh check_http check_mailq check_ntp_peer check_sensors check_ups
    check_clamd check_icmp check_mrtg check_ntp_time check_simap check_uptime
    check_cluster check_ide_smart check_mrtgtraf check_nwstat check_smtp check_users
    check_dhcp check_ifoperstatus check_mysql check_oracle check_spop check_wave
    check_disk check_ifstatus check_mysql_query check_overcr check_ssh negate
    check_disk_smb check_imap check_nagios check_ping check_ssmtp urlize
    check_dummy check_ircd check_nntp check_pop check_swap utils.pm
    check_file_age check_jabber check_nntps check_procs check_tcp utils.sh

    重启nagios服务,检查环境

    [root@localhost nagios-plugins-2.1.1]# systemctl restart httpd; /etc/init.d/nagios restart

    浏览器测试:登陆之后,点击hosts,可以看到,默认监控的是本机,说明环境没有什么问题

    六nagios监控本服务器

    配置监控之前,我们需要做一系列的准备工作(指定主配置文件需要加载的配置文件—定义主机—定义服务 –定义监控命令—检查配置文件—启动Nagios

    1、监控本地NFS状态

    首先安装nfs

    [root@localhost objects]# yum -y install nfs-utils

    [root@localhost nagios-plugins-2.1.1]# cd /usr/local/nagios/etc/objects/
    [root@localhost objects]# cp localhost.cfg localhost.cfg.bak  #备份配置文件

    [root@localhost objects]# vim localhost.cfg    #在配置文件最后按照模板添加如下内容

    define service{
    use local-service ; Name of service template to use
    host_name localhost
    service_description NFS
    check_command check_tcp!2049
    }

    #在使用check命令之前,要确保下/usr/local/nagios/libexec/  目录下有没有你需要的check命令,如果有,直接调用,如果没有,检测端口来代替,检测格式:  check_tcp!端口号

     [root@localhost objects]# vim /etc/exports                         //创建一个共享

    /tmp    *(rw)                 

     [root@localhost objects]# systemctl restart nfs

     [root@localhost objects]# showmount -e 192.168.0.63        //检测NFS目前是否正常

    Export list for 192.168.0.63:

    /tmp *

    检测localhost是否正常启用

     [root@localhost objects]# grep cfg_file /usr/local/nagios/etc/nagios.cfg

    cfg_file=/usr/local/nagios/etc/objects/localhost.cfg        #localhost默认已经启用了

    检测配置文件是否有误

     [root@localhost objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

    Total Warnings:0

    Total Errors:   0

    [root@localhost objects]# /etc/init.d/nagios restart     #重启nagios服务

    网页测试

    以及有NFS的监控项了,稍等一会儿他正在检测

    NFS以及监控成功,我们测试停到nfs看监控会不会随之变化

    [root@localhost libexec]# systemctl stop nfs      //再观察这里注意,一般没回立马又显示出来状态,需要一段时间,最好最快的方法就是手动强制刷新,否则你需要等待,强制刷新,点击NFS后有一个Reschedule the next check of this service,强制刷新

     七、配置nagios监控远程MySQL数据库状态

    【监控任何一台服务器,工作流程是定义主机,定义服务,定义命令】

    首先准备一台服务器,ip地址为192.168.204.136  在此服务器上安装msyql 蓝色为在此服务器上操作,黑色为在nagios服务器上操作

    [root@localhost ~]# yum -y install mariadb-server mariadb

    [root@localhost ~]# systemctl start mariadb  

    [root@localhost ~]# mysql  #登录创建一个测试数据库,并授权nagios服务器可以登录

    MariaDB [(none)]> create database nagios;  
    Query OK, 1 row affected (0.00 sec)

    MariaDB [(none)]> grant select on nagios.* to nagios@'192.168.204.128' identified by '123456';
    Query OK, 0 rows affected (0.00 sec)

    在nagios服务器上配置

    现在主配置文件中添加一下两行,用来导入新增的配置文件

    [root@localhost ~]# vim /usr/local/nagios/etc/nagios.cfg

    cfg_file=/usr/local/nagios/etc/objects/hosts.cfg  #此文件用来增加远程主机的
    cfg_file=/usr/local/nagios/etc/objects/service.cfg  #此文件用来定义远程主机监控服务的

    [root@localhost ~]# vim /usr/local/nagios/etc/objects/hosts.cfg   创建配置文件

    define host{
      use   linux-server    #使用的模板名字
      host_name    mysql.cn  #主机名
      address    192.168.204.136  #IP 地址
    }

    [root@localhost ~]# vim /usr/local/nagios/etc/objects/service.cfg

    define service{
      use    local-service
      host_name    mysql.cn
      service_description   MySqlSev
      check_commadn   check_mysql
    }

    [root@localhost ~]# vim /usr/local/nagios/etc/objects/commands.cfg  #编辑定义命令的配置文件

    define command{
      command_name check_mysql
      command_line $USER1$/check_mysql -H $HOSTADDRESS$ -u nagios -p 123456 -d nagios
    }

    在重启服务之前可以先通过检查命令来看下check_mysql是否可用,也检测下配置的检测命令是否正确

    [root@localhost ~]# /usr/local/nagios/libexec/check_mysql -H192.168.204.136 -unagios -p123456 -d nagios
    Uptime: 914 Threads: 1 Questions: 6 Slow queries: 0 Opens: 0 Flush tables: 2 Open tables: 26 Queries per second avg: 0.006|Connections=4c;;; Open_files=21;;; Open_tables=26;;; Qcache_free_memory=0;;; Qcache_hits=0c;;; Qcache_inserts=0c;;; Qcache_lowmem_prunes=0c;;; Qcache_not_cached=0c;;; Qcache_queries_in_cache=0;;; Queries=7c;;; Questions=6c;;; Table_locks_waited=0c;;; Threads_connected=1;;; Threads_running=1;;; Uptime=914c;;;

    注意:所有的check_command字段中的所使用的命令,必须在command.cfg中定义好才能使用,而command.cfg中的command_line中使用的命令,必须在/usr/local/Nagios/libexec/目录下存在,安装plugins会生成

    手动检测command.cfg的命令有效性

    注意:服务器要安装了mysql客户端软件,然后再重新编译安装下plugins 才会生成check_mysql  yum install mysql mysql-devel

    现在重启nagios服务,然后网页上看下是否添加成功

    定义监控web服务:

    先手动测试下:/usr/local/nagios/libexec/check_tcp -H192.168.0.64 -p 80

    [root@localhost objects]# vim hosts.cfg

    define host{

            use          linux-server

            host_name    xuegod64.cn

            address     192.168.0.64

    }   

    ##上面已经定义过mysql的主机,此处无需再定义

     [root@localhost objects]# vim service.cfg

    define service{

            use                     local-service

            host_name             xuegod64.cn

            service_description    Nginx

            check_command       check_nginx

    }

     [root@localhost objects]# vim commands.cfg

    define command{

            command_name    check_nginx

            command_line    $USER1$/check_tcp -H $HOSTADDRESS$ -p 80

    }

    [root@localhost objects]#/etc/init.d/nagios restart  #重启测试监控nginx 

    八、nrpe插件

    8.1nagios监控外部主机私有信息

    私有信息,包饭默认的硬盘使用,进程数目,SWAP分区等等

    私有信息,就是我需要再本机登录操作登录的

    非私有,就可以通过远程的方式

    只有监控私有信息的时候,才调用NRPE这个插件来通信

    8.2nrpe插件

    通过nrpe服务可以添加本地信息的监控,将数据发送到我们nagios服务器

    nrpe分两部分组成,一部分是监控机check_nrpr,一部分是被监控机的nrpe守护进程

    nagios服务器执行check_nrpe插件并告诉他检查哪个服务,check_nrpe插件通过SSL连接方式联系远程服务器上的NRPE守护进程,NRPE守护进程执行相应的插件完成指定的检测,并返回结果。

    8.3nrpe工作原理

    nrpe是基于SSL的机制,那么我们需要做的时间就是构建SSL环境,所以需要使用NRPE工作的时候,都需要安装ssl,而且服务端和客户端都需要安装NRPE软件,而我们客户端不需要装nagios服务端

    客户端的NRPE安装

    1)安装nagios-plugins插件

    2)安装nrpe

    3)配置我们xinted服务,允许谁来拿数据

    4)启动xinetd

    5)查看端口是否正常启动

    解决依赖,客户端和服务端都需要安装

    yum install -y openssl openssl-devel

    服务端安装

    [root@localhost nagios]# tar xvf nrpe-2.15.tar.gz -C /usr/local/src/

    [root@localhost ~]# cd /usr/local/src/nrpe-2.15/

    [root@localhost nrpe-2.15]# ./configure

    [root@localhost nrpe-2.15]# make && make install

    [root@localhost nrpe-2.15]# make install-plugin

    [root@localhost nrpe-2.15]# make install-daemon

    前者安装插件,后者以守护进程来允许

    [root@localhost nrpe-2.15]# ls /usr/local/nagios/libexec/check_nrpe
    /usr/local/nagios/libexec/check_nrpe    #这个命令需要安装nrpe之后才有

    客户端安装

    [root@localhost src]# useradd -s /sbin/nologin nagios

    [root@localhost src]# groupadd nagcmd

    [root@localhost src]# usermod -G nagcmd nagios

    [root@localhost src]# yum -y install xinetd

    [root@localhost src]# tar xvf nagios-plugins-2.1.1.tar.gz

    [root@localhost src]# cd nagios-plugins-2.1.1

    [root@localhost nagios-plugins-2.1.1]# ./configure

    [root@localhost nagios-plugins-2.1.1]# make && make install

    [root@localhost src]# tar -zxvf nrpe-2.15.tar.gz

    [root@localhost src]# cd nrpe-2.15

    [root@localhost nrpe-2.15]# make && make install

    [root@localhost nrpe-2.15]# make install-daemon-config    #这里是客户端,不用make-install-plugin

    [root@localhost nrpe-2.15]# make install-xinetd

    [root@localhost nrpe-2.15]# vim /etc/xinetd.d/nrpe

    # default: on
    # description: NRPE (Nagios Remote Plugin Executor)
    service nrpe
    {
    flags = REUSE
    socket_type = stream
    port = 5666
    wait = no
    user = nagios
    group = nagios
    server = /usr/local/nagios/bin/nrpe
    server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
    log_on_failure += USERID
    disable = no
    only_from = 127.0.0.1 192.168.204.128    #添加nagios服务器地址,徐云63这台机器来连接自己的nrpe服务,多个地址IP地址空格分开
    }

    [root@localhost nrpe-2.15]# echo "nrpe 5666/tcp #NRPE">>/etc/services    #注册端口,向服务器说明我要用5666这个端口,不要把这个端口分配给别人了

    注:

    nrpe            5666/tcp                # NRPE

    #/etc/services文件的作用:

    #作用1xinet.d来启动服务时他就会在/etc/services找相应服务对应的端口来启动服务。找不到对应端口,将不启动服务。

    #作用2: 显示对应端口对应的协议名。

    #例如 iptables  -L  不加-n参数,   查看时,把 80   -> www  http

    #作用3:查看常用端口

    [root@localhost nrpe-2.15]# systemctl restart xinetd   #启动服务

    [root@localhost nrpe-2.15]# netstat -antup | grep 5666
    tcp6 0 0 :::5666 :::* LISTEN 42666/xinetd

    配置客户端nrpe命令

    [root@localhost nrpe-2.15]# vim /usr/local/nagios/etc/nrpe.cfg

    command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 38% -c 35% -p /dev/sda1

    command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 42% -c 43% -p /dev/sda2

    command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%

    #-w为警告 -C为告急  sda2中,我们是指剩余42%

    [root@localhost nrpe-2.15]# systemctl restart xinetd

    在服务端手动测试下命令是否可用

    [root@localhost libexec]# ./check_nrpe -H192.168.204.136
    NRPE v2.15
    [root@localhost libexec]# /usr/local/nagios/libexec/check_nrpe -H192.168.204.136 -c check_sda1
    DISK OK - free space: / 15797 MB (90% inode=99%); /dev 474 MB (100% inode=99%); /dev/shm 486 MB (100% inode=99%); /run 478 MB (98% inode=99%); /sys/fs/cgroup 486 MB (100% inode=99%); /boot 881 MB (86% inode=99%); /run/user/0 97 MB (100% inode=99%);| /=1596MB;17394;;0;17394 /dev=0MB;474;;0;474 /dev/shm=0MB;486;;0;486 /run=7MB;486;;0;486 /sys/fs/cgroup=0MB;486;;0;486 /boot=132MB;1014;;0;1014 /run/user/0=0MB;97;;0;97

    然后定义监控主机

    [root@localhost libexec]# vim /usr/local/nagios/etc/objects/hosts.cfg

    define host{
    use linux-server
    host_name mysql.cn
    address 192.168.204.136
    }

    我们现在还是监控的是136的这个机器,所以这里信息不用改,如果定义新的机器,则需要重新定义

    定义需要监控的服务

    [root@localhost libexec]# vim /usr/local/nagios/etc/objects/service.cfg

    define service{
    use local-service
    host_name mysql.cn
    service_description sda2_Partition
    check_command check_nrpe!check_sda2
    }
    define service{
    use local-service
    host_name mysql.cn
    service_description Total Processes
    check_command check_nrpe!check_total_procs
    }
    define service{
    use local-service
    host_name mysql.cn
    service_description Current Load
    check_command check_nrpe!check_load
    }

    #分别是监测分区,进程总数,负载

    定义NRPE监控命令

    [root@localhost libexec]# vim /usr/local/nagios/etc/objects/commands.cfg

    define command{
    command_name check_nrpe
    command_name $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
    }

    #$ARG1$ 表示调用后面的参数。

  • 相关阅读:
    c语言一道题
    try,catch,finally尝试(一个程序块多个catch)
    利用接口及抽象类设计实现
    设计一个限制子类的访问的抽象类实例,要求在控制台输出如下结果
    多态,重写和重载
    织梦被挂了黑链的可能原因和排查清除办法
    织梦cms手机站首页不更新的解决办法
    dedecms织梦会员登录二级域名跨域不能获取数据的解决办法
    织梦cms添加新变量出现:Request var not allow!的解决办法
    织梦dedecms使用Mysql8.0无法登录后台的解决办法
  • 原文地址:https://www.cnblogs.com/hackerlin/p/11325317.html
Copyright © 2011-2022 走看看