前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >NRPE介绍

NRPE介绍

作者头像
sunsky
发布2020-08-20 11:14:49
8630
发布2020-08-20 11:14:49
举报
文章被收录于专栏:sunskysunsky

一、简介

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
wKioL1Qm3NLBZZSnAAHCItyFxXI201.jpg

2、NRPE的工作原理

NRPE有两部分组成

check_nrpe插件:位于监控主机上

nrpe daemon:运行在远程主机上,通常是被监控端agent

注意:nrpe daemon需要Nagios-plugins插件的支持,否则daemon不能做任何监控

wKioL1Qm2krywnxLAACf2VJUtQI655.jpg
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. [root@ClientNrpe ~]# useradd -s /sbin/nologin nagios

2、安装nagios-plugins,因为NRPE依赖此插件

  1. [root@ClientNrpe ~]# yum -y install gcc gcc-c++ make openssl openssl-devel
  2. [root@ClientNrpe ~]# tar xf nagios-plugins-2.0.3.tar.gz
  3. [root@ClientNrpe ~]# cd nagios-plugins-2.0.3
  4. [root@ClientNrpe nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
  5. [root@ClientNrpe nagios-plugins-2.0.3]# make && make install
  6. #注意:如何要监控mysql 需要添加 --with-mysql

3、安装NRPE

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

4、配置NRPE

  1. [root@ClientNrpe ~]# grep -v '^#' /usr/local/nagios/etc/nrpe.cfg |sed '/^$/d'
  2. log_facility=daemon
  3. pid_file=/var/run/nrpe.pid
  4. server_port=5666 #监听的端口
  5. nrpe_user=nagios
  6. nrpe_group=nagios
  7. allowed_hosts=192.168.0.105 #允许的地址通常是Nagios服务器端
  8. dont_blame_nrpe=0
  9. allow_bash_command_substitution=0
  10. debug=0
  11. command_timeout=60
  12. connection_timeout=300
  13. command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
  14. command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
  15. command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
  16. command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
  17. command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

5、启动NRPE

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

有两种方式用于管理nrpe服务,nrpe有两种运行模式:

  1. -i # Run as a service under inetd or xinetd
  2. -d # Run as a standalone daemon

可以为nrpe编写启动脚本,使得nrpe以standard alone方式运行:

  1. [root@ClientNrpe ~]# cat /etc/init.d/nrped
  2. #!/bin/bash
  3. # chkconfig: 2345 88 12
  4. # description: NRPE DAEMON
  5. NRPE=/usr/local/nagios/bin/nrpe
  6. NRPECONF=/usr/local/nagios/etc/nrpe.cfg
  7. case "$1" in
  8. start)
  9. echo -n "Starting NRPE daemon..."
  10. $NRPE -c $NRPECONF -d
  11. echo " done."
  12. ;;
  13. stop)
  14. echo -n "Stopping NRPE daemon..."
  15. pkill -u nagios nrpe
  16. echo " done."
  17. ;;
  18. restart)
  19. $0 stop
  20. sleep 2
  21. $0 start
  22. ;;
  23. *)
  24. echo "Usage: $0 start|stop|restart"
  25. ;;
  26. esac
  27. exit 0
  28. [root@ClientNrpe ~]# chmod +x /etc/init.d/nrped
  29. [root@ClientNrpe ~]# chkconfig --add nrped
  30. [root@ClientNrpe ~]# chkconfig nrped on
  31. [root@ClientNrpe ~]# service nrped start
  32. Starting NRPE daemon... done.
  33. [root@ClientNrpe ~]# netstat -tnlp
  34. Active Internet connections (only servers)
  35. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  36. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1031/sshd
  37. tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1108/master
  38. tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 22597/nrpe
  39. tcp 0 0 :::22 :::* LISTEN 1031/sshd
  40. tcp 0 0 ::1:25 :::* LISTEN 1108/master
  41. tcp 0 0 :::5666 :::* LISTEN 22597/nrpe

三、监控端安装NRPE

1、安装NRPE

  1. [root@Nagios ~]# tar xf nrpe-2.15.tar.gz
  2. [root@Nagios ~]# cd nrpe-2.15
  3. [root@Nagios nrpe-2.15]# ./configure
  4. > --with-nrpe-user=nagios \
  5. > --with-nrpe-group=nagios \
  6. > --with-nagios-user=nagios \
  7. > --with-nagios-group=nagios \
  8. > --enable-command-args \
  9. > --enable-ssl
  10. [root@Nagios nrpe-2.15]# make all
  11. [root@Nagios nrpe-2.15]# make install-plugin
  12. #安装完成后,会在Nagios安装目录的libexec下生成check_nrpe的插件
  13. [root@Nagios ~]# cd /usr/local/nagios/libexec/
  14. [root@Nagios libexec]# ll -d check_nrpe
  15. -rwxrwxr-x. 1 nagios nagios 76769 9月 28 08:07 check_nrpe

2、check_nrpe的用法

  1. [root@Nagios libexec]# ./check_nrpe -h
  2. NRPE Plugin for Nagios
  3. Copyright (c) 1999-2008 Ethan Galstad (nagios@nagios.org)
  4. Version: 2.15
  5. Last Modified: 09-06-2013
  6. License: GPL v2 with exemptions (-l for more info)
  7. SSL/TLS Available: Anonymous DH Mode, OpenSSL 0.9.6 or higher required
  8. Usage: check_nrpe -H <host> [ -b <bindaddr> ] [-4] [-6] [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]
  9. Options:
  10. -n = Do no use SSL
  11. -u = Make socket timeouts return an UNKNOWN state instead of CRITICAL
  12. <host> = The address of the host running the NRPE daemon
  13. <bindaddr> = bind to local address
  14. -4 = user ipv4 only
  15. -6 = user ipv6 only
  16. [port] = The port on which the daemon is running (default=5666)
  17. [timeout] = Number of seconds before connection times out (default=10)
  18. [command] = The name of the command that the remote daemon should run
  19. [arglist] = Optional arguments that should be passed to the command. Multiple
  20. arguments should be separated by a space. If provided, this must be
  21. the last option supplied on the command line.
  22. Note:
  23. This plugin requires that you have the NRPE daemon running on the remote host.
  24. You must also have configured the daemon to associate a specific plugin command
  25. with the [command] option you are specifying here. Upon receipt of the
  26. [command] argument, the NRPE daemon will run the appropriate plugin command and
  27. send the plugin output and return code back to *this* plugin. This allows you
  28. to execute plugins on remote hosts and 'fake' the results to make Nagios think
  29. the plugin is being run locally.

通过NRPE监控远程Linux主机要使用chech_nrpe插件进行,其语法格式如下:

  1. check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]
  2. [root@Nagios libexec]# ./check_nrpe -H 192.168.0.81
  3. NRPE v2.15

3、定义命令

  1. [root@Nagios ~]# cd /usr/local/nagios/etc/objects/
  2. [root@Nagios objects]# vim commands.cfg
  3. #增加到末尾行
  4. define command{
  5. command_name check_nrpe
  6. command_line $USER1$/check_nrpe -H "$HOSTADDRESS$" -c "$ARG1$"
  7. }

4、定义服务

  1. [root@Nagios objects]# cp windows.cfg linhost.cfg
  2. [root@Nagios objects]# grep -v '^#' linhost.cfg |sed '/^$/d'
  3. define host{
  4. use linux-server
  5. host_name linhost
  6. alias My Linux Server
  7. address 192.168.0.81
  8. }
  9. define service{
  10. use generic-service
  11. host_name linhost
  12. service_description CHECK USER
  13. check_command check_nrpe!check_users
  14. }
  15. define service{
  16. use generic-service
  17. host_name linhost
  18. service_description Load
  19. check_command check_nrpe!check_load
  20. }
  21. define service{
  22. use generic-service
  23. host_name linhost
  24. service_description SDA1
  25. check_command check_nrpe!check_hda1
  26. }
  27. define service{
  28. use generic-service
  29. host_name linhost
  30. service_description Zombie
  31. check_command check_nrpe!check_zombie_procs
  32. }
  33. define service{
  34. use generic-service
  35. host_name linhost
  36. service_description Total procs
  37. check_command check_nrpe!check_total_procs
  38. }

这里重点说下,Nagios服务端定义服务的命令完全是根据被监控端NRPE中内置的监控命令,如下图所示

wKioL1QnZhGQMN-ZAAM_Km8AoXQ787.jpg
wKioL1QnZhGQMN-ZAAM_Km8AoXQ787.jpg

5、启动所定义的命令和服务

  1. [root@Nagios ~]# vim /usr/local/nagios/etc/nagios.cfg
  2. #增加一行
  3. cfg_file=/usr/local/nagios/etc/objects/linhost.cfg

6、配置文件语法检查

  1. [root@Nagios ~]# service nagios configtest
  2. Nagios Core 4.0.7
  3. Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
  4. Copyright (c) 1999-2009 Ethan Galstad
  5. Last Modified: 06-03-2014
  6. License: GPL
  7. Website: http://www.nagios.org
  8. Reading configuration data...
  9. Read main config file okay...
  10. Read object config files okay...
  11. Running pre-flight check on configuration data...
  12. Checking objects...
  13. Checked 20 services.
  14. Checked 3 hosts.
  15. Checked 2 host groups.
  16. Checked 0 service groups.
  17. Checked 1 contacts.
  18. Checked 1 contact groups.
  19. Checked 26 commands.
  20. Checked 5 time periods.
  21. Checked 0 host escalations.
  22. Checked 0 service escalations.
  23. Checking for circular paths...
  24. Checked 3 hosts
  25. Checked 0 service dependencies
  26. Checked 0 host dependencies
  27. Checked 5 timeperiods
  28. Checking global event handlers...
  29. Checking obsessive compulsive processor commands...
  30. Checking misc settings...
  31. Total Warnings: 0
  32. Total Errors: 0
  33. Things look okay - No serious problems were detected during the pre-flight check
  34. Object precache file created:
  35. /usr/local/nagios/var/objects.precache

7、重新启动nagios服务

  1. [root@Nagios ~]# service nagios restart
  2. Running configuration check...
  3. Stopping nagios: done.
  4. Starting nagios: done.

8、打开Nagios web监控页面

1)首先点击【Hosts】查看监控主机状态是否为UP

wKiom1Qm8WfyoR-sAAF5rctJNZ8410.jpg
wKiom1Qm8WfyoR-sAAF5rctJNZ8410.jpg

2)其次点击【Services】查看各监控服务的状态是否为OK

注意:在监控新添加的主机linhost;出现状态为CRITICAL,提示没有那个文件或目录。下面是解决办法

wKiom1Qm8WfCZrd-AAb-FyGH-V4273.jpg
wKiom1Qm8WfCZrd-AAb-FyGH-V4273.jpg

在监控Linhost主机时出现一个CRITICAL的警告,查找解决办法

wKioL1Qm8jyzbPBcAAEWP2KVKxc476.jpg
wKioL1Qm8jyzbPBcAAEWP2KVKxc476.jpg

  1. ###被监控端修改NRPE配置文件并重启NRPE服务
  2. [root@ClientNrpe etc]# vim nrpe.cfg
  3. command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
  4. [root@ClientNrpe etc]# service nrped restart
  5. ###监控端修改linhost.cfg配置文件并重启nagios和httpd服务
  6. [root@Nagios objects]# vim linhost.cfg
  7. #注释:原来这里是hda1,现在修改成sda1
  8. define service{
  9. use generic-service
  10. host_name linhost
  11. service_description SDA1
  12. check_command check_nrpe!check_sda1
  13. }
  14. [root@Nagios ~]# service nagios restart
  15. Running configuration check...
  16. Stopping nagios: done.
  17. Starting nagios: done.
  18. [root@Nagios ~]# service httpd restart
  19. 停止 httpd: [确定]
  20. 正在启动 httpd: [确定]

再次点击【services】即为刷新页面,查看如下图所示:

wKioL1Qm9JKADd8SAAa9TVtAuVc417.jpg
wKioL1Qm9JKADd8SAAa9TVtAuVc417.jpg
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018-03-20 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
前端性能监控
前端性能监控(Real User Monitoring,RUM)是一站式前端监控解决方案,专注于 Web、小程序等场景监控。前端性能监控聚焦用户页面性能(页面测速,接口测速,CDN 测速等)和质量(JS 错误,Ajax 错误等),并且联动腾讯云应用性能监控实现前后端一体化监控。用户只需要安装 SDK 到自己的项目中,通过简单配置化,即可实现对用户页面质量的全方位守护,真正做到低成本使用和无侵入监控。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档