nagios系列(三)之nagios被动监控模式之添加系统负载load、swap、磁盘iostat及memory内存监控详解

环境:
nagios server:192.168.8.42 host_name:node4.chinasoft.com
nagios client:192.168.8.41 host_name:node3.chinasoft.com


1.编辑nagios.cfg文件
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


注释掉
# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg


2.生成hosts.cfg和service.cfg文件
cd /usr/local/nagios/etc/objects/
head -50 localhost.cfg >hosts.cfg
chown nagios.nagios hosts.cfg


# touch service.cfg
[root@node4 objects]# chown -R nagios.nagios service.cfg 


3.编辑hosts.cfg、service.cfg增加被监控的主机


define host{
use linux-server
    host_name node4.chinasoft.com
alias node4.chinasoft.com
address 192.168.8.42
}
define host{
        use             linux-server
        host_name       node3.chinasoft.com
        alias           node3.chinasoft.com
        address         192.168.8.41
}


# Define an optional hostgroup for Linux machines


define hostgroup{
        hostgroup_name  linux-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         node4.chinasoft.com,node3.chinasoft.com     ; Comma separated list of hosts that belong to this group
        }


编辑service文件
vim service.cfg 
define service{
use generic-service
host_name node3.chinasoft.com,node4.chinasoft.com
service_descriptiondisk partition
check_command check_nrpe!check_disk
}


编辑commands.cfg添加check_nrpe命令
# 'check_nrpe" command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}


4.编辑nagios启动脚本,打开报错日志
vim /etc/init.d/nagios
改为:$NagiosBin -v $NagiosCfgFile


检测语法是否正确
/etc/init.d/nagios checkconfig
或者
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 


5.开启jack用户的访问权限
sed -i 's#nagiosadmin#jack#g' /usr/local/nagios/etc/cgi.cfg


6.client的配置
编辑/usr/local/nagios/etc/cgi.cfg,运行服务端连接
allowed_hosts=127.0.0.1,192.168.8.42


报错:
Connection refused by host 
排错:
/usr/local/nagios/libexec/check_nrpe -H 192.168.8.42 -c check_disk
NRPE: Command 'check_disk' not defined
check_disk命令没有定义
增加相关定义即可,如下:
cp /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg.ori
sed -i '199,203d' /usr/local/nagios/etc/nrpe.cfg


echo "command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,6 -c 30,25,20">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -w 6% -c 3%">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 8% -p /">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 6 -c 10">>/usr/local/nagios/etc/nrpe.cfg


重启nrpe服务
pkill nrpe
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
# ps -ef|grep nrpe
nagios   52207     1  0 15:39 ?        00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
root     52209  1703  0 15:39 pts/0    00:00:00 grep nrpe


在客户端执行命令:
# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_disk
DISK OK - free space: / 16337 MB (87% inode=95%);| /=2348MB;15748;18110;0;19685
[root@node4 etc]# /usr/local/nagios/libexec/check_nrpe -H 192.168.8.42 -c check_disk
DISK OK - free space: / 16337 MB (87% inode=95%);| /=2348MB;15748;18110;0;19685


通过直接执行相关的脚本可以看出是否ok:/usr/local/nagios/libexec/check_disk -w 20% -c 8% -p /


7、添加新的监控项目:

vim /usr/local/nagios/etc/objects/service.cfg添加相应的监控项即可(监控的check_command必须要和客户端的nrpe.cfg中定义的一致)




define service{
        use generic-service
        host_name node3.chinasoft.com,node4.chinasoft.com
        service_description     memory
        check_command   check_nrpe!check_mem
}
define service{
        use generic-service
        host_name node3.chinasoft.com,node4.chinasoft.com
        service_description     load
        check_command   check_nrpe!check_load
}






posted @ 2016-07-21 20:11  reblue520  阅读(429)  评论(0编辑  收藏  举报