標籤:nagios nrpe nagios-plugins
一、簡介
1、NRPE介紹
NRPE是Nagios的一個功能擴充,它可在遠程Linux/Unix主機上執行外掛程式程式。通過在遠程伺服器上安裝NRPE外掛程式及Nagios外掛程式程式來向Nagios監控平台提供該伺服器的本地情況,如CPU負載,記憶體使用量,磁碟使用等。這裡將Nagios監控端稱為Nagios伺服器端,而將遠程被監控的主機稱為Nagios用戶端。
Nagios監控遠程主機的方法有多種,其方式包括SNMP,NRPE,SSH,NCSA等。這裡介紹其通過NRPE監控遠程Linux主機的方式。
NRPE(Nagios Remote Plugin Executor)是用於在遠端伺服器上運行監測命令的守護進程,它用於讓Nagios監控端基於安裝的方式觸發遠端主機上的檢測命令,並將檢測結果返回給監控端。而其執行的開銷遠低於基於SSH的檢測方式,而且檢測過程不需要遠程主機上的系統帳號資訊,其安全性也高於SSH的檢測方式。
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M01/4A/C3/wKioL1Qm3NLBZZSnAAHCItyFxXI201.jpg" title="2.png" alt="wKioL1Qm3NLBZZSnAAHCItyFxXI201.jpg" />
2、NRPE的工作原理
NRPE有兩部分組成
check_nrpe外掛程式:位於監控主機上
nrpe daemon:運行在遠程主機上,通常是被監控端agent
注意:nrpe daemon需要Nagios-plugins外掛程式的支援,否則daemon不能做任何監控
650) this.width=650;" src="http://s3.51cto.com/wyfs02/M00/4A/C3/wKioL1Qm2krywnxLAACf2VJUtQI655.jpg" title="1.jpg" alt="wKioL1Qm2krywnxLAACf2VJUtQI655.jpg" />
詳細的介紹NRPE的工作原理
當Nagios需要監控某個遠程Linux主機的服務或者資源情況時:
首先:Nagios會運行check_nrpe這個外掛程式,告訴它要檢查什麼;
其次:check_nrpe外掛程式會串連到遠端NRPE daemon,所用的方式是SSL;
然後:NRPE daemon 會運行相應的Nagios外掛程式來執行檢查;
最後:NRPE daemon 將檢查的結果返回給check_nrpe 外掛程式,外掛程式將其遞交給nagios做處理。
二、被監控端安裝Nagios-plugins外掛程式和NRPE
1、添加nagios使用者
[[email protected] ~]# useradd -s /sbin/nologin nagios
2、安裝nagios-plugins,因為NRPE依賴此外掛程式
[[email protected] ~]# yum -y install gcc gcc-c++ make openssl openssl-devel[[email protected] ~]# tar xf nagios-plugins-2.0.3.tar.gz [[email protected] ~]# cd nagios-plugins-2.0.3[[email protected] nagios-plugins-2.0.3]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios[[email protected] nagios-plugins-2.0.3]# make && make install#注意:如何要監控mysql 需要添加 --with-mysql
3、安裝NRPE
[[email protected] ~]# tar xf nrpe-2.15.tar.gz [[email protected] ~]# cd nrpe-2.15[[email protected] 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[[email protected] nrpe-2.15]# make all[[email protected] nrpe-2.15]# make install-plugin[[email protected] nrpe-2.15]# make install-daemon[[email protected] nrpe-2.15]# make install-daemon-config
4、配置NRPE
[[email protected] ~]# grep -v ‘^#‘ /usr/local/nagios/etc/nrpe.cfg |sed ‘/^$/d‘log_facility=daemonpid_file=/var/run/nrpe.pidserver_port=5666 #監聽的連接埠nrpe_user=nagiosnrpe_group=nagiosallowed_hosts=192.168.0.105 #允許的地址通常是Nagios伺服器端 dont_blame_nrpe=0allow_bash_command_substitution=0debug=0command_timeout=60connection_timeout=300command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Zcommand[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
5、啟動NRPE
#以守護進程的方式啟動[[email protected] ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d[[email protected] ~]# netstat -tulpn | grep nrpetcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 22597/nrpe tcp 0 0 :::5666 :::* LISTEN 22597/nrpe
有兩種方式用於管理nrpe服務,nrpe有兩種運行模式:
-i # Run as a service under inetd or xinetd-d # Run as a standalone daemon
可以為nrpe編寫啟動指令碼,使得nrpe以standard alone方式運行:
[[email protected] ~]# cat /etc/init.d/nrped #!/bin/bash# chkconfig: 2345 88 12# description: NRPE DAEMONNRPE=/usr/local/nagios/bin/nrpeNRPECONF=/usr/local/nagios/etc/nrpe.cfgcase "$1" instart)echo -n "Starting NRPE daemon..."$NRPE -c $NRPECONF -decho " done.";;stop)echo -n "Stopping NRPE daemon..."pkill -u nagios nrpeecho " done.";;restart)$0 stopsleep 2$0 start;;*)echo "Usage: $0 start|stop|restart";;esacexit 0[[email protected] ~]# chmod +x /etc/init.d/nrped [[email protected] ~]# chkconfig --add nrped[[email protected] ~]# chkconfig nrped on[[email protected] ~]# service nrped startStarting NRPE daemon... done.[[email protected] ~]# netstat -tnlpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1031/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1108/master tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 22597/nrpe tcp 0 0 :::22 :::* LISTEN 1031/sshd tcp 0 0 ::1:25 :::* LISTEN 1108/master tcp 0 0 :::5666 :::* LISTEN 22597/nrpe
三、監控端安裝NRPE
1、安裝NRPE
[[email protected] ~]# tar xf nrpe-2.15.tar.gz [[email protected] ~]# cd nrpe-2.15[[email protected] 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[[email protected] nrpe-2.15]# make all[[email protected] nrpe-2.15]# make install-plugin#安裝完成後,會在Nagios安裝目錄的libexec下產生check_nrpe的外掛程式[[email protected] ~]# cd /usr/local/nagios/libexec/[[email protected] libexec]# ll -d check_nrpe -rwxrwxr-x. 1 nagios nagios 76769 9月 28 08:07 check_nrpe
2、check_nrpe的用法
[[email protected] libexec]# ./check_nrpe -hNRPE Plugin for NagiosCopyright (c) 1999-2008 Ethan Galstad ([email protected])Version: 2.15Last Modified: 09-06-2013License: GPL v2 with exemptions (-l for more info)SSL/TLS Available: Anonymous DH Mode, OpenSSL 0.9.6 or higher requiredUsage: 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 commandwith the [command] option you are specifying here. Upon receipt of the[command] argument, the NRPE daemon will run the appropriate plugin command andsend the plugin output and return code back to *this* plugin. This allows youto execute plugins on remote hosts and ‘fake‘ the results to make Nagios thinkthe plugin is being run locally.
通過NRPE監控遠程Linux主機要使用chech_nrpe外掛程式進行,其文法格式如下:check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>][[email protected] libexec]# ./check_nrpe -H 192.168.0.81NRPE v2.15
3、定義命令、主機、服務
本文出自 “鄭彥生” 部落格,請務必保留此出處http://467754239.blog.51cto.com/4878013/1558897
Nagios利用NRPE監控Linux主機