Nagios之NRPE监控Linux/UNIX主机
来源:互联网 发布:手机在线答题系统源码 编辑:程序博客网 时间:2024/06/01 08:58
1. NRPE简介
NRPE是Nagios的一个功能扩展,它可在远程Linux/Unix主机上执行插件程序。通过在远程服务器上安装NRPE插件及Nagios插件程序来向Nagios监控平台提供该服务器的本地情况,如CPU负载,内存使用,磁盘使用等。这里将Nagios监控端称为Nagios服务器端,而将远程被监控的主机称为Nagios客户端。
Nagios监控远程主机的方法有多种,其方式包括SNMP,NRPE,SSH,NCSA等。这里介绍其通过NRPE监控远程Linux主机的方式。
注意:通过SSH是可以实现在远程的Linux/UNIX主机上执行nagios插件的,比如说check_by_ssh插件就可以实现这项功能。虽然SSH的方式相较于NRPE插件方式更为安全,但是在CPU负载上,无论是监控端还是被监控的远程主机,SSH方式也都更大一些,当面对被监控的主机涉及到成千上百台时,使用这种方式就会是个问题,这也是许多nagios管理员选择使用NRPE方式的主要原因。
1.1 NRPE的设计原理
check_nrpe插件,位于本地监控端;
NRPE进程,运行于远程主机(Linux/UNIX),也就是被监控端。
Nagios会执行check_nrpe插件,并告诉它需要监控的服务项;
check_nrpe插件通过SSL方式与被监控端的nrpe进程连接;
nrpe进程运行对应的nagios插件来执行服务或资源的监测;
NRPE 进程将监测的结果返回给check_nrpe 插件,check_nrpe插件又将结果传递给nagios进程做后续处理。
1.2 NRPE使用案例
2.1 远程主机端(被监控端)的NRPE安装与配置
[root@kk ~]#useradd nagios
[root@kk ~]#cd /home/softwares/[root@kk softwares]#wget http://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz[root@kk softwares]#tar -xzf nagios-plugins-2.1.2.tar.gz [root@kk softwares]#cd nagios-plugins-2.1.2[root@kk nagios-plugins-2.1.2]#./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@kk nagios-plugins-2.1.2]#make[root@kk nagios-plugins-2.1.2]#make install
[root@kk nagios-plugins-2.1.2]# chown nagios.nagios /usr/local/nagios[root@kk nagios-plugins-2.1.2]# chown -R nagios.nagios /usr/local/nagios/libexec
3.安装NRPE[root@kk nagios-plugins-2.1.2]#cd ..[root@kk softwares]#tar zxf nrpe-3.0.1.tar.gz [root@kk softwares]#cd nrpe-3.0.1[root@kk nrpe-3.0.1]#yum -y install openssl openssl-devel[root@kk nrpe-3.0.1]#./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@kk nrpe-3.0.1]#make all
[root@kk nrpe-3.0.1]#make install-plugin
[root@kk nrpe-3.0.1]#make install-daemon
[root@kk nrpe-3.0.1]#make install-daemon-config
[root@kk nrpe-3.0.1]#make install-config
# iptables -I RH-Firewall-1-INPUT -p tcp -m tcp –dport 5666 -j ACCEPT # service iptables save
[root@kk nrpe-3.0.1]#vim /usr/local/nagios/etc/nrpe.cfg
/usr/local/nagios/libexec/check_nrpe -H localhost -c check_users/usr/local/nagios/libexec/check_nrpe -H localhost -c check_load/usr/local/nagios/libexec/check_nrpe -H localhost -c check_sda1/usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs/usr/local/nagios/libexec/check_nrpe -H localhost -c check_zombie_procs
查看配置结果:[root@kk ~]#grep -v '^#' /usr/local/nagios/etc/nrpe.cfg |sed '/^$/d'log_facility=daemondebug=0pid_file=/usr/local/nagios/var/nrpe.pidserver_port=5666nrpe_user=nagiosnrpe_group=nagiosallowed_hosts=192.183.3.145,172.16.56.131dont_blame_nrpe=0allow_bash_command_substitution=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_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1command[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 200 -c 300command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
[root@kk nrpe-3.0.1]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d [root@kk nrpe-3.0.1]#netstat -tulpn | grep nrpe
- -i:#Run as a service under inetd or xinetd
- -d:#Run as a standalone daemon
[root@kk nrpe-3.0.1]#vi /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
设置自启动:[root@kk nrpe-3.0.1]#chmod +x /etc/init.d/nrped [root@kk nrpe-3.0.1]#chkconfig --add nrped [root@kk nrpe-3.0.1]#chkconfig nrped on [root@kk nrpe-3.0.1]#service nrped start Starting NRPE daemon... done.
2.2 监控端NRPE安装与配置
root@monitors ~]# yum -y install openssl openssl-devel
否则编译nrpe时会出现如下问题:[root@monitors ~]# cd /home/nagios/[root@monitors nagios]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-3.0.1.tar.gz--2017-01-17 23:36:36-- http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-3.0.1.tar.gz[root@monitors nagios]# tar xzvf nrpe-3.0.1.tar.gz [root@monitors nagios]# cd nrpe-3.0.1[root@monitors nrpe-3.0.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@monitors nrpe-3.0.1]# make all
[root@monitors nrpe-3.0.1]# make install-plugin
[root@monitors nrpe-3.0.1]# ll /usr/local/nagios/libexec/check_nrpe-rwxrwxr-x 1 nagios nagios 125293 1月 17 23:47 /usr/local/nagios/libexec/check_nrpe
[root@monitors libexec]# ./check_nrpe -h NRPE Plugin for NagiosCopyright (c) 1999-2008 Ethan Galstad (nagios@nagios.org)Version: 3.0.1Last Modified: 09-08-2016License: GPL v2 with exemptions (-l for more info)SSL/TLS Available: OpenSSL 0.9.6 or higher requiredUsage: check_nrpe -H <host> [-2] [-4] [-6] [-n] [-u] [-V] [-l] [-d <dhopt>] [-P <size>] [-S <ssl version>] [-L <cipherlist>] [-C <clientcert>] [-K <key>] [-A <ca-certificate>] [-s <logopts>] [-b <bindaddr>] [-f <cfg-file>] [-p <port>] [-t <interval>:<state>] [-c <command>] [-a <arglist...>]Options: <host> = The address of the host running the NRPE daemon -2 = Only use Version 2 packets, not Version 3 -4 = bind to ipv4 only -6 = bind to ipv6 only -n = Do no use SSL -u = (DEPRECATED) Make timeouts return UNKNOWN instead of CRITICAL -V = Show version -l = Show license <dhopt> = Anonymous Diffie Hellman use: 0 = Don't use Anonymous Diffie Hellman (This will be the default in a future release.) 1 = Allow Anonymous Diffie Hellman (default) 2 = Force Anonymous Diffie Hellman <size> = Specify non-default payload size for NSClient++ <ssl ver> = The SSL/TLS version to use. Can be any one of: SSLv2 (only), SSLv2+ (or above), SSLv3 (only), SSLv3+ (or above), TLSv1 (only), TLSv1+ (or above DEFAULT), TLSv1.1 (only), TLSv1.1+ (or above), TLSv1.2 (only), TLSv1.2+ (or above) <cipherlist> = The list of SSL ciphers to use (currently defaults to "ALL:!MD5:@STRENGTH". WILL change in a future release.) <clientcert> = The client certificate to use for PKI <key> = The private key to use with the client certificate <ca-cert> = The CA certificate to use for PKI <logopts> = SSL Logging Options <bindaddr> = bind to local address <cfg-file> = configuration file to use [port] = The port on which the daemon is running (default=5666) [command] = The name of the command that the remote daemon should run [arglist] = Optional arguments that should be passed to the command, separated by a space. If provided, this must be the last option supplied on the command line. NEW TIMEOUT SYNTAX -t <interval>:<state> <interval> = Number of seconds before connection times out (default=10) <state> = Check state to exit with in the event of a timeout (default=CRITICAL) Timeout state must be a valid state name (case-insensitive) or integer: (OK, WARNING, CRITICAL, UNKNOWN) or integer (0-3)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.
[root@monitors libexec]# ./check_nrpe -H 192.183.3.145 -p 5666NRPE v3.0.1
[root@monitors libexec]# cd /usr/local/nagios/etc/objects/[root@monitors objects]# vim commands.cfgdefine command{ command_name check_nrpe command_line $USER1$/check_nrpe -H "$HOSTADDRESS$" -c "$ARG1$"}
[root@monitors objects]# vi hosts.cfg
# Define a host for the remote machinedefine host{ host_name kk alias master-server use linux-server address 192.183.3.145 max_check_attempts 5 check_period 24x7 check_interval 5 retry_interval 1 max_check_attempts 10 check_command check-host-alive notification_period 24x7 notification_interval 30 notification_options d,r contact_groups admins }################################################################################################################################################################ HOST GROUP DEFINITION################################################################################################################################################################ Define an optional hostgroup for Linux machinesdefine hostgroup{ hostgroup_name remote-linux-servers ; The name of the hostgroup alias remoteLinux Servers ; Long name of the group members * ; Comma separated list of hosts that belong to this group }
[root@monitors objects]# vim prilinuxserver.cfg #PRIVATE SERVICE DEFINITIONS#The following service will monitor the CPU load on the remote host.# The "check_load" argument that is passed to the check_nrpe command# defiition tells the NRPE daemon to run the "check_load" comman#d as defied in the nrpe.cfg fiedefine service{use local-servicehost_name kkservice_description CPU Loadcheck_command check_nrpe!check_loadcontact_groups admins}#The following service will monitor the number of currently logged in users on the remote hostdefine service{use local-servicehost_name kkservice_description Current Userscheck_command check_nrpe!check_userscontact_groups admins}#The following service will monitor the free drive space on /dev/sda1 on the remote host.define service{use local-servicehost_name kkservice_description /dev/sda1 Free Spacecheck_command check_nrpe!check_sda1contact_groups admins}#The following service will monitor the total number of processes on the remote host.define service{use local-servicehost_name kkservice_description Total PProcessescheck_command check_nrpe!check_total_procscontact_groups admins}#The following service will monitor the number of zombie processes on the remote host.define service{use local-servicehost_name kkservice_description Zombie Processescheck_command check_nrpe!check_zombie_procscontact_groups admins}# monitoring the swap usage on the remote hostdefine service{use local-servicehost_name kkservice_description Swap Usagecheck_command check_nrpe!check_swapcontact_groups admins}
注意:监控端(Nagios服务端)定义的service命令与被监控端NRPE中内置的监控命令一致。[root@monitors objects]# vim /usr/local/nagios/etc/nagios.cfg 添加行: #definitions for monitoring the remote(linux/unix)hostcfg_file=/usr/local/nagios/etc/objects/hosts.cfg#definitions for monitoring the remote(linux/unix)host private servicescfg_file=/usr/local/nagios/etc/objects/prilinuxserver.cfg
如果host.cfg已经定义过则略过![root@monitors objects]# service nagios configtest或者[root@monitors objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgNagios Core 4.2.0Copyright (c) 2009-present Nagios Core Development Team and Community ContributorsCopyright (c) 1999-2009 Ethan GalstadLast Modified: 08-01-2016License: GPLWebsite: https://www.nagios.orgReading configuration data... Read main config file okay...Warning: Duplicate definition found for service 'Swap Usage' on host 'kk' (config file '/usr/local/nagios/etc/objects/publinuxserver.cfg', starting on line 75)Warning: Duplicate definition found for service 'Total Processes' on host 'kk' (config file '/usr/local/nagios/etc/objects/publinuxserver.cfg', starting on line 51)Warning: Duplicate definition found for service 'Current Users' on host 'kk' (config file '/usr/local/nagios/etc/objects/publinuxserver.cfg', starting on line 38) Read object config files okay...Running pre-flight check on configuration data...Checking objects...Checked 20 services.Checked 2 hosts.Checked 2 host groups.Checked 0 service groups.Checked 2 contacts.Checked 1 contact groups.Checked 26 commands.Checked 5 time periods.Checked 0 host escalations.Checked 0 service escalations.Checking for circular paths...Checked 2 hostsChecked 0 service dependenciesChecked 0 host dependenciesChecked 5 timeperiodsChecking global event handlers...Checking obsessive compulsive processor commands...Checking misc settings...Total Warnings: 0Total Errors: 0Things look okay - No serious problems were detected during the pre-flight checkObject precache file created:/usr/local/nagios/var/objects.precache
[root@monitors objects]# service nagios restartRunning configuration check...Stopping nagios: done.Starting nagios: done.
在远程主机端的nrpe.cfg文件中增加新的命令定义;
在监控端的nagios配置文件中增加新的服务监控定义;
[root@kk libexec]#/usr/local/nagios/libexec/check_swap -w 20% -c 10%SWAP OK - 59% free (2251 MB out of 3823 MB) |swap=2251MB;764;382;0;3823
[root@kk libexec]#vi /usr/local/nagios/etc/nrpe.cfgcommand[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
[root@kk libexec]#service nrped restartStopping NRPE daemon... done.Starting NRPE daemon... done.
[root@monitors ~]# vim /usr/local/nagios/etc/objects/prilinuxserver.cfg define service{use generic-servicehost_name remotehostservice_description Swap Usagecheck_command check_nrpe!check_swap}
验证配置:[root@monitors ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
重启nagios:[root@monitors ~]# service nagios restartRunning configuration check...Stopping nagios: done.Starting nagios: done.
- Nagios之NRPE监控Linux/UNIX主机
- Nagios之NRPE监控Linux/UNIX主机
- Nagios监控平台之二:nrpe监控远程Linux主机
- Nagios利用NRPE监控Linux主机
- Nagios利用NRPE监控Linux主机
- nagios nrpe监控Linux
- 监控之Nagios+Nrpe
- nrpe监控远程Linux主机
- Nagios监控--Linux客户端(Use NRPE)
- nagios监控Linux主机
- nagios 监控Linux 主机
- 部署Nagios监控系统(三)NRPE监控远程主机系统状况
- nagios上增加nrpe模块达到监控主机CPU、内存、磁盘使用情况
- nagios上增加nrpe模块达到监控主机CPU、内存、磁盘使用情况
- nagios 监控被监控服务器安装nrpe
- nagios 监控 linux主机的信息
- Nagios监控linux主机以及硬件信息
- 服务器监控:Nagios和NRPE配置
- Redis多种监控方案
- 日期操作(日期加减,格式化,比较)
- Spring整合Junit4进行单元测试
- Handler内存泄漏和解决方法
- 让你的APK瘦身--一图多用
- Nagios之NRPE监控Linux/UNIX主机
- spring boot快速入门
- Linux 的计划任务
- localStorage使用总结
- ReentrantReadWriteLock读写锁的使用
- windows 下使用python pip install
- 使用Diskgenius将U盘分区,分为启动盘和文件存储两大功能详解
- Tomcat 7服务器线程模型
- 格式化金额,每三位加逗号并保留两位小数