基于CentOS的Nagios配置实录

首先感谢博客园的博主David_Tang

我的实践成果都是基于他的知识分享。万分感谢!!!!

这是他的文章地址:http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html

只是在实践中出现了一些小瑕疵,在此笔者努力更正,为了帮助后来之人。

另外本文可能没有图片,图片请参考上面所提到的地址:http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html

 

先来一张Nagios的2015峰会的会标
THE INDUSTRY STANDARD IN IT INFRASTRUCTURE MONITORING
这是Nagios的宗旨,对于Nagios的监控能力和效用,由此大家可见一斑!
 

CentOS 6.x的安装指南

Install CentOS

These steps were performed using CentOS-6.5-x86_64-bin-DVD1.iso

  • Boot the CentOS installer ISO
  • Select Install or upgrade an existing system
  • You can skip the media test
  • The GUI installer appears
  • Click Next
  • Select your language and click Next
  • Select your keyboard and click Next
  • Storage - For the purposes of this guide I am:
    • Selecting Basic Storage Device and click Next
    • Storage Device Warning
      • Tick the box Apply my choice to all devices with undetected partitions or filesystems
      • Click Yes, discard any data
  • Hostname
    • I am using the hostname core40x.box293.local
    • Click Configure Network
      • Select System eth0
      • Click Edit
      • Tick the box Connect automatically
      • IPv4 Setting tab
        • A static IP Address is preferred for a Nagios core host
        • Provide the static IP Address parameters
      • Click Apply
    • Click Close
  • Click Next
  • Select your Timezone
  • Click Next
  • Provide a root password for this host
  • Click Next
  • Which type of install would you like - For the purposes of this guide I am:
    • Replace Existing Linux System(s)
    • Click Next
    • Click Write changes to disk 
  • Select Minimal and click Next
  • Wait while the installation is performed
  • When the installation is complete click Reboot

 

Confirm Network Configuration

After the system has booted:

  • Login to the console as root
  • Type ifconfig and press Enter
  • Your IP settings will be shown
  • If they do not appear it's likely eth0 was not put in an up state. Do the following to correct:
    • Type ifup eth0 and press Enter
    • Wait while eth0 is brought up
    • Type ifconfig and press Enter
    • Confirm the network settings are correct
    • You should also make sure that the interface is set to be in an up state on bootup
    • Type sed -i 's/ONBOOT=no/ONBOOT=yes/g' /etc/sysconfig/network-scripts/ifcfg-eth0 and press Enter
    • We'll reboot the server to ensure the interface comes up on boot
    • Type reboot and press Enter
    • After the host has booted up confirm the interface is up as per the steps above

 

SSH To Host

All steps from now on can be done via an ssh session to the host, the added benefit is that commands here can be copied and pasted into the ssh session (saves typing mistakes). Login as root.

 

Install Prerequisites And Other Items

The following commands will install all the prerequisites for Nagios core along with some other tools that you may use later.

  • Type yum install -y wget httpd php gcc glibc glibc-common gd gd-devel make net-snmp nano system-config-network-tui and press Enter
  • Wait while all of these components are installed

 

Install Net-SNMP

The following is optional, only required if you want the SNMP plugins installed.

 

Install LDAP Libraries

The following is optional, only required if you want the LDAP plugins installed.

  • Type yum install -y openldap-devel and press Enter
  • Wait while all of these components are installed / updated

Disable SELinux

Security-Enhanced Linux (SELinux) will cause a few headaches so it's simpler to disable it now.

  • Type sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config and press Enter
  • Type setenforce 0 and press Enter

 

Configure Timezone

The following commands will install ntp, configure the timezone in CentOS and in PHP. 

  • For the purposes of this guide I will be using America/Chicago as the timezone source
  • Type rm -f /etc/localtime and press Enter
  • Type ln -s /usr/share/zoneinfo/America/Chicago /etc/localtime and press Enter
  • Type yum install -y ntp and press Enter
  • Wait while ntp is installed
  • Type ntpdate pool.ntp.org and press Enter
  • You'll get a message like:
    • 16 Sep 20:54:54 ntpdate[1376]: step time server 198.110.48.12 offset 17975.735304 sec
  • Type service ntpd start and press Enter
  • You can now confirm the data and time are correct
  • Type date and press Enter
  • You'll get a message like:
    • Tue Sep 16 20:56:54 CDT 2014
  • We'll also configure PHP
  • Type nano /etc/php.ini and press Enter
    • This opens the nano editor
    • Press CTRL W
    • Type ;date.timezone and press Enter
    • This will take you the location in the ini file for the timezone setting
    • Remove the semicolon (;) and set the relevant value, for example:
    • date.timezone = America/Chicago
    • A list can be seen on the php website: http://php.net/manual/en/timezones.php
    • Press CTRL X
    • Type Y to save the changes
    • Press Enter to accept the php.ini file

 

Download Nagios Core

  • Type cd /tmp and press Enter
  • Type wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz and pressEnter
  • Wait while the file is downloaded
  • Type wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz and press Enter
  • Wait while the file is downloaded

 

Install Nagios Core

The following steps will install Nagios Core 4.0.8 and Nagios Plugins 2.0.3.

  • Type useradd nagios and press Enter
  • Type groupadd nagcmd and press Enter
  • Type usermod -a -G nagcmd nagios and press Enter
  • Type usermod -a -G nagcmd apache and press Enter
  • Type usermod -a -G nagios apache and press Enter
  • Type tar zxf nagios-4.0.8.tar.gz and press Enter
  • Type tar zxf nagios-plugins-2.0.3.tar.gz and press Enter
  • Type cd nagios-4.0.8 and press Enter
  • Type ./configure --with-command-group=nagcmd and press Enter
  • Wait for the configure command to complete
  • Type make all and press Enter
  • Wait for the make all command to complete
  • Type make install and press Enter
  • Wait for the make install command to complete
  • Type make install-init and press Enter
  • Wait for the make install-init command to complete
  • Type make install-config and press Enter
  • Wait for the make install-config command to complete
  • Type make install-commandmode and press Enter
  • Wait for the make install-commandmode command to complete
  • Type make install-webconf and press Enter
  • Wait for the make install-webconf command to complete
  • Type cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/ and press Enter
  • Type chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers and press Enter
  • Type /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg and press Enter
  • The last command ran the nagios pre-flight check
  • Type /etc/init.d/nagios start and press Enter
  • The last command started nagios
  • Type htpasswd -c -b /usr/local/nagios/etc/htpasswd.users nagiosadmin nagiosadminpassword and press Enter
  • The last command added the user nagiosadmin with the password nagiosadminpassword
  • Type cd /tmp/nagios-plugins-2.0.3 and press Enter
  • Type ./configure --with-nagios-user=nagios --with-nagios-group=nagios and press Enter
  • Wait for the configure command to complete
  • Type make and press Enter
  • Wait for the make command to complete
  • Type make install and press Enter
  • Wait for the make install command to complete
  • Type chkconfig --add nagios and press Enter
  • Type chkconfig --level 35 nagios on and press Enter
  • Type chkconfig --add httpd and press Enter
  • Type chkconfig --level 35 httpd on and press Enter
  • Type iptables -I INPUT -p tcp --destination-port 80 -j ACCEPT and press Enter
  • Type service iptables save and press Enter
  • Type service httpd start and press Enter

This completes the Nagios Core and Nagios Plugins installation.

 

Login To Nagios Core Web Interface

  • Open a web browser to http://core40x.box293.local/nagios
  • You will be prompted for credentials, I will use the ones I defined earlier:
    • Username: nagiosadmin
    • Password:  nagiosadminpassword
  • You are now on the main web interface of Nagios Core
 
 
 
 
 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

Nagios简介

Nagios logo

  Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。

  Nagios原名为NetSaint,由Ethan Galstad开发并维护至今。NAGIOS是一个缩写形式: "Nagios Ain't Gonna Insist On Sainthood" Sainthood 翻译为圣徒,而"Agios"是"saint"的希腊表示方法。Nagios被开发在Linux下使用,但在Unix下也工作得非常好。

主要功能

  • 网络服务监控(SMTP、POP3、HTTP、NNTP、ICMP、SNMP、FTP、SSH)
  • 主机资源监控(CPU load、disk usage、system logs),也包括Windows主机(使用NSClient++ plugin)
  • 可以指定自己编写的Plugin通过网络收集数据来监控任何情况(温度、警告……)
  • 可以通过配置Nagios远程执行插件远程执行脚本
  • 远程监控支持SSH或SSL加通道方式进行监控
  • 简单的plugin设计允许用户很容易的开发自己需要的检查服务,支持很多开发语言(shell scripts、C++、Perl、ruby、Python、PHP、C#等)
  • 包含很多图形化数据Plugins(Nagiosgraph、Nagiosgrapher、PNP4Nagios等)
  • 可并行服务检查
  • 能够定义网络主机的层次,允许逐级检查,就是从父主机开始向下检查
  • 当服务或主机出现问题时发出通告,可通过email, pager, sms 或任意用户自定义的plugin进行通知
  • 能够自定义事件处理机制重新激活出问题的服务或主机
  • 自动日志循环
  • 支持冗余监控
  • 包括Web界面可以查看当前网络状态,通知,问题历史,日志文件等

二、Nagios工作原理

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

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

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

  Nagios可以识别4种状态返回信息,即 0(OK)表示状态正常/绿色、1(WARNING)表示出现警告/黄色、2(CRITICAL)表示出现非常严重的错误/红色、3(UNKNOWN)表示未知错误/深黄色。Nagios根据插件返回来的值,来判断监控对象的状态,并通过web显示出来,以供管理员及时发现故障。

四种监控状态

2

  再说报警功能,如果监控系统发现问题不能报警那就没有意义了,所以报警也是nagios很重要的功能之一。但是,同样的,Nagios 自身也没有报警部分的代码,甚至没有插件,而是交给用户或者其他相关开源项目组去完成的。

  Nagios 安装,是指基本平台,也就是Nagios软件包的安装。它是监控体系的框架,也是所有监控的基础。

  打开Nagios官方的文档,会发现Nagios基本上没有什么依赖包,只要求系统是Linux或者其他Nagios支持的系统。不过如果你没有安装apache(http服务),那么你就没有那么直观的界面来查看监控信息了,所以apache姑且算是一个前提条件。关于apache的安装,网上有很多,照着安装就是了。安装之后要检查一下是否可以正常工作。

  知道Nagios 是如何通过插件来管理服务器对象后,现在开始研究它是如何管理远端服务器对象的。Nagios 系统提供了一个插件NRPE。Nagios 通过周期性的运行它来获得远端服务器的各种状态信息。它们之间的关系如下图所示:

1

Nagios 通过NRPE 来远端管理服务

1. Nagios 执行安装在它里面的check_nrpe 插件,并告诉check_nrpe 去检测哪些服务。

2. 通过SSL,check_nrpe 连接远端机子上的NRPE daemon

3. NRPE 运行本地的各种插件去检测本地的服务和状态(check_disk,..etc)

4. 最后,NRPE 把检测的结果传给主机端的check_nrpe,check_nrpe 再把结果送到Nagios状态队列中。

5. Nagios 依次读取队列中的信息,再把结果显示出来。

三、实验环境

Host Name OS IP Software
Nagios-Server CentOS release 6.3 (Final) 192.168.1.108 Apache、Php、Nagios、nagios-plugins
Nagios-Linux CentOS release 5.8 (Final) 192.168.1.111 nagios-plugins、nrpe
Nagios-Windows Windows XP 192.168.1.113  NSClient++

Server 安装了nagios软件,对监控的数据做处理,并且提供web界面查看和管理。当然也可以对本机自身的信息进行监控。

Client 安装了NRPE等客户端,根据监控机的请求执行监控,然后将结果回传给监控机。

防火墙已关闭/iptables: Firewall is not running.

SELINUX=disabled

 

验证程序是否被正确安装

切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、sbin、share、var 这五个目录,如果存在则可以表明程序被正确的安装到系统了。Nagios 各个目录用途说明如下:

bin Nagios 可执行程序所在目录
etc Nagios 配置文件所在目录
sbin Nagios CGI 文件所在目录,也就是执行外部命令所需文件所在的目录
share Nagios网页文件所在的目录
libexec Nagios 外部插件所在目录
var Nagios 日志文件、lock 等文件所在的目录
var/archives Nagios 日志自动归档目录
var/rw 用来存放外部命令文件的目录

 

/usr/local/nagios/etc每个文件或目录含义如下表所示:

文件名或目录名 用途
cgi.cfg 控制CGI访问的配置文件
nagios.cfg Nagios 主配置文件
resource.cfg 变量定义文件,又称为资源文件,在些文件中定义变量,以便由其他配置文件引用,如$USER1$
objects objects 是一个目录,在此目录下有很多配置文件模板,用于定义Nagios 对象
objects/commands.cfg 命令定义配置文件,其中定义的命令可以被其他配置文件引用
objects/contacts.cfg 定义联系人和联系人组的配置文件
objects/localhost.cfg 定义监控本地主机的配置文件
objects/printer.cfg 定义监控打印机的一个配置文件模板,默认没有启用此文件
objects/switch.cfg 定义监控路由器的一个配置文件模板,默认没有启用此文件
objects/templates.cfg 定义主机和服务的一个模板配置文件,可以在其他配置文件中引用
objects/timeperiods.cfg 定义Nagios 监控时间段的配置文件
objects/windows.cfg 监控Windows 主机的一个配置文件模板,默认没有启用此文件

详解:
template.cfg  定义最最基本的 联系人、主机、服务这三类的模板
                     define contact      generic-contact
                   
                       define host            generic-host
                                                     linux-server(继承generic-host属性)
                                                     windows-server(继承generic-host属性)
                                                    generic-printer(继承generic-host属性)
                                                    generic-switch(继承generic-host属性)
 
                      define  service       generic-service 
                                                      local-server(继承generic-service属性)
 
localhost.cfg
                        define host              继承:  linux-server属性
                                                         名   localhost
                                                           别名 localhost
                                                            地址 127.0.0.1
                        define service        继承local-server属性
                                                          名 localhost
                                                        别名 localhost    
                                                        描述:
                                                        check命令:
                      service包括 1.ping  2.disk  3.user   4.process  5.load  6.swap   7.SSH 8.HTTP
                       check命令都在command.cfg中进行了定义。
 
contact.cfg    
                         define contact       继承:  generic-contact的属性
                                                          名称:     nagiosadmin     
                                                            别名: nagios admin   
                   define contactgroup      名称 
                                                            别名
                                                            成员    nagiosadmin
 
timeperiod.cfg   
                             define  timeperiod   名称:24x7
                                                                提醒时间: 全天候
                               define timeperiod   名称: workhour
                                                                   提醒时间: 工作周
                                define timeperiod  名称: none
                                                                    提醒时间: 无(不提醒)
                                define timeperiod  名称: US holiday
                                                                    提醒时间:除了美式假期
 
windows.cfg    
                             define host           继承: windows-server属性
                                                            名:
                                                            别名:
                                                            地址:
                            define hostgroup   名:
                                                            别名:
                            define service         继承:generic-service属性
                                                            名:
                                                            描述:
                                                            check命令:
                              check命令查询:1.NSClient++ version     2.Uptime  3.CPU_load   4.Memory  5.C:\Drive space  6.W3SVC 7.explorer
 
 
define host{
        use                     linux-server          ;引用主机linux-server的属性信息,linux-server主机在templates.cfg文件中进行了定义。
        host_name               x-Linux         ;主机名
        alias                    xianyuan-Linux          ;主机别名
        address                 192.168.1.9         ;被监控的主机地址,这个地址可以是ip,也可以是域名。
define host{
        use                     linux-server          ;引用主机linux-server的属>性信息,linux-server主机在templates.cfg文件中进行了定义。
        host_name               a-Linux          ;主机名
        alias                   annong-Linux          ;主机别名
        address                 192.168.1.10        ;被监控的主机地址,这个地址>可以是ip,也可以是域名。
define host{
        use                     linux-server          ;引用主机linux-server的属>性信息,linux-server主机在templates.cfg文件中进行了定义。
        host_name               k-Linux          ;主机名
        alias                   kupin-Linux          ;主机别名
        address                 192.168.1.12         ;被监控的主机地址,这个地址>可以是ip,也可以是域名。
        }
#定义一个主机组
define hostgroup{
        hostgroup_name          hanminfo-servers        ;主机组名称,可以随意指定。
        alias                   hanminfo servers        ;主机组别名
        members                 x-Linux,a-Linux,k-Linux          ;主机组成员,其中“Nagios-Linux”就是上面定义的主机。
        }
 
 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

利用NRPE监控远程Linux上的“本地信息”

上面已经对远程Linux 主机是否存活做了监控,而判断远程机器是否存活,我们可以使用ping 工具对其监测。还有一些远程主机服务,例如ftp、ssh、http,都是对外开放的服务,即使不用Nagios,我们也可以试的出来,随便找一台机器看能不能访问这些服务就行了。但是对于像磁盘容量,cpu负载这样的“本地信息”,Nagios只能监测自己所在的主机,而对其他的机器则显得有点无能为力。毕竟没得到被控主机的适当权限是不可能得到这些信息的。为了解决这个问题,nagios有这样一个附加组件--“NRPE”,用它就可以完成对Linux 类型主机"本地信息”的监控。

9.1 NRPE 工作原理

nrpe

NRPE 总共由两部分组成:
  • check_nrpe 插件,位于监控主机上
  • NRPE daemon,运行在远程的Linux主机上(通常就是被监控机)

按照上图,整个的监控过程如下:

当Nagios 需要监控某个远程Linux 主机的服务或者资源情况时:

  1. Nagios 会运行check_nrpe 这个插件,告诉它要检查什么;
  2. check_nrpe 插件会连接到远程的NRPE daemon,所用的方式是SSL;
  3. NRPE daemon 会运行相应的Nagios 插件来执行检查;
  4. NRPE daemon 将检查的结果返回给check_nrpe 插件,插件将其递交给nagios做处理。

注意:NRPE daemon 需要Nagios 插件安装在远程的Linux主机上,否则,daemon不能做任何的监控。

 

监控主机操作如下:

在监控主机(Nagios-Server)上

之前已经将Nagios运行起来了,现在要做的事情是:

  • 安装check_nrpe 插件;
  • 在commands.cfg 中创建check_nrpe 的命令定义,因为只有在commands.cfg 中定义过的命令才能在services.cfg 中使用;
  • 创建对被监控主机的监控项目;

9.3.1 安装check_nrpe 插件

# tar zxvf nrpe-2.13.tar.gz 
# cd nrpe-2.13
# ./configure
# make all
# make install-plugin

只运行这一步就行了,因为只需要check_nrpe插件。

在Nagios-Linux 上我们已经装好了nrpe,现在我们测试一下监控机使用check_nrpe 与被监控机运行的nrpe daemon之间的通信。

看到已经正确返回了NRPE的版本信息,说明一切正常。

9.3.2 在commands.cfg中增加对check_nrpe的定义

# vi /usr/local/nagios/etc/objects/commands.cfg

在最后面增加如下内容:

意义如下:

复制代码
# 'check_nrpe' command definition
define command{
        command_name    check_nrpe         # 定义命令名称为check_nrpe,在services.cfg中要使用这个名称.
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$       #这是定义实际运行的插件程序.
# 这个命令行的书写要完全按照check_nrpe这个命令的用法,不知道用法的就用check_nrpe –h查看. }
复制代码

-c 后面带的$ARG1$ 参数是传给nrpe daemon 执行的检测命令,之前说过了它必须是nrpe.cfg 中所定义的那5条命令中的其中一条。在services.cfg 中使用check_nrpe 的时候要用 “!” 带上这个参数。

 

修改services.cfg

 

define service{
        use                     local-service
        host_name               Nagios-Linux     
#可以把host_name统统改成hostgroup_name,这样可以定义一个hostgroup组使用相同监控的服务
#这里的hostgroup_name的值即为上文定义的hanminfo-servers.
        service_description     Current Load
        check_command           check_nrpe!check_load
        }

define service{
        use                     local-service
        hostgroup_name          hanminfo-servers   #此处已改变!!
        service_description     Check Disk sda1
        check_command           check_nrpe!check_sda1
        }

define service{
        use                     local-service
        hostgroup_name          hanminfo-servers
        service_description     Total Processes
        check_command           check_nrpe!check_total_procs
        }

define service{
        use                     local-service
        hostgroup_name          hanminfo-servers
        service_description     Current Users
        check_command           check_nrpe!check_users
        }

define service{
        use                     local-service
        hostgroup_name          hanminfo-servers
        service_description     Check Zombie Procs
        check_command           check_nrpe!check_zombie_procs
        }

#以下的service检测是手动添加的:对应的需要被监控机上的nrpe.cfg配置好command命令!!!
define service{
        use                     local-service
        hostgroup_name          hanminfo-servers
        service_description     Check Swap
        check_command           check_nrpe!check_swap
        }
define service{
        use                     local-service
        hostgroup_name          hanminfo-servers
        service_description     HTTP
        check_command           check_nrpe!check_http
        }

 

被监控主机上操作如下:

 

# useradd nagios

# passwd nagios

安装Nagios 插件

# tar zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure --prefix=/usr/local/nagios
# make && make install
这一步完成后会在/usr/local/nagios/下生成三个目录include、libexec和share。

 

修改目录权限

# chown nagios.nagios /usr/local/nagios
# chown -R nagios.nagios /usr/local/nagios/libexec

 安装NRPE

# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz
# tar zxvf nrpe-2.13.tar.gz
# cd nrpe-2.13
# ./configure
# make all
# make install-plugin 安装check_nrpe插件 可以不装 目的是为了测试本地nrpe链接是否正常
# make install-daemon 
# make install-daemon-config
# make install-xinetd   安装xinetd脚本
编辑nrpe的xinted脚本
vi /etc/xinetd.d/nrpe
在only_from 后增加监控主机的IP地址。
 

编辑/etc/services 文件,增加NRPE服务 监听端口为tcp的5666

重启xinted 服务

# service xinetd restart

 

测试本地nrpe链接是否正常

# /usr/local/nagios/libexec/check_nrpe -H localhost

防火墙开启5666端口

 

提供帮助信息

# /usr/local/nagios/libexec/check_nrpe –h

 

编辑配置信息

# vi /usr/local/nagios/etc/nrpe.cfg

 

[root@Nagiso-Linux etc]# vi /usr/local/nagios/etc/nrpe.cfg
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1 #编译的nrpe默认是hda1,需要更改
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200      #进程数需要看情况改动
#以下是手动添加的命令,对应的需要在监控机上添加到service.cfg中!!!!
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
command[check_http]=/usr/local/nagios/libexec/check_http -I 127.0.0.1

红色部分是命令名,也就是check_nrpe 的-c 参数可以接的内容,等号 “=” 后面是实际执行的插件程序,都是利用脚本运行的。

 

 
 
 
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

、利用NSClient++监控远程Windows上的“本地信息”

在Nagios的libexec下有check_nt这个插件,它就是用来检查windows机器的服务的。其功能类似于check_nrpe。不过还需要搭配另外一个软件NSClient++,它则类似于NRPE。

NSClient++的原理如下图

可以看到NSClient与nrpe最大的区别就是:

  • 被监控机上安装有nrpe,并且还有插件,最终的监控是由这些插件来进行的。当监控主机将监控请求发给nrpe后,nrpe调用插件来完成监控。
  • NSClient++则不同,被监控机上只安装NSClient,没有任何的插件。当监控主机将监控请求发给NSClient++后,NSClient直接完成监控,所有的监控是由NSClient完成的。

这也说明了NSClient++的一个很大的问题:不灵活、没有可扩展性。它只能完成自己本身包含的监控操作,不能由一些插件来扩展。好在NSClient++已经做的不错了,基本上可以完全满足我们的监控需求。

 
被监控的windows配置如下:
 
安装NSClient++
安装目录到C盘
配置NSClient.ini配置文件
                                         默认端口tcp 12489 pwd 123456 需要与监控机上的密码对应
                                         将 [modules]部分的所有模块前面的注释都去掉,除了CheckWMI.dll。
DOS进入services.msc
选择NSClient服务的属性 允许服务与桌面交互,确定该服务已开启,且为“自动”(开机启动)
防火墙允许tcp 12489通过。
cmd 进入dos 命令:netstat -an |findstr "12489"
windows-server中,如果ping不成功,开启文件和打印机TCP回显:
实现效果如图:
W3SVC是IIS服务,开启就行。
普遍会出现Explorer not running的结果,此时修改监控机上的windows.cfg中define services模块中的Explorer的check_command.
把命令中大写的E改成小写就可以了。
 
总结:考虑到各个服务器的配置情况有所差异,尤其是web服务器不尽相同,所以check_http并不是良好的hostgroup服务,为了统一,可以在被监测的linux的nrpe.cfg中开启check_tcp命令 监测80端口即可。
 
 
至此,所有的服务和问题全部搞定。
尽情享受Nagios带来的便捷的监控体验吧。
posted @ 2015-08-29 15:54  Volcharge  阅读(125)  评论(0编辑  收藏  举报