Nagios监控软件配置

At 2011-07-19

转载请注明文章转载自:Dbabc.Net [http://dbabc.net]
本文链接:http://dbabc.net/archives/2011/07/19/nagios01.shtml

实验环境:Server:RHEL5.6 Client:RHEL6.0,CentOS4.8,Window7
一、安装
1、相关安装包:
nagios-3.2.3(Nagios程序),nagios-plugins(Nagios插件),nrpe-2.12(检测代理程序)
所需系统软件包:
httpd,gcc,glibc,glibc-common,gd,gd-devel
2、安装过程:
1)为nagios建立用户和组

[root@scan ~]# useradd -m nagios
[root@scan ~]# passwd
[root@scan ~]# groupadd nagcmd
[root@scan ~]# usermod -a -G nagcmd nagios
[root@scan ~]# usermod -a -G nagcmd apache

2)安装nagios所需的包
(1)nagios-3.2.3 解压完依次运行

./configure --with-command-group=nagcmd
      make all & make install & make install-init &
      make install-commandmode & make install-config & make install-webconf
      htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin(建立登录apache页面所需的用户名和密码)

(2)nagios-plugins解压完依次运行

./configure --with-nagios-user=nagios --with-nagios-group=nagios
      make & make install

(3)nagios-snmp-plugins解压完依次运行

perl –MCPAN –e shell
        cpan> install Net::SNMP
        ./install.sh
        chkconfig –add nagios
        chkconfig nagios on
        service nagios start

(4)nrpe-2.1.2解压完依次执行

./configure & make all & make install-plugin &
   make install-daemon & make install-daemon-config & make install-xinetd
       /etc/services添加一行: nrpe    5666/tcp
在/etc/xinetd.d下建立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
        allowshosts     = (允许访问的主机IP)

}
二、配置
1、主配置文件:nagios.cfg
路径:/usr/local/nagios/etc/nagios.cfg
定义文件名及所在路径:

 cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/linux.cfg (自定义,Linux主机监控)
cfg_file=/usr/local/nagios/etc/objects/windows.cfg (自定义,windows主机监控)

以上文件可根据习惯自定义,甚至所有条目都写到一个文件里也可,定义后的文件必须存在,若nagios在启动时检测不到以上文件的存在,将无法启动。不需要的可注释掉。
在配置完成后重启nagios,若有错误可以用

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

来检测错误所在行。
2、主机和组配置
定义被监控的主机和组:
在上面linux.cfg和windows.cfg里可自定义主机和组,例linux.cfg:

define hostgroup{
        hostgroup_name  linux Servers
        alias           Linux Servers
        members 192.168.1.220
     }
define host{
        use                    linux-servers
        host_name              192.168.1.220
        alias                   FTP Server
        address                 192.168.1.220
max_check_attempts      5   #认为失败前的最多检查次数
        check_interval           3   #检测间隔分钟
        retry_interval            1   #检测失败后重检测的间隔
}

windows server也同样方式定义。
3、 客户机配置
1)Linux
Linux客户机同样安装nagios-plugins和nrpe,在/etc/xinetd.d/nrpe里,加入监控主机访问权限。
2)windows
Windows主机需要安装NSClient++插件,安装过程中,需要填入监控主机IP。
配置:安装完成后,修改nsc.ini如下:
[modules]模块,将除CheckWMI.dll和RemoteConfiguration.dll外的所有dll文件名前的注释(;)去掉。
[Settings]模块, allowed_hosts=(监控主机IP);空白表示所有的主机都可以连接上来
[NSClient]处的allowed_hosts不需要设定
设置完成后重启NSClient++服务
三、监控配置
1)Linux监控:
(1)监控特定服务进程
(常用:dhcp ,dns,ftp,http,imap,mysql, oracle,smtp,snmp,ssh等,这些特定进程的监控命令带有-H参数,可以指定IP直接监控远程机器)
如果监控ftp服务,先要对commands.cfg里对check_ftp命令进行配置:

define command{
             command_name    check_ftp
             command_line    $USER1$/check_ftp -H $HOSTADDRESS$ $ARG1$
             }

# check_ftp是nrpe插件所带的命令,路径/usr/local/nagios/libexec/
然后对linux.cfg配置:

define service{
        use                             local-service
        host_name                       192.168.1.220
        service_description                 check_ftp
        check_command                   check_ftp
        }  #监控ftp,在commands.cfg里设置

(2)监控自定义进程(check_procs)
监控任意自定义进程时需要用check_procs命令查找相应进程名称,但这个check_procs只能监控本机进程无法远程监控,需要通过check_nrpe命令调用被监控端的check_procs,被监控端的监控命令可以在nrpe.cfg定义,比如监控crond可以在被监控机上自定义一个check_crond命令如下

command[check_crond]=/usr/local/nagios/libexec/check_procs -w 2:4 -c 1:8 -C crond

#意义:-w:waning区域,如果不在这个范围内,报warning
-c:critical区域,如果不在这个范围内,报critrial
然后在监控主机commands.cfg定义一个check_nrpe 的command如下:

define command{
    command_name check_nrpe
    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        } #默认存在

在配置文件如linux.cfg定义监控条目如下:

define service{
        use                             local-service
        host_name                       192.168.1.220
        service_description                check_crond
        check_command                  check_nrpe!check_crond
        }

需要用check_procs远程调用的监控,常用的有:disk,CPU,memory,其中memory监控脚本可在官方页面单独下载。
2)windows:
监控windows上的服务和进程,需要先对commands.cfg配置check_nt:

define command{
        command_name    check_nt
        command_line    $USER1$/check_nt -H $HOSTADDRESS$ -p 12489 -s password -v $ARG1$ $ARG2$
        }

然后配置windows.cfg,例如监控Server服务和firefox.exe进程,需要加入以下:

define service{
        use                  generic-service
        host_name            192.168.17.1
        service_description     Server Service
        check_command       check_nt!SERVICESTATE!-d SHOWALL -l Server
 }
define service{
        use                    generic-service
        hostgroup_name          windows-servers
        host_name              192.168.17.1
        service_description     firefox
        check_command       check_nt!PROCSTATE!-d SHOWALL -l firefox.exe
        }

#这里调用的nrpe的check_nt命令,!!中间的SERVICESTATE和PROCSTATE分别代表检测service和process的状态。另外常用的还有:
CPULOAD:CPU使用
USEDDISKSPACE:硬盘使用
MEMUSE:内存使用
四、WEB查看
http://IP/nagios,访问监控页面。用户名和密码:
htpasswd -c /usr/local/nagios/etc/htpasswd.users建立的那一个。

无觅相关文章插件,快速提升流量

Copyright © Dbabc.Net All Rights Reserved. 本站内容仅代表个人观点, 与其他任何组织或公司无关

-The End-
  • 暂无相关日志

发表评论


*

为你保密









Copyright © Dbabc.Net All Rights Reserved. 本站内容仅代表个人观点, 与其他任何组织或公司无关

Powered by Wordpress and Theme by WPYOU