作为Nagios的一个扩展功能插件,NRPE可在远程的linux主机上执行的插件程序。远程的liux服务器通过安装NRPE及Nagios的相关插件程序可以向Nagios服务端监控平台提供自身的情况例如:CPU负载,内存使用以及磁盘使用等情况。这里依旧将node1.cn主机作为Nagios监控端,node2.cn作为被监控端。
一、NRPE简介
Nrpe作为Nagios的一个扩展功能,其可以在远程Linux主机上执行插件程序,通过远程服务器自身安装的NRPE插件和Nagios插件程序向Nagios监控平台提供自身负载:CPU负载,内存使用以及磁盘使用等等。
NRPE作为Nagios远程主机监控插件,它被用于让Nagios监控端基于安装的方式触发远端主机检测指令,并发送给Nagios监控端。且执行开销低于SS和的检查方式,并由检测过程不需要远程主机上的系统账号信息,因此安全性方面优于SSH的检测方式。
1.1 NRPE工作原理
NRPE构成:
check_nrpe:位于监控主机
nrpe daemon:位于远程主机(npre daemon需要Nagios-plugins插件的支持,否则daemon在远程主机无效)
Nagios监控某个远程linux主机的服务或资源的过程如下:
第一:Nagios运行check_nrpe插件,使nrpe知道需要做什么检查;
第二:check_nrpe插件会链接到远程的daemon,所用的方式是SSL;
第三:NRPE daemon运行相应Nagios插件执行相关检查;
最后:NRPE daemon将检查结果返回check_nrpe插件,进而check_nrpe将结果递交给Nagios进行处理。
二、远程主机Nagios-plugins插件和NRPE的安装
2.1添加运行用户nagios
2.2安装nagios-plugins插件
1
2
3
4
5
6
|
[root@node2 src]
[root@node2 src]
[root@node2 src]
[root@node2 src]
[root@node2 nagios-plugins-2.2.1]
[root@node2 nagios-plugins-2.2.1]
|
2.3安装nrpe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@node2 src]
[root@node2 src]
[root@node2 nrpe-2.15]
*** Configuration summary for nrpe 2.15 09-06-2013 ***:
General Options:
-------------------------
NRPE port: 5666
NRPE user: nagios
NRPE group: nagios
Nagios user: nagios
Nagios group: nagios
Review the options above for accuracy. If they look okay,
type 'make all' to compile the NRPE daemon and client.
[root@node2 nrpe-2.15]
[root@node2 nrpe-2.15]
cd . /src/ && make install -plugin
[root@node2 nrpe-2.15]
cd . /src/ && make install -daemon
[root@node2 nrpe-2.15]
|
2.4 配置NRPE
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
[root@node2 ~]
log_facility=daemon
pid_file= /var/run/nrpe .pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1,192.168.31.101
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
|
2.5 NRPE守护进程启动
1
2
3
4
|
[root@node2 ~]
[root@node2 ~]
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 26018 /nrpe
tcp 0 0 :::5666 :::* LISTEN 26018 /nrpe
|
NRPE的运行模式:
1
2
3
|
-i = Run as a service under inetd or xinetd
-d = Run as a standalone daemon
-d -s = Run as a subsystem under AIX
|
2.6 nrpe启动脚本的编辑
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
|
[root@node2 ~]
NPRE= /usr/local/nagios/bin/nrpe
NRPECFG= /usr/local/nagios/etc/nrpe .cfg
case "$1" in
start)
echo -n "Starting NPRE daemon..."
${NPRE} -c ${NRPECFG} -d
echo "Start NPRE daemon done..."
;;
stop)
echo -n "stopping NRPE daemon..."
pkill -u nagios nrpe
echo "Stop NPRE daemon done..."
;;
restart)
$0 stop
sleep 3
$0 start
;;
*)
echo "Usage:$0 start|stop|restart"
;;
esac
exit 0
|
2.7 nrped脚本测试和设置nrped服务开机启动启动
1
2
3
4
5
6
7
|
[root@node2 ~]
[root@node2 ~]
stopping NRPE daemon...Stop NPRE daemon done ...
Starting NPRE daemon...Start NPRE daemon done ...
[root@node2 ~]
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 26085 /nrpe
tcp 0 0 :::5666 :::* LISTEN 26085 /nrpe
|
3 Nagios服务端安装NRPE
1
2
3
4
5
6
|
[root@node1 src]
[root@node1 nrpe-2.15]
[root@node1 nrpe-2.15]
[root@node1 nrpe-2.15]
[root@node1 nrpe-2.15]
/usr/local/nagios/libexec/check_nrpe
|
3.1 关于check_nrpe的一些用法
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
|
[root@node1 libexec]
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 <host> [ -b <bindaddr> ] [-4] [-6] [-n] [-u] [-p <port>] [-t <timeout>] [-c < command >] [-a <arglist...>]
Options:
-n = Do no use SSL
-u = Make socket timeouts return an UNKNOWN state instead of CRITICAL
<host> = The address of the host running the NRPE daemon
<bindaddr> = bind to local address
-4 = user ipv4 only
-6 = user ipv6 only
[port] = The port on which the daemon is running (default=5666)
[timeout] = Number of seconds before connection times out (default=10)
[ command ] = The name of the command that the remote daemon should run
[arglist] = Optional arguments that should be passed to the command . Multiple
arguments should be separated by a space. If provided, this must be
the last option supplied on the command line.
Note:
This plugin requires that you have the NRPE daemon running on the remote host.
You must also have configured the daemon to associate a specific plugin command
with the [ command ] option you are specifying here. Upon receipt of the
[ command ] argument, the NRPE daemon will run the appropriate plugin command and
send the plugin output and return code back to *this* plugin. This allows you
to execute plugins on remote hosts and 'fake' the results to make Nagios think
the plugin is being run locally.
|
相关语法格式:
1
2
3
|
[root@node1 libexec]
[root@node1 libexec]
NRPE v2.15
|
3.2 定义相关命令
[root@node1 libexec]# cd /usr/local/nagios/etc/objects/
添加内容到commands.cfg末尾
[root@node1 objects]# vim commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_npre -H "$HOSTADDRESS$" -c "$ARG1$"
}
3.3 添加nagios.cfg配置文件内容
1
2
|
[root@node1 objects]
cfg_file= /usr/local/nagios/etc/objects/linehost .cfg
|
3.4 定义主机linehost.cfg和服务service.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@node1 objects]
define host{
use linux-server ; Name of host template to use
; This host definition will inherit all variables that are defined
; in (or inherited by) the linux-server host template definition.
host_name linehost
alias linehost
address 192.168.31.102
}
define hostgroup{
hostgroup_name my-linux-servers ; The name of the hostgroup
alias My Linux Servers ; Long name of the group
members linehost ; Comma separated list of hosts that belong to this group
}
[root@node1 objects]
define service{
use local -service
host_name linehost
service_groups MysqlGroup
service_description MySqlSev
|
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
|
check_command check_mysql
}
define service{
use local -service ; Name of service template to use
host_name linehost
service_description PING
check_commandcheck_ping!100.0,20%!500.0,60%
}
define service{
use local -service ; Name of service template to use
host_name linehost
service_description Root Partition
check_commandcheck_local_disk!20%!10%!/
}
define service{
use local -service ; Name of service template to use
host_name linehost
service_description Current Users
check_commandcheck_local_users!20!50
}
define service{
use local -service ; Name of service template to use
host_name linehost
service_description Total Processes
check_commandcheck_local_procs!250!400!RSZDT
}
检查配置文件
[root@node1 objects]
无错误信息重启服务
[root@node1 objects]
|
web端进行查看验证
Nagios通过NRPE对远程linux服务器监控就介绍到这里,下一章将介绍Nagios对windowns主机的监控以及的邮件报警功能的配置
博文出自:http://os.51cto.com/art/201409/452605.htm
本文转自 CARYFLASH 51CTO博客,原文链接:http://blog.51cto.com/maoxiaoxiong/1980787