NRPE是Nagios的一個(gè)功能擴(kuò)展,它可在遠(yuǎn)程Linux/Unix主機(jī)上執(zhí)行插件程序。通過(guò)在遠(yuǎn)程服務(wù)器上安裝NRPE插件及Nagios插件程序來(lái)向Nagios監(jiān)控平臺(tái)提供該服務(wù)器的本地情況,如CPU負(fù)載,內(nèi)存使用,磁盤(pán)使用等。這里將Nagios監(jiān)控端稱(chēng)為Nagios服務(wù)器端,而將遠(yuǎn)程被監(jiān)控的主機(jī)稱(chēng)為Nagios客戶端。
Nagios監(jiān)控遠(yuǎn)程主機(jī)的方法有多種,其方式包括SNMP,NRPE,SSH,NCSA等。這里介紹其通過(guò)NRPE監(jiān)控遠(yuǎn)程Linux主機(jī)的方式。
NRPE(Nagios Remote Plugin Executor)是用于在遠(yuǎn)端服務(wù)器上運(yùn)行監(jiān)測(cè)命令的守護(hù)進(jìn)程,它用于讓Nagios監(jiān)控端基于安裝的方式觸發(fā)遠(yuǎn)端主機(jī)上的檢測(cè)命令,并將檢測(cè)結(jié)果返回給監(jiān)控端。而其執(zhí)行的開(kāi)銷(xiāo)遠(yuǎn)低于基于SSH的檢測(cè)方式,而且檢測(cè)過(guò)程不需要遠(yuǎn)程主機(jī)上的系統(tǒng)賬號(hào)信息,其安全性也高于SSH的檢測(cè)方式。
NRPE有兩部分組成
check_nrpe插件:位于監(jiān)控主機(jī)上
nrpe daemon:運(yùn)行在遠(yuǎn)程主機(jī)上,通常是被監(jiān)控端agent
注意:nrpe daemon需要Nagios-plugins插件的支持,否則daemon不能做任何監(jiān)控
當(dāng)Nagios需要監(jiān)控某個(gè)遠(yuǎn)程Linux主機(jī)的服務(wù)或者資源情況時(shí):
首先:Nagios會(huì)運(yùn)行check_nrpe這個(gè)插件,告訴它要檢查什么;
其次:check_nrpe插件會(huì)連接到遠(yuǎn)程的NRPE daemon,所用的方式是SSL;
然后:NRPE daemon 會(huì)運(yùn)行相應(yīng)的Nagios插件來(lái)執(zhí)行檢查;
最后:NRPE daemon 將檢查的結(jié)果返回給check_nrpe 插件,插件將其遞交給nagios做處理。
<版權(quán)所有,文章允許轉(zhuǎn)載,但必須以鏈接方式注明源地址,否則追究法律責(zé)任!>
原博客地址: http://blog.csdn.net/mchdba/article/details/46666229
原作者:黃杉 (mchdba)
去mysql客戶端安裝nrpe客戶端服務(wù)
[root@localhost ~]# useradd -s/sbin/nologin nagios
[root@localhost ~]# yum -yinstall gcc gcc-c++ make openssl openssl-devel
tar -xvf 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
grep -v '^#' /usr/local/nagios/etc/nrpe.cfg |sed '/^$/d'
[root@localhost ~]# grep -v '^#' /usr/local/nagios/etc/nrpe.cfg|sed '/^$/d'
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.121.211
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 8 -c 12
command[check_load]=/usr/local/nagios/libexec/check_load -w15,10,5 -c 30,25,20
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w20% -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 750 -c 800
command[check-host-alive]=/usr/local/nagios/libexec/check_ping-H 10.254.3.72 -w 3000.0,80% -c 5000.0,100% -p 5
command[check_mysql_status]=/usr/local/nagios/libexec/check_mysql-unagios -P3306 -s /usr/local/mysql/mysql.sock -Hlocalhost--password='nagiosq@0625' -d test -w 60 -c 100
[root@localhost ~]#
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe
[root@localhost bin]# cat /etc/init.d/nrped
#chkconfig: 2345 80 90
#description:auto_run
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
[root@localhost bin]#
chmod +x /etc/init.d/nrped
chkconfig --add nrped
chkconfig nrped on
[root@localhost bin]# ps -eaf|grep nrpe
nagios 30440 1 0 23:48 ? 00:00:00 /usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d
root 30442 3292 0 23:48 pts/0 00:00:00 grep nrpe
[root@localhost bin]#
[root@localhost bin]# netstat -tnlp |grepnrpe
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 30440/nrpe
tcp 0 0 :::5666 :::* LISTEN 30440/nrpe
[root@localhost bin]#
tar xf 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
#安裝完成后,會(huì)在Nagios安裝目錄的libexec下生成check_nrpe的插件,如下所示:
[root@test_db2 nagios]# ll /usr/local/nagios/libexec/check_nrpe
-rwxrwxr-x 1 nagios nagios 76777 Jun 2523:53 /usr/local/nagios/libexec/check_nrpe
[root@test_db2 nagios]#
檢測(cè)報(bào)錯(cuò):
[root@test_db2 libexec]# ./check_nrpe -H192.168.121.210
CHECK_NRPE: Error - Could not complete SSLhandshake.
[root@test_db2 libexec]#
去客戶端在allowed_hosts中添加監(jiān)控端IP地址
[root@localhost ~]# vim/usr/local/nagios/etc/nrpe.cfg
allowed_hosts=127.0.0.1,192.168.121.211
在mysql服務(wù)器上,報(bào)錯(cuò):
[root@localhost ~]#/usr/local/nagios/libexec/check_mysql -unagios -P3306 -S -s/usr/local/mysql/mysql.sock -Hlocalhost --password='nagiosq@0512' -d test -w 60-c 100
/usr/local/nagios/libexec/check_mysql:error while loading shared libraries: libmysqlclient.so.18: cannot open sharedobject file: No such file or directory
[root@localhost ~]#
[root@localhost ~]# find / -namelibmysqlclient.so.18
/usr/local/mysql/lib/libmysqlclient.so.18
/root/mysql/mysql-5.6.12/libmysql/libmysqlclient.so.18
/root/mysql-5.6.12/libmysql/libmysqlclient.so.18
[root@localhost ~]# ln -s/usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
[root@localhost ~]#
添加mysql賬號(hào):
mysql> GRANT PROCESS, SUPER, REPLICATIONCLIENT ON *.* TO 'nagios'@'localhost' IDENTIFIED BY 'nagiosq@0625';
Query OK, 0 rows affected (0.05 sec)
mysql>
客戶端自己檢測(cè):
[root@localhost ~]#/usr/local/nagios/libexec/check_mysql -unagios -P3306 -s /usr/local/mysql/mysql.sock -Hlocalhost--password='nagiosq@0625' -d test -w 60 -c 100
Uptime: 1823238 Threads: 6 Questions: 684495 Slow queries:0 Opens: 124 Flush tables: 1 Open tables: 116 Queries per second avg:0.375|Connections=3116c;;; Open_files=19;;; Open_tables=116;;; Qcache_free_memory=61538880;;;Qcache_hits=176271c;;; Qcache_inserts=41370c;;; Qcache_lowmem_prunes=0c;;;Qcache_not_cached=331835c;;; Qcache_queries_in_cache=3373;;; Queries=684496c;;;Questions=681384c;;; Table_locks_waited=0c;;; Threads_connected=5;;;Threads_running=2;;; Uptime=1823238c;;;
[root@localhost ~]#
將servers.cfg添加進(jìn)nagios.cfg里面,將command.cfg里面的check_host_alive以及check_mysql_status補(bǔ)充好,然后重啟nagios
# add by timman on 20150512
define command{
command_name check_mysql_status
command_line $USER1$/check_mysql_status-w $ARG1$ -c $ARG2$
}
# 'check_nrpe' command definition,add bytimman on 20140508
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe-H $HOSTADDRESS$ -c $ARG1$
}
define command{
command_name check_host_alive
command_line $USER1$/check_ping-H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5
}
[root@test_db2 etc]# more servers.cfg
# servicedefinition
define service{
host_name cactitest
service_description check_load
check_command check_nrpe!check_load
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups dba
}
define service{
host_name cactitest
service_description check_host_alive
check_command check_host_alive
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups dba
}
define service{
host_name cactitest
service_description Check Disksda1
check_command check_nrpe!check_sda1
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups dba
}
define service{
host_name cactitest
service_description TotalProcesses
check_command check_nrpe!check_total_procs
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups dba
}
define service{
host_name cactitest
service_description CurrentUsers
check_command check_nrpe!check_users
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups dba
}
define service{
host_name cactitest
service_description CheckZombie Procs
check_command check_nrpe!check_zombie_procs
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups dba
}
define service{
host_name cactitest
service_description CheckMysql Status
check_command check_nrpe!check_mysql_status
max_check_attempts 5
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
contact_groups dba
}
在nagios.cfg里面配置
cfg_file=/usr/local/nagios/etc/servers.cfg
同時(shí)添加新的主機(jī)或者服務(wù)配置cfg文件,都需要在nagios.cfg里面配置一下,然后重啟nagios才能生效,如下所示:
[root@test_db2 nagios]# grep -v '^#'/usr/local/nagios/etc/nagios.cfg |sed '/^$/d' |grep cfg_file
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_file=/usr/local/nagios/etc/servers.cfg
cfg_file=/usr/local/nagios/etc/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
[root@test_db2 nagios]#
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com