一、前言
NRPE是Nagios的一个扩展插件,可以让Nagios在远程的监控主机本地触发执行相应的检测命令,从而获取远端被监控主机的本地性能的相关参数。
NRPE插件的组成分为两部分:安装在监控主机上的check_nrpe插件和运行在远程被监控主机上的nrpe daemon进程。
NRPE工作流程图其工作流程大致为:
1、nagios监控主机会运行本地的check_nrpe插件来连接到远端被监控主机上的nrpe daemon,并告知它需要对哪些资源或服务进行检测。
2、远程被监控主机的NRPE daemon会运行本地的各种nagios插件来完成对本地指定服务和资源的监测。
3、NRPE daemon将检查的结果返回给nagios监控主机的check_nrpe插件,然后该插件将结果送到nagios状态队列中等待显示。
nagios的安装可参考官方说明:https://support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html#CentOS
二、在远程主机安装配置Nagios-plugins和NRPE daemon
1、添加nagios用户
[root@localhost ~]# useradd -s /sbin/nologin nagios
2、安装nagios-plugins插件
[root@localhost ~]# yum -y install gcc gcc-c++ make openssl openssl-devel
[root@localhost ~]# cd /usr/local/src/ #事先下载相应的插件包
[root@localhost src]# tar zxf nagios-plugins-2.2.1.tar.gz
[root@localhost src]# cd nagios-plugins-2.2.1
[root@localhost nagios-plugins-2.2.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@localhost nagios-plugins-2.2.1]# make && make install
3、配置安装NRPE
[root@localhost nagios-plugins-2.2.1]# cd ..
[root@localhost src]# tar zxf nrpe-3.2.1.tar.gz
[root@localhost src]# cd nrpe-3.2.1
[root@localhost nrpe-3.2.1]# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
[root@localhost nrpe-3.2.1]# make all
[root@localhost nrpe-3.2.1]# make install-plugin
[root@localhost nrpe-3.2.1]# make install-daemon
[root@localhost nrpe-3.2.1]# make install-config
[root@localhost nrpe-3.2.1]# vim /usr/local/nagios/etc/nrpe.cfg
[root@localhost nrpe-3.2.1]# grep ^[a-Z] /usr/local/nagios/etc/nrpe.cfg
log_facility=daemon
debug=0
pid_file=/usr/local/nagios/var/nrpe.pid
server_port=5666 #配置nagios的监听端口
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=10.10.10.8 #允许nagios监控主机访问
dont_blame_nrpe=0
allow_bash_command_substitution=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 -r -w .15,.10,.05 -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
4、启动NRPE
#以守护进程的方式启动NRPE
[root@localhost nrpe-3.2.1]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@localhost nrpe-3.2.1]# netstat -tunlp | grep nrpe
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 1525/nrpe
tcp 0 0 :::5666 :::* LISTEN 1525/nrpe
另外也可以自行编写脚本启动NRPE,如:
[root@localhost nrpe-3.2.1]# vim /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
[root@localhost nrpe-3.2.1]# vim /etc/init.d/nrped
[root@localhost nrpe-3.2.1]# chmod +x /etc/init.d/nrped
[root@localhost nrpe-3.2.1]# chkconfig --add nrped
[root@localhost nrpe-3.2.1]# chkconfig nrped on
[root@localhost nrpe-3.2.1]# service nrped start
[root@localhost nrpe-3.2.1]# netstat -tunlp | grep nrpe
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 25859/nrpe
tcp 0 0 :::5666 :::* LISTEN 25859/nrpe
三、在监控端安装NRPE
1、安装NRPE
[root@localhost src]# tar zxf nrpe-3.2.1.tar.gz
[root@localhost src]# cd nrpe-3.2.1
[root@localhost nrpe-3.2.1]# ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
[root@localhost nrpe-3.2.1]# make all
[root@localhost nrpe-3.2.1]# make install-plugin
#安装完成后,会在Nagios安装目录的libexec下生成check_nrpe的插件
[root@localhost nrpe-3.2.1]# ll /usr/local/nagios/libexec/check_nrpe
-rwxrwxr-x. 1 nagios nagios 132392 Jul 20 03:38 /usr/local/nagios/libexec/check_nrpe
#能通过check_nrpe查看远程主机的NRPE版本则说明安装正常
[root@localhost nrpe-3.2.1]# /usr/local/nagios/libexec/check_nrpe -H 10.10.10.11
NRPE v3.2.1
2、定义NRPE监控命令
[root@localhost nrpe-3.2.1]# cd /usr/local/nagios/etc/objects/
[root@localhost objects]# vim commands.cfg
#增加下述命令道文件末尾
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H "$HOSTADDRESS$" -c "$ARG1$"
}
3、定义监控主机及监控服务
[root@localhost objects]# vim newlinux.cfg
define host{ #定义远程主机
use linux-server
host_name newlinux
alias Linux Server
address 10.10.10.11
}
define service{ #定义远程主机监控的资源服务
use generic-service
host_name newlinux
service_description CHECK USER
check_command check_nrpe!check_users
}
define service{
use generic-service
host_name newlinux
service_description Load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name newlinux
service_description SDA1
check_command check_nrpe!check_hda1
}
define service{
use generic-service
host_name newlinux
service_description Zombie
check_command check_nrpe!check_zombie_procs
}
define service{
use generic-service
host_name newlinux
service_description Total procs
check_command check_nrpe!check_total_procs
}
此处定义的NRPE监控的资源服务是根据被监控主机的NRPE配置文件中内置的监控命令来编写的,如:
[root@localhost nrpe-3.2.1]# vim /usr/local/nagios/etc/nrpe.cfg
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -r -w .15,.10,.05 -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
3、调用监控主机配置文件
#在nagios监控主机中的配置文件中添加下述配置,此配置可添加多行
[root@localhost objects]# vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/newlinux.cfg
4、检查配置文件
[root@localhost objects]# service nagios configtest
5、重启nagios服务
root@localhost objects]# service nagios restart
此时登录http://IP/nagios/ 访问nagios web管理界面应该能正常查看到监控的Linux主机。
监控状态
网友评论