Nagios安装部署全攻略(2)

说明:NRPE(nagios remore plugin execute)远程插件执行器,用于在远端服务区上运行监测命令的守护进程,它用于让nagios监控端基于安装的方式出发远端主机上的检测命令,并将检测结果输出至监控端。而其执行的开销远低于基于ssh的检测方式,而且检测过程中并不需要远程主机上的系统账号等信息。必须在客户端安装nrpe的nagios的plugin
1、安装plugin
#useradd -s /sbin/nologin nagios
#yum grouplist
#yum -y groupinstall "Development Tools" "Development Libraries"
#tar zxvf nagios-plugins-1.4.13.tar.gz 
#cd nagios-plugins-1.4.13
#./configure --with-nagios-user=nagios --with-nagios-group=nagios
#make all
#make install

2、安装nrpe
#tar zxvf nrpe-2.15.tar.gz
#cd 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
#make all
#make install-plugin
#make install-daemon
#make install-daemon-config

3、配置NRPE
# vi /usr/local/nagios/etc/nrpe.cfg 
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
#修改为本机的IP
server_address=192.168.1.101
nrpe_user=nagios
nrpe_group=nagios
#修改为Nagios服务端的IP
allowed_hosts=192.168.1.100
command_timeout=60

4、启动nrpe
# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
为了方便NRPE的启动,可以将如下内容定义为/etc/init.d/nrped脚本
#!/bin/bash
NRPE=/usr/local/nagios/bin/nrpe
NRPECONF=/usr/local/nagios/etc/nrpe.cfg
case "$1" in
        start)
                echo -n "Staring NRPE daemon...."
                $NRPE -c $NRPECONF -d
                echo "done.."
                ;;
        stop)
                echo -n "Stopping NRPE daemon...."
                pkill -u nagios nrpe
                echo "done.."
                ;;
        restart)
                $0  stop
                sleep 1
                $0 start
                ;;
        *)
                echo "Usage: $0 start|stop|restart"
        esac
exit 0

5、配置示例
vi /usr/local/nagios/etc/nrpe.cfg

command[check_users]=/usr/local/nagios/libexec/check_users -w 10 -c 20
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_sd1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda6
command[check_sd2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda3
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 200 -c 400
command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh -w 50 -c 80
command[check_mem]=/usr/local/nagios/libexec/check_mem.sh -w 50 -c 80
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%


四、NRPE服务端

1、安装NRPE
#tar zxvf nrpe-2.15.tar.gz
#cd 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 --with-mysql
#make all
#make install-plugin
2、定义如何监控远程主机及服务
通过NPRE监控远程Linux主机要使用check_nrpe插件进行,其语法格式如下:
check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]
示例:

define command
{
    command_name check_swap_nrpe
    command_line $USER1$check_nrpe -H "$HOSTADDRESS$" -c "check_swap"
}


如果还希望在监控远程LINUX主机时还能向其传递参数,则可以使用类似如下方式进行:
#cd /etc/nagios/objects/
#vi commands.cfg \\增加以下内容
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

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

转载注明出处:https://www.heiqu.com/2182f8f0aa99ea86b2db6cbcc2b1c5f1.html