首页 > Nagios > CentOS 安装使用 Nagios的NRPE

CentOS 安装使用 Nagios的NRPE

2012年10月9日 发表评论 阅读评论

相关链接:

Nagios: http://www.nagios.org/
Official Nagios Plugins: http://www.nagios.org/download/plugins/
NRPE: http://www.nagios.org/download/addons

相关说明:

操作系统: CentOS 5.4
nagios plugins: 1.4.16
NRPE: 2.13

NRPE是Nagios下的一个扩展, 也可称它为被监控端的客户端, 配合Nagios可以完成各种监控与定制, Nagios在没有安装这个扩展的时候, 只能监控”监控端”本机, 它是搭建Nagios监控必不可少的一部分.
本文即讲解Nagios的NRPE安装, Nagios的安装不在本文的讨论中, 如有需要请查看本博boll(xiaobo_l)的别的文章.

安装过程:

创建账户:

groupadd nagios
useradd -g nagios -c "Nagios Server" nagios -s /sbin/nologin -M

安装nagios-plugins:

tar -xzvf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --prefix=/usr/local/nagios
make
make install

安装NRPE:

tar -xzvf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure --prefix=/usr/local/nagios
make all
make install-plugin
make install-daemon
make install-daemon-config
chown -R nagios:nagios /usr/local/nagios

修改配置文件:

#将以下'172.16.1.1'替换成nagios服务器地址
sed -i 's#^allowed_hosts=.*#allowed_hosts=172.16.1.1#gi' /usr/local/nagios/etc/nrpe.cfg

安装服务:
将下面的代码拷贝到/etc/init.d/nrpe里面

#
# chkconfig: - 81 90
# description: this script is used for nrpe
#!/bin/bash
#
#file nrpe
#change logs 2012.5.4
#by xiaobo_l
#
killproc_nagios ()
{
        kill $2 $NagiosPID
}
pid_nagios ()
{
        if test ! -f $NagiosRunFile; then
                echo "No lock file found in $NagiosRunFile"
                exit 1
        fi
        NagiosPID=`head -n 1 $NagiosRunFile`
}
function fun_start() {
                echo -n "Starting nrpe: "
                $NagiosBin -c $NagiosCfgFile -d > /dev/null 2>&1;
                if [ $? -eq 0 ]; then
                        echo "start success."
                else
                        echo "start fail"
                        exit 1
                fi
}
function fun_stop() {
                echo -n "Stopping nrpe: "
                pid_nagios
                killproc_nagios nrpe
                if [ $? -eq 0 ]; then
                        echo "stop success."
                else
                        echo "stop fail"
                        exit 1
                fi
                rm -f  $NagiosRunFile
}
# Source function library
# Solaris doesn't have an rc.d directory, so do a test first
if [ -f /etc/rc.d/init.d/functions ]; then
        . /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
        . /etc/init.d/functions
fi
prefix=/usr/local/nagios
exec_prefix=${prefix}
NagiosBin=${exec_prefix}/bin/nrpe
NagiosCfgFile=${prefix}/etc/nrpe.cfg
NagiosRunFile=/var/run/nrpe.pid
# Check that nagios exists.
if [ ! -f $NagiosBin ]; then
    echo "Executable file $NagiosBin not found.  Exiting."
    exit 1
fi
# Check that nagios.cfg exists.
if [ ! -f $NagiosCfgFile ]; then
    echo "Configuration file $NagiosCfgFile not found.  Exiting."
    exit 1
fi
# See how we were called.
case "$1" in
        start)
                fun_start
                ;;
        stop)
                fun_stop
                ;;
        status)
                pid_nagios
                echo "pid file: $NagiosRunFile"
                echo "pid: $(cat $NagiosRunFile)"
                ;;
        restart)
                fun_stop
                fun_start
                ;;
        *)
                echo "Usage: nrpe {start|stop|restart|status}"
                exit 1
                ;;
esac
# End of this script

注: 如以上代码拷贝无法使用, 请到这个地址下载脚本: http://download.boll.me/nrpe

添加服务启动:

chmod 755 /etc/init.d/nrpe
chkconfig --add nrpe
chkconfig nrpe on
service nrpe start

测试安装:

/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1

显示 NRPE v2.13说明安装成功

使用NRPE:

NRPE的被监控端默认可以使用以下几个参数:

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

可以使用以下命令来查看结果.:

/usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_load

监控端的配置文/usr/local/nagios/etc/objects/commands.cfg件加入:

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

使用NRPE监控:

define service{
           .....
        check_command                   check_nrpe!check_load
           .....
}

到此, NRPE的安装使用已经完成.



除非注明,波尔博客的文章均为原创, 转载请注明作者和出处, 谢谢合作.
博客网址: 波尔 Boll
本文链接地址: https://www.boll.me/archives/377



分类: 标签:
  1. 本文目前尚无任何评论.
  1. 本文目前尚无任何 trackbacks 和 pingbacks.