设为首页 收藏本站
查看: 1338|回复: 0

Nagios利用NRPE监控Linux主机

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-9-28 09:21:08 | 显示全部楼层 |阅读模式
一、简介

1、NRPE介绍
    NRPE是Nagios的一个功能扩展,它可在远程Linux/Unix主机上执行插件程序。通过在远程服务器上安装NRPE插件及Nagios插件程序来向Nagios监控平台提供该服务器的本地情况,如CPU负载,内存使用,磁盘使用等。这里将Nagios监控端称为Nagios服务器端,而将远程被监控的主机称为Nagios客户端。

    Nagios监控远程主机的方法有多种,其方式包括SNMP,NRPE,SSH,NCSA等。这里介绍其通过NRPE监控远程Linux主机的方式。
    NRPE(Nagios Remote Plugin Executor)是用于在远端服务器上运行监测命令的守护进程,它用于让Nagios监控端基于安装的方式触发远端主机上的检测命令,并将检测结果返回给监控端。而其执行的开销远低于基于SSH的检测方式,而且检测过程不需要远程主机上的系统账号信息,其安全性也高于SSH的检测方式。
wKioL1Qm3NLBZZSnAAHCItyFxXI201.jpg

2、NRPE的工作原理
NRPE有两部分组成
check_nrpe插件:位于监控主机上
nrpe daemon:运行在远程主机上,通常是被监控端agent
注意:nrpe daemon需要Nagios-plugins插件的支持,否则daemon不能做任何监控
wKioL1Qm2krywnxLAACf2VJUtQI655.jpg
详细的介绍NRPE的工作原理
当Nagios需要监控某个远程Linux主机的服务或者资源情况时:
首先:Nagios会运行check_nrpe这个插件,告诉它要检查什么;
其次:check_nrpe插件会连接到远程的NRPE daemon,所用的方式是SSL;
然后:NRPE daemon 会运行相应的Nagios插件来执行检查;
最后:NRPE daemon 将检查的结果返回给check_nrpe 插件,插件将其递交给nagios做处理。

二、被监控端安装Nagios-plugins插件和NRPE
1、添加nagios用户
1
[iyunv@ClientNrpe ~]# useradd -s /sbin/nologin nagios



2、安装nagios-plugins,因为NRPE依赖此插件
1
2
3
4
5
6
7
8
[iyunv@ClientNrpe ~]# yum -y install gcc gcc-c++ make openssl openssl-devel

[iyunv@ClientNrpe ~]# tar xf nagios-plugins-2.0.3.tar.gz
[iyunv@ClientNrpe ~]# cd nagios-plugins-2.0.3
[iyunv@ClientNrpe nagios-plugins-2.0.3]# ./configure  --with-nagios-user=nagios --with-nagios-group=nagios
[iyunv@ClientNrpe nagios-plugins-2.0.3]# make && make install

#注意:如何要监控mysql 需要添加 --with-mysql



3、安装NRPE

1
2
3
4
5
6
7
8
9
10
11
12
[iyunv@ClientNrpe ~]# tar xf nrpe-2.15.tar.gz
[iyunv@ClientNrpe ~]# cd nrpe-2.15
[iyunv@ClientNrpe nrpe-2.15]# ./configure --with-nrpe-user=nagios
> --with-nrpe-group=nagios
> --with-nagios-user=nagios
> --with-nagios-group=nagios
> --enable-command-args
> --enable-ssl
[iyunv@ClientNrpe nrpe-2.15]# make all
[iyunv@ClientNrpe nrpe-2.15]# make install-plugin
[iyunv@ClientNrpe nrpe-2.15]# make install-daemon
[iyunv@ClientNrpe nrpe-2.15]# make install-daemon-config



4、配置NRPE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[iyunv@ClientNrpe ~]# grep -v '^#' /usr/local/nagios/etc/nrpe.cfg |sed '/^$/d'
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666             #监听的端口
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=192.168.0.105   #允许的地址通常是Nagios服务器端
  
dont_blame_nrpe=0
allow_bash_command_substitution=0
debug=0
command_timeout=60
connection_timeout=300
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




5、启动NRPE
1
2
3
4
5
#以守护进程的方式启动
[iyunv@ClientNrpe ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[iyunv@ClientNrpe ~]# netstat -tulpn | grep nrpe
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      22597/nrpe         
tcp        0      0 :::5666                     :::*                        LISTEN      22597/nrpe




有两种方式用于管理nrpe服务,nrpe有两种运行模式:
1
2
-i        # Run as a service under inetd or xinetd
-d        # Run as a standalone daemon




可以为nrpe编写启动脚本,使得nrpe以standard alone方式运行:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
[iyunv@ClientNrpe ~]# cat /etc/init.d/nrped
#!/bin/bash
# chkconfig: 2345 88 12
# description: NRPE DAEMON

NRPE=/usr/local/nagios/bin/nrpe
NRPECONF=/usr/local/nagios/etc/nrpe.cfg

case "$1" in
    start)
        echo -n "Starting NRPE daemon..."
        $NRPE -c $NRPECONF -d
        echo " done."
        ;;
    stop)
        echo -n "Stopping NRPE daemon..."
        pkill -u nagios nrpe
        echo " done."
    ;;
    restart)
        $0 stop
        sleep 2
        $0 start
        ;;
    *)
        echo "Usage: $0 start|stop|restart"
        ;;
    esac
exit 0
[iyunv@ClientNrpe ~]# chmod +x /etc/init.d/nrped
[iyunv@ClientNrpe ~]# chkconfig --add nrped
[iyunv@ClientNrpe ~]# chkconfig nrped on

[iyunv@ClientNrpe ~]# service nrped start
Starting NRPE daemon... done.
[iyunv@ClientNrpe ~]# netstat -tnlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1031/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1108/master         
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      22597/nrpe         
tcp        0      0 :::22                       :::*                        LISTEN      1031/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1108/master         
tcp        0      0 :::5666                     :::*                        LISTEN      22597/nrpe





三、监控端安装NRPE
1、安装NRPE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[iyunv@Nagios ~]# tar xf nrpe-2.15.tar.gz
[iyunv@Nagios ~]# cd nrpe-2.15
[iyunv@Nagios nrpe-2.15]# ./configure
> --with-nrpe-user=nagios
> --with-nrpe-group=nagios
> --with-nagios-user=nagios
> --with-nagios-group=nagios
> --enable-command-args
> --enable-ssl
[iyunv@Nagios nrpe-2.15]# make all
[iyunv@Nagios nrpe-2.15]# make install-plugin

#安装完成后,会在Nagios安装目录的libexec下生成check_nrpe的插件
[iyunv@Nagios ~]# cd /usr/local/nagios/libexec/
[iyunv@Nagios libexec]# ll -d check_nrpe
-rwxrwxr-x. 1 nagios nagios 76769 9月  28 08:07 check_nrpe




2、check_nrpe的用法
[iyunv@Nagios libexec]# ./check_nrpe -h

NRPE Plugin for Nagios
Copyright (c) 1999-2008 Ethan Galstad (nagios@nagios.org)
Version: 2.15
Last Modified: 09-06-2013
License: GPL v2 with exemptions (-l for more info)
SSL/TLS Available: Anonymous DH Mode, OpenSSL 0.9.6 or higher required

Usage: check_nrpe -H  [ -b  ] [-4] [-6] [-n] [-u] [-p ] [-t ] [-c
wKioL1Qm8jyzbPBcAAEWP2KVKxc476.jpg
wKiom1Qm8WfCZrd-AAb-FyGH-V4273.jpg
wKiom1Qm8WfyoR-sAAF5rctJNZ8410.jpg

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-25436-1-1.html 上篇帖子: nagios-plugin(mem) 下篇帖子: Nagios利用NSClient++监控Windows主机 Linux 监控 主机
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表