Nagios學習筆記四:基於NRPE監控遠程Linux主機

來源:互聯網
上載者:User

標籤:start   linu   inetd   str   debug   configure   格式   lib   ppi   

1、NRPE簡介

 

Nagios監控遠程主機的方法有多種,其方式包括SNMP、NRPE、SSH和NCSA等。這裡介紹其通過NRPE監控遠程Linux主機的方式。

 

NRPE(Nagios Remote Plugin Executor)是用於在遠端伺服器上運行檢測命令的守護進程,它用於讓Nagios監控端基於安裝的方式觸發遠端主機上的檢測命令,並將檢測結果輸出至監控端。而其執行的開銷遠低於基於SSH的檢測方式,而且檢測過程並不需要遠程主機上的系統帳號等資訊,其安全性也高於SSH的檢測方式。

 

2、安裝配置被監控端

 

1)先添加nagios使用者

# useradd -s /sbin/nologin nagios

 

2)NRPE依賴於nagios-plugins,因此,需要先安裝

 

# tar zxf nagios-plugins-1.4.15.tar.gz

# cd nagios-plugins-1.4.15

# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

# make all

# make instal

 

3)安裝NRPE

 

# tar -zxvf nrpe-2.12.tar.gz

# cd nrpe-2.12.tar.gz

# ./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

 

4)配置NRPE

 

# vim /usr/local/nagios/etc/nrpe.conf

 

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  #允許哪些nagios服務端查詢

command_timeout=60

connection_timeout=300

debug=0                      #是否開啟日誌,0表示不開啟,1表示開啟,日誌在message中

dont_blame_nrpe=1           #是否允許傳遞參數,1表示運行,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檔案,使其成為一個基於非獨立守護進程的服務,檔案內容如下:

 

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

}

 

此種情況下啟動NRPE進程需要通過重啟xinetd來實現。

 

6)配置允許遠程主機監控的對象

 

在被監控端,可以通過NRPE監控的服務或資源需要通過nrpe.conf檔案使用命令進行定義,定義命令的文法格式為:command[<command_name>]=<command_to_execute>。比如:

當nrpe收到命令後其實是調用外掛程式提供的命令,把結果在返回給nrpe,所以nagios服務端發送的命令為定義的命令

 

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

 

command[check_all_procs]=/usr/local/nagios/libexec/check_procs -w $ARG1$ -c $ARG2$

修改為可以傳遞參數的方式

Nagios學習筆記四:基於NRPE監控遠程Linux主機

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.