nagios全攻略

来源:互联网 发布:apm飞控源码下载 编辑:程序博客网 时间:2024/05/20 06:09
. 基本安装和配置
本部分主要参考官方文档和田逸的文章<<看我出招之:我用Nagios(技术细节)>>来修改完成.
最后达到如下的功能
监控机自身的信息,包括主机信息以及对外提供的服务
被监控机对外提供的服务
如下所有的操作都在监控机192.168.18.89上进行
 
1.安装nagios主程序
解压缩
tar -zxvf nagios-2.9.tar.gz
cd nagios-2.9
编译,指定安装目录为/usr/local/nagios
./configure --prefix=/usr/local/nagios
输出如下信息
*** Configuration summary for nagios 2.9 04-10-2007 ***:
 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagios
            Embedded Perl:  no
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
                Lock file:  ${prefix}/var/nagios.lock
           Init directory:  /etc/rc.d/init.d
                  Host OS:  linux-gnu
 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  /usr/sbin/traceroute
Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.
 
make all
输出如下信息
*** Compile finished ***
If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
  make install
         This installs the main program, CGIs, and HTML files
使用make install来安装主程序,CGI和HTML文件
  make install-init
         This installs the init script in /etc/rc.d/init.d
使用make install-init在/etc/rc.d/init.d安装启动脚本
  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file
使用make install-commandmode来配置目录权限
  make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!
使用make install-commandmode来安装示例配置文件,安装的路径是/usr/local/nagios/etc.
*** Support Notes *******************************************
If you have questions about configuring or running Nagios,
please make sure that you:
     - Look at the sample config files
     - Read the HTML documentation
     - Read the FAQs online at http://www.nagios.org/faqs
before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you.  This might include:
     - What version of Nagios you are using
     - What version of the plugins you are using
     - Relevant snippets from your config files
     - Relevant error messages from the Nagios log file
For more information on obtaining support for Nagios, visit:
*************************************************************
Enjoy.
很多人都不注意安装过程中的输出信息,直到make install出错了才到处找人求救,而实际上输出的内容包含很多有价值的信息,例如安装路径,版本,每一步做什么,接下来的步骤等.尤其是输出的最后一屏信息,我个人建议好好的读一下.例如上面就列出了很多有价值的信息,我们只需要按照他说的做就行了.
 
安装
make install
输出如下错误
cd ./base && make install
make[1]: Entering directory `/home/yahoon/nagios/nagios-2.9/base'
make install-basic
make[2]: Entering directory `/home/yahoon/nagios/nagios-2.9/base'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
/usr/bin/install: invalid user `nagios' 非法用户nagios
make[2]: *** [install-basic] Error 1
make[2]: Leaving directory `/home/yahoon/nagios/nagios-2.9/base'
make[1]: *** [install] Error 2
make[1]: Leaving directory `/home/yahoon/nagios/nagios-2.9/base'
make: *** [install] Error 2
按照文档说明增加用户,修改权限
[root@localhost nagios-2.9]# groupadd nagios
[root@localhost nagios-2.9]# useradd -g nagios nagios
[root@localhost nagios-2.9]# mkdir /usr/local/nagios
[root@localhost nagios-2.9]# chown -R nagios.nagios /usr/local/nagios
查看目录权限
[root@localhost nagios-2.9]# ll /usr/local
drwxr-sr-x    2 nagios   nagios       4096 Jul 10 11:14 nagios
看到nagios目录的权限已经被正确修改了
 
重新执行make install输出信息如下
*** Main program, CGIs and HTML files installed ***
You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
  make install-init
     - This installs the init script in /etc/rc.d/init.d
  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file
  make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!
make[1]: Leaving directory `/home/yahoon/nagios/nagios-2.9'
 
执行如下命令来安装脚本
make install-init
 
执行
make install-commandmode
输出信息如下
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw
*** External command directory configured ***
You can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):
  make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!
 
执行
make install-config
输出信息如下
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg-sample
/usr/bin/install -c -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg-sample
/usr/bin/install -c -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg-sample
/usr/bin/install -c -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/localhost.cfg-sample
/usr/bin/install -c -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/commands.cfg-sample
*** Sample config file installed ***
Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.
If you have questions about configuring Nagios properly, please:
       - Look at the sample config files
       - Read the HTML documentation
       - Read the FAQs online at http://www.nagios.org/faqs
*BEFORE* you post a question to one of the mailing lists.
 
验证程序是否被正确安装。切换目录到安装路径(这里是/usr/local/nagios),看是否存在 etc、bin、 sbin、 share、 var这五个目录,如果存在则可以表明程序被正确的安装到系统了。后表是五个目录功能的简要说明:
bin
Nagios执行程序所在目录,nagios文件即为主程序
etc
Nagios配置文件位置,初始安装完后,只有几个*.cfg-sample文件
sbin
Nagios Cgi文件所在目录,也就是执行外部命令所需文件所在的目录
Share
Nagios网页文件所在的目录
Var
Nagios日志文件、spid 等文件所在的目录
var/archives
Empty directory for the archived logs
var/rw
Empty directory for the external command file
 
2.安装插件
解压缩
tar -zxvf nagios-plugins-1.4.9.tar.gz
cd nagios-plugins-1.4.9
编译,指定路径为之前nagios的安装路径
./configure --prefix=/usr/local/nagios/
make
安装
make install
ls /usr/local/nagios/libexec/
会显示安装的插件文件,即所有的插件都安装在libexec这个目录下
 
将apache的运行用户加到nagios组里面
从httpd.conf中过滤出当前的apache运行用户
grep ^User /usr/local/apache2/conf/httpd.conf
我的是vpopmail,下面将这个用户加入nagios组
usermod -G nagios apache
 
3.修改apache配置
修改apache的配置文件,增加nagios的目录,并且访问此目录需要进行身份验证
vi /usr/local/apache2/conf/httpd.conf,在最后增加如下内容
#setting for nagios 20070707
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
<Directory "/usr/local/nagios/sbin">
    Options ExecCGI
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "Nagios Access"
    AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
//用于此目录访问身份验证的文件
    Require valid-user
</Directory>
 
Alias /nagios /usr/local/nagios/share
<Directory "/usr/local/nagios/share">
    Options None
    AllowOverride None
    Order allow,deny
    Allow from all
    AuthName "Nagios Access"
    AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd
//用于此目录访问身份验证的文件
    Require valid-user
</Directory>
 
增加验证用户
也就是通过web访问nagios的时候,必须要用这个用户登陆.在这里我们增加用户test:密码为12345
[root@localhost conf]# /usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd mandahang
New password: (输入12345)
Re-type new password: (再输入一次密码)
Adding password for user test
 
查看认证文件的内容
[root@localhost conf]# less /usr/local/nagios/etc/htpasswd
test:OmWGEsBnoGpIc  前半部分是用户名test,后面是加密后的密码
 
到这里nagios的安装也就基本完成了,你可以通过web来访问了.
http://192.168.18.89/nagios 会弹出对话框要求输入用户名密码
输入test,密码12345,就可以进入nagios的主页面了
但是可以发现什么也点不开,因为nagios还没启动呢!下面的工作就是修改配置文件,增加要监控的主机和服务
4.典型配置
之前已经说过nagios要用起来,就必须修改配置文件,增加要监控的主机和服务才行.在具体做这个动作之前,下面的概念必须要了解.
 
1)预备知识
Nagios自己定义了一套规则用于配置文件,其中最重要的概念就是”对象”----object.通俗的理解:假定我们首先定义了”性别”这个对象,它的值只可能是男,女,人妖等等,然后定义某人为一个对象,例如张三,定义张三的时候有”性别”这个属性,它的值就必须来源了之前定义的性别这个对象,要么是男是女,或者是人妖.
在Nagios里面定义了一些基本的对象,一般用到的有:
联系人
contact
出了问题像谁报告?一般当然是系统管理员了
监控时间段
timeperiod
7X24小时不间断还是周一至周五,或是自定义的其他时间段
被监控主机
host
所需要监控的服务器,当然可以是监控机自己
监控命令
command
nagios发出的哪个指令来执行某个监控,这也是自己定义的
被监控的服务
service
例如主机是否存活,80端口是否开,磁盘使用情况或者自定义的服务等
另外,多个被监控主机可以定义为一个主机组,多个联系人可以被定义为一个联系人组,多个服务还能定义成一个服务组呢.
回到上面的例子,定义张三需要之前定义的性别,我们定义一个被监控的服务,当然就要指定被监控的主机,需要监控的时间段,要用哪个命令来完成这个监控操作,出了问题向哪个联系人报告.
所有这些对象绝对多数都是需要我们手动定义的,这就是nagios的安装显得复杂的地方.其实了解了原理,做一遍之后余下的工作就是复制粘贴了.下面就开始动手.
 
2)将示例配置文件复制为真实配置文件名
cd /usr/local/nagios/etc
cgi.cfg  htpasswd  nagios.cfg  objects  resource.cfg
cd /usr/local/nagios/etc/objects
 commands.cfg  localhost.cfg  switch.cfg     timeperiods.cfg
contacts.cfg  printer.cfg    templates.cfg  windows.cfg
 
3)修改配置文件
修改nagios的主配置文件nagios.cfg
vi nagios.cfg
注释行 #cfg_file=/usr/local/nagios/etc/localhost.cfg[2],然后把下面几行的注释去掉: 
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg      //联系人配置文件路径
cfg_file=/usr/local/nagios/etc/objects/commands.cfg     //命令配置文件路径
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg    //主机配置文件路径
cfg_file=/usr/local/nagios/etc/objects/templates.cfg    //摸板配置文件路径
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg   //监视时段配置文件路径
注释掉就说明不使用这个文件,去掉了注释就是需要使用这个文件.
改check_external_commands=0为check_external_commands=1 .这行的作用是允许在web界面下执行重启nagios、停止主机/服务检查等操作。
把command_check_interval的值从默认的1改成command_check_interval=10s(根据自己的情况定这个命令检查时间间隔,不要太长也不要太短)。
主配置文件要改的基本上就是这些,通过上面的修改,发现/usr/local/nagios/etc并没有文件hosts.cfg等一干文件,怎么办?稍后手动创建它们。
 
修改CGI脚本控制文件cgi.cfg
vi cgi.cfg
第二个要修改的配置文件是cgi.cfg,它的作用是控制相关cgi脚本。先确保use_authentication=1。曾看过不少的文章,都是建议把use_authentication的值设置成”0”来取消验证,这是一个十分糟糕的想法。接下来修改default_user_name=test ,再后面的修改在下表列出:
 authorized_for_system_information=nagiosadmin,mandahang
authorized_for_configuration_information=nagiosadmin,mandahang
authorized_for_system_commands=mandahang  //多个用户之间用逗号隔开
authorized_for_all_services=nagiosadmin,mandahang
authorized_for_all_hosts=nagiosadmin,mandahang
authorized_for_all_service_commands=nagiosadmin,mandahang
authorized_for_all_host_commands=nagiosadmin,mandahang
那么上述用户名打那里来的呢?是执行命令 /usr/local/apache/bin/htpasswd –c /usr/local/nagios/etc/htpasswd mandahang 所生成的,这个要注意,不能随便加没有存在的验证用户,为了安全起见,不要添加过多的验证用户。
 
定义监控时间段,创建配置文件timeperiods.cfg
[root@localhost etc]# vi timeperiods.cfg
define timeperiod{
        timeperiod_name         24x7   //时间段的名称,这个地方不要有空格
        alias                   24 Hours A Day,7Days 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
        }
定义了一个监控时间段,它的名称是24x7,监控的时间是每天全天24小时
 
定义联系人,创建配置文件contacts.cfg
[root@localhost etc]# vi contacts.cfg
define contact{
        contact_name                    mandahang//联系人的名称,这个地方不要有空格
        alias                           sys admin
        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-host-by-email
        host_notification_commands      notify-host-by-email
        email                           tfhudong@sohu.com
        pager                           1391119xxxx
        }
创建了一个名为test的联系人,下面列出其中重要的几个选项做说明
service_notification_period     24x7
服务出了状况通知的时间段,这个时间段就是上面在timeperiods.cfg中定义的.
host_notification_period        24x7
主机出了状况通知的时间段, 这个时间段就是上面在timeperiods.cfg中定义的
service_notification_options    w,u,c,r
当服务出现w—报警(warning),u—未知(unkown),c—严重(critical),或者r—从异常情况恢复正常,在这四种情况下通知联系人.
host_notification_options       d,u,r
当主机出现d­­­­—当机(down),u—返回不可达(unreachable),r—从异常情况恢复正常,在这3种情况下通知联系人
service_notification_commands   notify-by-email
服务出问题通知采用的命令notify-by-email,这个命令是在commands.cfg中定义的,作用是给联系人发邮件.至于commands.cfg之后将专门介绍
host_notification_commands      host-notify-by-email
同上,主机出问题时采用的也是发邮件的方式通知联系人
email                           yahoon@test.com
很明显,联系的人email地址
pager                           1338757xxxx
联系人的手机,如果支持短信的通知的话,这个就很有用了.
alias是联系人别名,address是地址 意义不大.
按照上面的方式简单的复制修改就可以创建多个联系人了.
 
下面就可以将多个联系人组成一个联系人组,创建文件contactgroups.cfg
[root@localhost etc]# vi contactgroups.cfg
define contactgroup{
        contactgroup_name               sagroup   
//联系人组的名称,同样不能空格
        alias                   System Administrators        //别名
        members                 mandahang 
//组的成员,来自于上面定义的contacts.cfg,如果有多个联系人则以逗号相隔
        }
 
定义被监控主机,创建文件hosts.cfg
[root@localhost etc]# vi hosts.cfg
define host{
        host_name                       localhost
//被监控主机的名称,最好别带空格
        alias                           localhost
        //别名
        address                         127.0.0.1
        //被监控主机的IP地址,我现在暂时先填本机的IP
        check_command                   check-host-alive
        //监控的命令check-host-alive,这个命令来自commands.cfg,用来监控主机是否存活
        max_check_attempts              5
        //检查失败后重试的次数
        check_period                    24x7
        //检查的时间段24x7,同样来自于我们之前在timeperiods.cfg中定义的
contact_groups                  sagroup
        //联系人组,上面在contactgroups.cfg中定义的sagroup
notification_interval           10
        //提醒的间隔,每隔10秒提醒一次
notification_period             24x7
        //提醒的周期, 24x7,同样来自于我们之前在timeperiods.cfg中定义的
notification_options            d,u,r
//指定什么情况下提醒,具体含义见之前contacts.cfg部分的介绍
        }
通过简单的复制修改就可以定义多个主机了.我们在这加上另外两台机器:
名为dbpi的linux主机,ip为192.168.18.81
名为yahoon的xp主机,ip为192.168.18.73
 
与联系人可以组成联系人组一样,多个主机也可以组成主机组.创建文件hostgrops.cfg
[root@localhost etc]# vi hostgroups.cfg
define hostgroup{
        hostgroup_name          linux-servers  //主机组名称
        alias                   linux-servers  //别名
        members                 localhost,linux81
//组的成员主机,多个主机以逗号相隔,必须是上面hosts.cfg中定义的
        }
 
下面是最关键的了,用nagios主要是监控一台主机的各种信息,包括本机资源,对外的服务等等.这些在nagios里面都是被定义为一个个的项目(nagios称之为服务,为了与主机提供的服务相区别,我这里用项目这个词),而实现每个监控项目,则需要通过commands.cfg文件中定义的命令.
例如我们现在有一个监控项目是监控一台机器的web服务是否正常, 我们需要哪些元素呢?最重要的有下面三点:首先是监控哪台机,然后是这个监控要用什么命令实现,最后就是出了问题的时候要通知哪个联系人?
 
定义监控的项目,也叫服务,创建services.cfg
[root@localhost etc]# vi services.cfg
#service definition
define service{
        host_name               localhost
        //被监控的主机,hosts.cfg中定义的
        service_description     check-host-alive
        //这个监控项目的描述(也可以说是这个项目的名称),可以空格,我们这里定义的是监控这个主机是不是存活
        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
        //通知的时间段, ,是timeperiods.cfg中定义的
        notification_options    w,u,c,r
        //在监控的结果是wucr时通知联系人,具体含义看前文.
        contact_groups          sagroup
        //联系人组,是contactgroups.cfg中定义的
        }
可以看到基本上所有的成员都是已经定义的.同样的将上面的内容复制修改,就可以加上另外两个监控项目:分别监控yahoon和dbpi是否存活
这样整个的配置过程就结束了.虽然功能很简单,但是已经为以后扩展打下了良好的基础.可以放心的告诉大家,以后的工作基本都是复制粘贴啦!!!
 
在运行nagios之前首先做测试
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
看到下面这些信息就说明没问题了
Total Warnings: 0
Total Errors:   0
Things look okay - No serious problems were detected during the pre-flight check
如果有问题的话就可以按照输出信息来排查
 
作为守护进程后台启动nagios
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
 
还等什么,登陆http://192.168.18.89/nagios/来查看吧.点左边的Host Detail
再点Service Detail
哇,终于写完了第二部分…痛苦啊…..不过,不过,不过,难道仅仅就监控个主机死不死就满足了?那一个个ping也花不了多久嘛
ssh开放了没?ftp工作正常不?http可以访问不?磁盘用了多少了?这些问题更有价值…..咋办?接着看呗.
. 使用命令和插件监控更多信息
个人觉得这里是全篇文章里面最难理解的部分,我也将尽力解释清楚.还是那句话,原理了解了什么就都简单了.
 
在上篇文章里面,我们已经增加了三个监控项目,分别监控localhost,81,73这三台主机是否存活.现在我对这三台机器分别做了如下设置
开放localhost的ftp
开放81的ssh
开放73的IIS
这篇文章里面所做的就是对这些服务进行监控,另外我们还要监控localhost的根分区的使用情况.
 
在这个系列的开篇<nagios全攻略()----准备阶段>里面谈到nagios的原理时,特别指出了nagios本身并没有监控的功能,所有的监控是由插件完成的,插件将监控的结果返回给nagios,nagios分析这些结果,以web的方式展现给我们,同时提供相应的报警功能(这个报警的功能也是由插件完成的)
所有的这些插件是一些实现特定功能的可执行程序,默认安装的路径是/usr/local/nagios/libexec,可以查看
这些程序都是可以独立执行的,使用方法可以通过”命令名 –h”来查看
例如,我们查看check_disk这个插件的用法则可以使用check_disk –h,如下图
[root@server1 libexec]# ./check_disk -h
check_disk (nagios-plugins 1.4.9) 1.91
Copyright (c) 1999 Ethan Galstad <nagios@nagios.org>
Copyright (c) 1999-2006 Nagios Plugin Development Team
This plugin checks the amount of used disk space on a mounted file system
and generates an alert if free space is less than one of the threshold values
Usage: check_disk -w limit -c limit [-p path | -x device] [-t timeout][-m] [-e] [-W limit] [-K limit] [-v] [-q] [-E]
Options:
……以下略
输出的资料十分详细给出了这个插件的功能,使用方法,参数意义等,对于每一个插件都是这样.所以当你不懂某个插件怎么使用时就好好读读吧.从上面的输出可以看到check_disk这个插件是用来检查磁盘使用情况的.
我现在来独立执行它,例如查看根分区的使用情况,执行
[root@server1 libexec]# ./check_disk -w 10% -c 5% /
命令的含义是检查分区/的使用情况,若剩余10%以下,为警告状态(warning),5%以下为严重状态(critical),
执行后我们会看到下面这条信息
DISK WARNING - free space: / 487 MB (6% inode=78%);| /=7449MB;7524;7942;0;8361
说明当前是warning的状态,空闲空间只有6%了.如果nagios收到这些状态结果就会采取报警等措施了
 
或许在这里大家又迷糊了,我们在定义某个监控项目时,所用的监控命令都是来自commands.cfg的,这和这些插件有什么关系???想到了吧,commands.cfg中定义的监控命令就是使用的这些插件.举个例子,之前我们已经不止一次用到了check-host-alive这个命令,打开commands.cfg就可以看到这个命令的定义,如下:
################################################################################
#
# SAMPLE HOST CHECK COMMANDS
#
################################################################################
# This command checks to see if a host is "alive" by pinging it
# The check must result in a 100% packet loss or 5 second (5000ms) round trip
# average time to produce a critical error.
# Note: Only one ICMP echo packet is sent (determined by the '-p 1' argument)
# 'check-host-alive' command definition
define command{
        command_name    check-host-alive
        command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 1
        }
command_name    check-host-alive
这句话的意思是定义的命令名是check-host-alive,也就是我们在services.cfg中使用的名称
执行的操作是
$USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 1
其中$USER1$是在resource.cfg文件中定义的,代表插件的安装路径.就如我们上面看到的那样$USER1$=/usr/local/nagios/libexec,至于$HOSTADDRESS$,则默认被定义为监控主机的地址.
简单的说,我们在services.cfg中定义了对dbpi执行check-host-alive命令,实际上就是执行了
/usr/local/nagios/libexec/ check_ping -H dbpiip地址 -w 3000.0,80% -c 5000.0,100% -p 1
实际上check-host-alive只是这一长串命令的简称而已,而在services.cfg中都是使用简称的.
在commands.cfg中定义了很多这样的命令简称.基本上我们常用的监控项目都包含了,例如ftp,http,本地的磁盘,负载等等.
我们再看一个命令,check_local_disk定义如下
# 'check_local_disk' command definition
define command{
        command_name    check_local_disk
        command_line    $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$
        }
check_local_disk实际上是执行的check_disk插件.这里的$ARG1$, $ARG2$, $ARG3$是什么意思呢?在之前我们已经提到了这个check_disk这个插件的用法,-w的参数指定磁盘剩了多少是警告状态,-c的参数指定剩多少是严重状态,-p用来指定路径.
在使用check-host-alive的时候,只需要在services.cfg中直接写上这个命令名check-host-alive.后面没任何的参数.而使用check_local_disk则不同,在services.cfg中这要这么写
check_local_disk!10%!5%!/
在命令名后面用!分隔出了3个参数,10%是$ARG1$的值,5%是$ARG2$的值,/ 是$ARG3$的值,
 
我不知道讲的是否清楚,头晕的就在后面提问哈.简单的一句话就是
services.cfg定义监控项目用某个命令
这个命令必须在commands.cfg中定义
定义这个命令时使用了libexec下的插件
如果命令不带$ARG1$就可以在services.cfg中直接使用,如果带了使用时就带上参数,!相隔
 
如果你理解了上面我说的”昏话”,下面的事情就简单的多了.我们要监控什么就修改相应的命令就行了.
1).监控localhostftp
编辑services.cfg 增加下面的内容,基本上就是copy上节我们定义监控主机存活的代码.略做修改.
define service{
        host_name               localhost
        要监控的机器,给出机器名,注意必须是hosts.cfg中定义的
        service_description     check ftp
        给这个监控项目起个名字吧,任意起,你自己懂就行
        check_command           check_ftp
        所用的命令,当然必须是commands.cfg中定义了的
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        contact_groups          sagroup
        }
 
2).监控81ssh
define service{
        host_name               81
        意义同上
service_description     check-ssh
        意义同上
check_command           check_tcp!22
        ssh所用的tcp22号端口,我就用commands中定义的check_tcp命令.至于!22的意思不用我说了吧.
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        contact_groups          sagroup
        }
 
3).监控73IIS
define service{
        host_name               73
        service_description     check-http
        check_command           check_http
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        contact_groups          sagroup
        }
 
4).监控nagios-sever的根分区的使用情况.
define service{
        host_name               localhost
        service_description     check disk
        check_command           check_local_disk!10%!5%!/
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        contact_groups          sagroup
        }
修改了配置文件,当然就要重新启动了,简单的方法杀掉nagios进程,然后重新启动
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
等几分钟,你会看到下面这张图
可以看到我的nagios-seerver上磁盘空间已经不足了,是warning.
 
哈哈,本章到此结束!!!
但是,但是但是…事情远远没完.我提几个问题:你知道了nagios-server这台机器的磁盘使用情况,可是dbpi这台机器的使用情况呢?dbpi当前登陆多少用户?多少进程?cpu负载如何?
ftp,ssh,http这些都是向外开放的服务,即使不用nagios我自己也可以试的出来,随便找一台机器看能不能访问这些服务就行了.可是磁盘容量,cpu负载,当前登陆用户数量你不登录这台机器原则上是不可能知道的,因为他们是本地信息.当然,木马可以做到…下节我们就让nagios做”木马”..
注:我们通过nagios查看到了nagios-server这台机的磁盘信息,这应该属于”本地信息”,本地信息不是得不到的吗??这是因为我们nagios运行在这台机器上啊.它当然可以检测自己所在的机器,对dbpi和yahoon…暂时看来是无能为力了.
. 使用NRPE监控LINUX上的本地信息
本部分主要参考了NRPE的官方手册
 
本节的目的,对系统为linux的主机dbpi进行如下监控:CPU负载,磁盘容量,登陆用户数,总进程数,僵尸进程数,swap分区使用情况
 
书接前文,对于像磁盘容量,cpu负载这样的”本地信息”,nagios只能监测自己所在的主机,而对其他的机器则显得有点无能为力.毕竟没得到被控主机的适当权限是不可能得到这些信息的.为了解决这个问题,nagios有这样一个附加组件----NRPE.用它就可以完成对linux类型主机”本地信息”的监控.
 
所以我们按照图示在监控主机(localhost)和被监控主机(81,也就是图中运行NRPE的remote linux host)上安装相应的软件
 
在被监控主机上
1增加用户
[root@dbpi root]# useradd nagios
设置密码
[root@dbpi root]# passwd nagios
 
2安装nagios插件
解压缩
tar -zxvf nagios-plugins-1.4.9.tar.gz
cd nagios-plugins-1.4.9
编译安装
./configure
make
make install
这一步完成后会在/usr/local/nagios/下生成两个目录libexec和share
[root@dbpi local]# ls /usr/local/nagios/
libexec  share
修改目录权限
[root@dbpi local]# chown nagios.nagios /usr/local/nagios
[root@dbpi local]# chown -R nagios.nagios /usr/local/nagios/libexec
 
3安装nrpe
解压缩
tar -zxvf nrpe-2.8.1.tar.gz
cd nrpe-2.8.1
编译
./configure
输出如下
*** Configuration summary for nrpe 2.8.1 05-10-2007 ***:
 General Options:
 -------------------------
 NRPE port:    5666
 NRPE user:    nagios
 NRPE group:   nagios
 Nagios user:  nagios
 Nagios group: nagios
Review the options above for accuracy.  If they look okay,
type 'make all' to compile the NRPE daemon and client.
可以看到NRPE的端口是5666,下一步是make all
 
make all
输出如下
*** Compile finished ***
If the NRPE daemon and client compiled without any errors, you
can continue with the installation or upgrade process.
Read the PDF documentation (NRPE.pdf) for information on the next
steps you should take to complete the installation or upgrade.
接下来安装NPRE插件,daemon和示例配置文件
 
安装check_nrpe这个插件
make install-plugin
之前说过监控机需要安装check_nrpe这个插件,被监控机并不需要,我们在这里安装它是为了测试的目的
安装deamon
make install-daemon
安装配置文件
make install-daemon-config
 
现在再查看nagios目录就会发现有4个目录了
[root@dbpi nrpe-2.8.1]# ls /usr/local/nagios/
bin      etc      libexec  share
按照安装文档的说明,是将NRPE deamon作为xinetd下的一个服务运行的.在这样的情况下xinetd就必须要先安装好,不过一般系统已经默认装了
 
4.安装xinetd脚本
[root@dbpi nrpe-2.8.1]# make install-xinetd
输出如下
/usr/bin/install -c -m 644 sample-config/nrpe.xinetd /etc/xinetd.d/nrpe
可以看到创建了这个文件/etc/xinetd.d/nrpe
编辑这个脚本
vi /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在后面增加监控主机的地址0.111,以空格间隔
}
改后
     only_from       = 127.0.0.1 192.168.18.89
 
编辑/etc/services文件,增加NRPE服务
vi /etc/services
增加如下
# Local services
nrpe            5666/tcp                        # nrpe
重启xinetd服务
[root@dbpi nrpe-2.8.1]# service xinetd restart
Stopping xinetd: [  OK  ]
Starting xinetd: [  OK  ]
 
查看NRPE是否已经启动
[root@dbpi nrpe-2.8.1]# netstat -at|grep nrpe
tcp            0 *:nrpe                  *:*                     LISTEN   
[root@dbpi nrpe-2.8.1]# netstat -an|grep 5666
tcp            0 0.0.0.0:5666            0.0.0.0:*               LISTEN  
可以看到5666端口已经在监听了
 
5.测试NRPE是否则正常工作
之前我们在安装了check_nrpe这个插件用于测试,现在就是用的时候.执行
/usr/local/nagios/libexec/check_nrpe -H localhost
会返回当前NRPE的版本
[root@dbpi nrpe-2.8.1]# /usr/local/nagios/libexec/check_nrpe -H localhost
NRPE v2.8.1
也就是在本地用check_nrpe连接nrpe daemon是正常的
注:为了后面工作的顺利进行,注意本地防火墙要打开5666能让外部的监控机访问
 
/usr/local/nagios/libexec/check_nrpe –h查看这个命令的用法
可以看到用法是check_nrpe –H 被监控的主机 -c要执行的监控命令
注意:-c后面接的监控命令必须是nrpe.cfg文件中定义的.也就是NRPE daemon只运行nrpe.cfg中所定义的命令
 
查看NRPE的监控命令
cd /usr/local/nagios/etc
vi nrpe.cfg
找到下面这段话
# The following examples use hardcoded command arguments...
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_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/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
红色部分是命令名,也就是check_nrpe 的-c参数可以接的内容,等号=后面是实际执行的插件程序(这与commands.cfg中定义命令的形式十分相似,只不过是写在了一行).也就是说check_users就是等号后面/usr/local/nagios/libexec/check_users -w 5 -c 10的简称.
我们可以很容易知道上面这5行定义的命令分别是检测登陆用户数,cpu负载,hda1的容量,僵尸进程,总进程数.各条命令具体的含义见插件用法(执行”插件程序名 –h”)
由于-c后面只能接nrpe.cfg中定义的命令,也就是说现在我们只能用上面定义的这五条命令.我们可以在本机实验一下.执行
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_users
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_load
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_hda1
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_zombie_procs
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs
 
 
在运行nagios的监控主机上
之前已经将nagios运行起来了,现在要做的事情是:
– 安装check_nrpe插件
– 在commands.cfg中创建check_nrpe的命令定义,因为只有在commands.cfg中定义过的命令才能在services.cfg中使用
–      创建对被监控主机的监控项目
安装check_nrpe插件
[root@server1 yahoon]# tar -zxvf nrpe-2.8.1.tar.gz
[root@server1 yahoon]# cd nrpe-2.8.1
[root@server1 nrpe-2.8.1]# ./configure
[root@server1 nrpe-2.8.1]# make all
[root@server1 nrpe-2.8.1]# make install-plugin
只运行这一步就行了,因为只需要check_nrpe插件
 
在81们刚装好了nrpe,现在我们测试一下监控机使用check_nrpe与被监控机运行的nrpedaemon之间的通信.
[root@server1 nrpe-2.8.1]# /usr/local/nagios/libexec/check_nrpe -H 192.168.18.81
NRPE v2.8.1
看到已经正确返回了NRPE的版本信息,说明一切正常.
 
在commands.cfg中增加对check_nrpe的定义
vi /usr/local/nagios/etc/commands.cfg
在最后面增加如下内容
########################################################################
#
# 2007.9.5 add by yahoon
# NRPE COMMAND
#
########################################################################
# 'check_nrpe ' command definition
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }
意义如下
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中定义对dbpi主机cpu负载的监控
define service{
        host_name               linux81
被监控的主机名,这里注意必须是linux且运行着nrpe,而且必须是hosts.cfg中定义的
        service_description     check-load
        监控项目的名称
        check_command           check_nrpe!check_load
        监控命令是check_nrpe,是在commands.cfg中定义的,带的参数是check_load,是在nrpe.cfg中定义的
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        contact_groups          sagroup
        }
像这样将其余四个监控项目加进来.
 
之前我们说过了,今天还有一个任务是要监控dbpi的swap使用情况.但是很遗憾,在nrpe.cfg中默认没有定义这个监控功能的命令.怎么办?手动在nrpe.cfg中添加,也就是自定义NRPE命令.
现在我们要监控swap分区,如果空闲空间小于20%则为警告状态—warning;如果小于10%则为严重状态—critical.我们可以查得需要使用check_swap插件,完整的命令行应该是下面这样.
/usr/local/nagios/libexec/check_swap -w 20% -c 10%
 
在被监控机上增加check_swap命令的定义
vi /usr/local/nagios/etc/nrpe.cfg
增加下面这一行
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
我们知道check_swap现在就可以作为check_nrpe的-c的参数使用了
修改了配置文件,当然要重启.但是
如果你是以独立的daemon运行的nrpe,那么需要手动重启.
如果你是在xinetd或者inetd下面运行的,则不需要.
由于我们是xinetd下运行的,所以不需要重启服务
 
在监控机上增加这个监控项目
define service{
        host_name               linux81
        service_description     check-swap
        check_command           check_nrpe!check_swap
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        contact_groups          sagroup
        }
所有的配置文件已经修改好了,现在重启nagios.杀掉nagios进程,然后再重启.等上一会你就可以看到下面这个画面了
 
基本上nagios的主要功能就有这些,nagios的使用关键在于如何活用那些丰富的插件.nagios可以说是一个对于linux/unix环境支持十分好的程序.对于被监控主机是windows系列相关的文章比较少.我就专门花一章来讲述.
有了下一篇,大家就可以功德圆满了.
写到这里,有几个我在安装和使用的几个小知识点,也可以说是小问题附在此处,欢迎大家批评指教.一般的附录都是在文章最后,可下一篇是windows相关了,与我要说的这几个问题没什么联系正所谓打铁趁热,我就在这里一气呵成,大家也容易看.
 
附录:
1.重启nagios的方法
之前我说重启nagios的时候都是用的杀进程的方式,其实也可以不这么做.如果在安装nagios的时候安装了启动脚本就可以使用/etc/init.d/nagios restart 还可以带的参数有stop, start,status
如果报错了,有可能是脚本里面的路径设置错误,解决办法
vi /etc/init.d/nagios
将prefix=/usr/local/nagiosaa改为安装的目录/etc/init.d/nagios
注:在nagios安装的时候说是将脚本安装到了/etc/rc.d/init.d,其实这和/etc/init.d是一个目录
2.有关于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状态
四.如何监控windows系统的”本地信息”
在nagios2.x系列里面,文档里面对于windows服务器的监控相关说明较少,刚到nagios主页上看到3.x的文档里面有一篇讲监控windows的(http://nagios.sourceforge.net/docs/3_0/monitoring-windows.html
),我就仿照过来,对它略作修改来应用到我们当前的nagios2.9上去.(毕竟3.x还是测试版,2.9是最新的稳定版,用起来放心啊)
 
细心的朋友可能注意到了,在nagios的libexec下有check_nt这个插件,它就是用来检查windows机器的服务的,其功能类似于上一章讲的check_nrpe.不过还需要搭配另外一个软件NSClient,它则类似于NRPE
 
NSClient的原理如下图
可以看到,NSClient与nrpe最大的区别就是:
--被监控机上安装有nrpe,并且还有插件,最终的监控是由这些插件来进行的.当监控主机将监控请求发给nrpe后,nrpe调用插件来完成监控.
--NSClient则不同,被监控机上只安装NSClient,没有任何的插件.当监控主机将监控请求发给NSClient后,NSClient直接完成监控,所有的监控是由NSClient完成的.
这也说明了NSClient的一个很大的问题,不灵活,没有可扩展性.它只能完成自己本身包含的监控操作,不能由一些插件来扩展.好在NSClient已经做的不错了,基本上可以完全满足我们的监控需要.
 
安装NSClient
http://sourceforge.net/projects/nscplus下载NSClient++-0.2.7.zip
解压为C:\NSClient++
打开cmd 切换到C:\NSClient++
执行nsclient++ /install进行安装
执行nsclient++ SysTray 注意大小写,这一步是安装系统托盘,时间稍微有点长
在运行里面输入services.msc打开”服务”
看到下图就说明NSClient服务已经安装上了
双击打开,点”登录”标签,在”允许服务与桌面交互”前打勾
 
编辑C:\NSClient++下的NSC.ini文件
将 [modules]部分的所有模块前面的注释都去掉,除了CheckWMI.dll and RemoteConfiguration.dll这两个
在[Settings]部分设置'password'选项来设置密码,作用是在nagios连接过来时要求提供密码.这一步是可选的,我这里方便起见跳过它,不要密码.
将[Settings]部分'allowed_hosts'选项的注释去掉,并且加上运行nagios的监控主机的IP.我改为如下这样allowed_hosts=127.0.0.1/32,192.168.0.111 以逗号相隔.这个地方是支持子网的,如果写成192.168.0.0/24则表示该子网内的所有机器都可以访问.如果这个地方是空白则表示所有的主机都可以连接上来.注意是[Settings]部分的,因为[NSClient]部分也有这个选项.
必须保证[NSClient]的'port'选项并没有被注释,并且它的值是'12489',这是NSClient的默认监听端口
在CMD中执行nsclient++ /start启动服务,注意所在目录是C:\NSClient++
这时在桌面右下角的系统托盘处会出现一个黄色的M字样的图标
 
查看服务
已经正常启动了.注意服务默认设的是”自动”,也就是说是开机自动启动的.
在cmd里面执行netstat –an可以看到已经开始监听tcp的12489端口了
这样外部就可以访问了吗?错!防火墙也要打开tcp的12489端口,否则nagios检查此服务的时候会报socket 超时错误.是critical哦!后果很十分严重啊.我就犯了这个错误,所以特别强调一下.
这样被监控机的配置就搞定了,它就等待nagios发出某个监控请求,然后它执行请求将监控的结果发回到nagios监控主机上.
 
对监控主机的配置
接下来就是要配置监控主机了.与之前的nrpe的过程类似,在监控主机上做的就3件事情
1.安装监控windows的插件(已经默认安装了,check_nt)
2.定义命令
3.定义要监控的项目
 
定义命令
vi /usr/local/nagios/etc/commands.cfg
增加下面的内容
########################################################################
#
# 2007.9.6 add by yahoon
# CHECK_NT
# check windows hosts info
#
########################################################################
define command{
        command_name    check_nt
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489  -v $ARG1$ $ARG2$
        }
如果NSClient设置了连接需要密码,则应写成如下格式
$USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s PASSWORD -v $ARG1$ $ARG2$
具体含义参考check_nt命令的用法
 
增加监控项目
vi /usr/local/nagios/etc/services.cfg
下面这个服务是监控NSClient的版本
define service{
        host_name               yahoon
        service_description     check-version
        check_command           check_nt!CLIENTVERSION
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        notification_options    w,u,c,r
        contact_groups          sagroup
        }
同样的可以增加如下服务(为了篇幅,我只给出最关键的check_command这一项)
1)监控windows服务器运行的时间
check_command           check_nt!UPTIME
2)监控Windows服务器的CPU负载,如果5分钟超过80%则是warning,如果5分钟超过90%则是critical
check_command           check_nt!CPULOAD!-l 5,80,90
3)监控Windows服务器的内存使用情况,如果超过了80%则是warning,如果超过90%则是critical.
check_command           check_nt!MEMUSE!-w 80 -c 90
4)监控Windows服务器C:\盘的使用情况,如果超过80%已经使用则是warning,超过90%则是critical
check_command           check_nt!USEDDISKSPACE!-l c -w 80 -c 90
注:-l后面接的参数用来指定盘符
5)监控Windows服务器D:\盘的使用情况,如果超过80%已经使用则是warning,超过90%则是critical
check_command           check_nt!USEDDISKSPACE!-l d -w 80 -c 90
6)监控Windows服务器的W3SVC服务的状态,如果服务停止了,则是critical
check_command           check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
7)监控Windows服务器的Explorer.exe进程的状态,如果进程停止了,则是critical
check_command           check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
 
重启nagios服务来生效,等一会就可以查看页面了
(红色的错误是因为我刚把ftp给关了,等会启动就好了)发现有三个服务的颜色是深黄色,状态是UNKNOWN,后面的信息是NSClient - ERROR: PDH Collection thread not running
这问题有点莫明其妙,因为大部分的新增服务都已经可以正常运行了,不要紧,把这句话放到goole里面一看,原来是由于操作系统语言的问题,好像NSClient默认支持的语言并不多.具体信息参考下面这两个页面
 
查看NSClient的日志C:\NSClient++下的nsclient.log,里面信息如下
2007-09-06 10:38:35: error:.\PDHCollector.cpp:69: Getting counter info...
2007-09-06 10:38:35: error:.\PDHCollector.cpp:97: Detected language: 0x0804 but it could not be found in: counters.defs
2007-09-06 10:38:35: error:.\PDHCollector.cpp:98: You need to manually configure performance counters!
注意红色部分,说是需要我手动配置.按照它的说明打开counters.defs文件,查看一下里面的内容,很容易就知道该怎么改了.结合上面的错误信息知道0x0804是当前系统语言”简体中文”的代码,推测系统文件和变量应该与原始的英文版都一样,复制文件里面"English US"那部分内容,再做修改就行.我在counters.defs的最后加上了如下的内容:
[0x0804]
Description = "Chinese"
NT4_SystemTotalProcessorTime = "\System\% Total Processor Time"
NT4_SystemSystemUpTime = "\System\System Up Time"
NT4_MemoryCommitLimit = "\Memory\Commit Limit"
NT4_MemoryCommitByte = "\Memory\Committed Bytes"
 
W2K_SystemTotalProcessorTime = "\Processor(_total)\% Processor Time"
W2K_SystemSystemUpTime = "\System\System Up Time"
W2K_MemoryCommitLimit = "\Memory\Commit Limit"
W2K_MemoryCommitByte = "\Memory\Committed Bytes"
 
OK,再等一会看页面,发现没变化,看来这样依样画葫芦不行啊…不甘心,看看日志,再次打开nsclient.log发现里面的内容没变.新修改的那部分根本就没起作用?至少也应该像之前那样报个ERROR才对啊?修改配置文件之后要干嘛???重启服务!!!!
在mmc里面重启NSClient服务,如下图右击对应的服务选”重新启动”
 
查看日志,内容如下
2007-09-06 12:32:37: error:.\PDHCollector.cpp:69: Getting counter info...
2007-09-06 12:32:37: error:.\PDHCollector.cpp:119: Attempting to open counter...
2007-09-06 12:32:38: error:.\PDHCollector.cpp:122: Counters opend...
看起来没什么问题(里面的error是引导符,开发这个程序的人下次该换换,正确了就不该是erorr了嘛),这边看起来没问题了,可还是要等页面正常才放心.耐心的等一会,得到了下面的页面.
 
一切搞定.我写的累,大家也看的累吧.不过希望大家都能有收获
整个nagios的配置过程也在此作结.多谢捧场.
 
后记:
罗唆一句,官方文档是最好的教程.大家可以看到我的所有操作,大部分都是按照官方文档一步步配置的.而且按照它配置出来的也就基本满足需要了.了解了整个过程和原理,就可以自己加加减减做修改满足自己的个性需求,出了问题不要紧,查文档,用google,达到活学活用也不是难事.
还是那句话,知道了原理,一切就都简单了.
 
最后针对nagios提炼几个要点
对于插件要注意使用方法,多用”命令名 –h”看看
修改了配置文件要重启服务生效
碰到问题google一下,别忘记了查看日志
 
阅读(1346) | 评论(1) | 转发(0) |
0

上一篇:Cisco交换机实现隔离访问

下一篇:Cisco的MAC地址与IP绑定

相关热门文章
  • Nagios 监控系统架设全攻略...
  • 打造完美商业空间装修,墙面漆...
  • Nginx负载均衡器的总结和思考...
  • Nagios如何监控Nginx服务器...
  • Nagios应该监控服务器基础选项...
  • linux 常见服务端口
  • 【ROOTFS搭建】busybox的httpd...
  • 什么是shell
  • linux socket的bug??
  • linux的线程是否受到了保护?...
  • 请教想查12个月的数据条数,看...
  • new/delete 和malloc/free 有...
  • ubuntu下hadoop环境的搭建...
  • 求助:如何用Linux架设ISATAP...
  • redhat图形界面不出先登录界面...
给主人留下些什么吧!~~

dbsrv2008-12-19 11:20:48

兄弟,问个问题,监控周期都定义了多久?我的进程是10-15分钟,CPU内存是20-30分钟,现在监控目标大概200多一点,其中有部分目标是进程组,就是一个目标内包含了4-6个进程。要是单个算起来,监控目标应该超过500了,结果就经常出现误报。想问问什么原因造成的。nagios到目标中间经过了2-3个路由器,nagios主机的配置是C2.1G,1G MEM,没有SWP分区。

回复 | 举报
原创粉丝点击