Linux上Nagios安装配置初入门(2)

NRPE(Nagios Remote Plugin Executor)是用于在远端服务器上运行检测命令的守护进程,它用于让Nagios监控端基于安装的方式触发远端主机上的检测命令,并将检测结果输出至监控端。而其执行的开销远低于基于SSH的检测方式,而且检测过程并不需要远程主机上的系统帐号等信息,其安全性也高于SSH的检测方式。

2、安装配置被监控端
(1)添加nagios用户

# useradd -s /sbin/nologin nagios

(2)NRPE依赖于nagios-plugins,因此,需要先安装之

# tar xvf nagios-plugins-2.1.1.tar.gz -C /usr/local/src/ # cd /usr/local/src/nagios-plugins-2.1.1/ # ./configure --with-nagios-user=nagios --with-nagios-group=nagios # make all # make install

(3)安装NRPE

# tar xvf nrpe-3.0.tar.gz -C /usr/local/src/ # cd /usr/local/src/nrpe-3.0 # ./configure --prefix=/usr/local/nrpe \ --sysconfdir=/etc/nrpe \ --with-nrpe-user=nagios \ --with-nrpe-group=nagios \ --with-nagios-user=nagios \ --with-nagios-group=nagios \ --enable-command-args \ --enable-ssl # make all # make install-plugin # make install-daemon # make install-config

(4)配置NRPE

# vim /etc/nrpe/nrpe.cfg log_facility=daemon pid_file=/var/run/nrpe.pid server_address=172.16.100.11 server_port=5666 nrpe_user=nagios nrpe_group=nagios allowed_hosts=172.16.100.1 command_timeout=60 connection_timeout=300 debug=0

上述配置指令可以做到见名知义,因此,配置过程中根据实际需要进行修改即可。其中,需要特定说明的是allowed_hosts指令用于定义本机所允许的监控端的IP地址。

(5)启动NRPE

# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d

为了便于NRPE服务的启动,可以将如下内容定义为/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

也可在/etc/xinetd.d目录中创建nrpe文件,使其成为一个基于非独立守护进程的服务,通过重启xinetd来实现启动NRPE进程,文件内容如下

service nrpe { flags = REUSE socket_type = stream wait = no user = nagios group = nagios server = /usr/local/nagios/bin/nrpe server_args = -c /etc/nagios/nrpe.cfg -i log_on_failure += USERID disable = no }

(6)配置允许远程主机监控的对象

在被监控端,可以通过NRPE监控的服务或资源需要通过nrpe.conf文件使用命令进行定义,定义命令的语法格式为:

command[<command_name>]=<command_to_execute>

比如:

command[check_rootdisk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /

command[check_swap]=/usr/local/nagios/libexec/check_disk -w 40% -c 20%

command[check_sensors]=/usr/local/nagios/libexec/check_sensors

command[check_users]=/usr/local/nagios/libexec/check_users -w 10 -c 20

command[check_load]=/usr/local/nagios/libexec/check_load -w 10,8,5 -c 20,18,15

command[check_zombies]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z

command[check_all_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

3、配置监控端
(1)安装NRPE

# tar xvf nrpe-3.0.tar.gz -C /usr/local/src/ # cd /usr/local/src/nrpe-3.0 # ./configure --with-nrpe-user=nagios \ --with-nrpe-group=nagios \ --with-nagios-user=nagios \ --with-nagios-group=nagios \ --enable-command-args \ --enable-ssl # make all # make install-plugin # /usr/local/nagios/libexec/check_nrpe -H client_IP ##测试是否能与被监控端通信 NRPE vnrpe-3.0

(2)定义如何监控远程主机及服务:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/1ff8509767fee9ab723c78de10f84d7f.html