自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Nagios利用NRPE監(jiān)控Linux主機(jī)

運(yùn)維 系統(tǒng)運(yùn)維 Linux
NRPE是Nagios的一個功能擴(kuò)展,它可在遠(yuǎn)程Linux/Unix主機(jī)上執(zhí)行插件程序。通過在遠(yuǎn)程服務(wù)器上安裝NRPE插件及Nagios插件程序來向Nagios監(jiān)控平臺提供該服務(wù)器的本地情況,如CPU負(fù)載,內(nèi)存使用,磁盤使用等。這里將Nagios監(jiān)控端稱為Nagios服務(wù)器端,而將遠(yuǎn)程被監(jiān)控的主機(jī)稱為Nagios客戶端。

一、簡介

1、NRPE介紹

NRPE是Nagios的一個功能擴(kuò)展,它可在遠(yuǎn)程Linux/Unix主機(jī)上執(zhí)行插件程序。通過在遠(yuǎn)程服務(wù)器上安裝NRPE插件及Nagios插件程序來向Nagios監(jiān)控平臺提供該服務(wù)器的本地情況,如CPU負(fù)載,內(nèi)存使用,磁盤使用等。這里將Nagios監(jiān)控端稱為Nagios服務(wù)器端,而將遠(yuǎn)程被監(jiān)控的主機(jī)稱為Nagios客戶端。

Nagios監(jiān)控遠(yuǎn)程主機(jī)的方法有多種,其方式包括SNMP,NRPE,SSH,NCSA等。這里介紹其通過NRPE監(jiān)控遠(yuǎn)程Linux主機(jī)的方式。

NRPE(Nagios Remote Plugin Executor)是用于在遠(yuǎn)端服務(wù)器上運(yùn)行監(jiān)測命令的守護(hù)進(jìn)程,它用于讓Nagios監(jiān)控端基于安裝的方式觸發(fā)遠(yuǎn)端主機(jī)上的檢測命令,并將檢測結(jié)果返回給監(jiān)控端。而其執(zhí)行的開銷遠(yuǎn)低于基于SSH的檢測方式,而且檢測過程不需要遠(yuǎn)程主機(jī)上的系統(tǒng)賬號信息,其安全性也高于SSH的檢測方式。

wKioL1Qm3NLBZZSnAAHCItyFxXI201.jpg

2、NRPE的工作原理

NRPE有兩部分組成

check_nrpe插件:位于監(jiān)控主機(jī)上
 

nrpe daemon:運(yùn)行在遠(yuǎn)程主機(jī)上,通常是被監(jiān)控端agent

注意:nrpe daemon需要Nagios-plugins插件的支持,否則daemon不能做任何監(jiān)控

wKioL1Qm2krywnxLAACf2VJUtQI655.jpg

詳細(xì)的介紹NRPE的工作原理

當(dāng)Nagios需要監(jiān)控某個遠(yuǎn)程Linux主機(jī)的服務(wù)或者資源情況時:

首先:Nagios會運(yùn)行check_nrpe這個插件,告訴它要檢查什么;

其次:check_nrpe插件會連接到遠(yuǎn)程的NRPE daemon,所用的方式是SSL;

然后:NRPE daemon 會運(yùn)行相應(yīng)的Nagios插件來執(zhí)行檢查;

最后:NRPE daemon 將檢查的結(jié)果返回給check_nrpe 插件,插件將其遞交給nagios做處理。
 

二、被監(jiān)控端安裝Nagios-plugins插件和NRPE

1、添加nagios用戶

  1. [root@ClientNrpe ~]# useradd -s /sbin/nologin nagios  

2、安裝nagios-plugins,因為NRPE依賴此插件

  1. [root@ClientNrpe ~]# yum -y install gcc gcc-c++ make openssl openssl-devel   
  2.     
  3. [root@ClientNrpe ~]# tar xf nagios-plugins-2.0.3.tar.gz    
  4. [root@ClientNrpe ~]# cd nagios-plugins-2.0.3   
  5. [root@ClientNrpe nagios-plugins-2.0.3]# ./configure  --with-nagios-user=nagios --with-nagios-group=nagios   
  6. [root@ClientNrpe nagios-plugins-2.0.3]# make && make install   
  7.     
  8. #注意:如何要監(jiān)控mysql 需要添加 --with-mysql 

3、安裝NRPE

  1. [root@ClientNrpe ~]# tar xf nrpe-2.15.tar.gz    
  2. [root@ClientNrpe ~]# cd nrpe-2.15   
  3. [root@ClientNrpe nrpe-2.15]# ./configure --with-nrpe-user=nagios \   
  4. > --with-nrpe-group=nagios \   
  5. > --with-nagios-user=nagios \   
  6. > --with-nagios-group=nagios \   
  7. > --enable-command-args \   
  8. > --enable-ssl   
  9. [root@ClientNrpe nrpe-2.15]# make all   
  10. [root@ClientNrpe nrpe-2.15]# make install-plugin   
  11. [root@ClientNrpe nrpe-2.15]# make install-daemon   
  12. [root@ClientNrpe nrpe-2.15]# make install-daemon-config 

4、配置NRPE

  1. [root@ClientNrpe ~]# grep -v '^#' /usr/local/nagios/etc/nrpe.cfg |sed '/^$/d'   
  2. log_facility=daemon   
  3. pid_file=/var/run/nrpe.pid   
  4. server_port=5666             #監(jiān)聽的端口   
  5. nrpe_user=nagios   
  6. nrpe_group=nagios   
  7. allowed_hosts=192.168.0.105   #允許的地址通常是Nagios服務(wù)器端   
  8.      
  9. dont_blame_nrpe=0   
  10. allow_bash_command_substitution=0   
  11. debug=0   
  12. command_timeout=60   
  13. connection_timeout=300   
  14. command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10   
  15. command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20   
  16. command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1  
  17. command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z   
  18. command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 

5、啟動NRPE

  1. #以守護(hù)進(jìn)程的方式啟動   
  2. [root@ClientNrpe ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d   
  3. [root@ClientNrpe ~]# netstat -tulpn | grep nrpe   
  4. tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      22597/nrpe            
  5. tcp        0      0 :::5666                     :::*                        LISTEN      22597/nrpe 

有兩種方式用于管理nrpe服務(wù),nrpe有兩種運(yùn)行模式:

  1. -i        # Run as a service under inetd or xinetd   
  2. -d        # Run as a standalone daemon 

可以為nrpe編寫啟動腳本,使得nrpe以standard alone方式運(yùn)行:

  1. [root@ClientNrpe ~]# cat /etc/init.d/nrped    
  2. #!/bin/bash   
  3. # chkconfig: 2345 88 12   
  4. # description: NRPE DAEMON   
  5.     
  6. NRPE=/usr/local/nagios/bin/nrpe  
  7. NRPECONF=/usr/local/nagios/etc/nrpe.cfg   
  8.     
  9. case "$1" in 
  10.     start)   
  11.         echo -n "Starting NRPE daemon..." 
  12.         $NRPE -c $NRPECONF -d   
  13.         echo " done." 
  14.         ;;   
  15.     stop)   
  16.         echo -n "Stopping NRPE daemon..." 
  17.         pkill -u nagios nrpe   
  18.         echo " done." 
  19.     ;;   
  20.     restart)   
  21.         $0 stop   
  22.         sleep 2   
  23.         $0 start   
  24.         ;;   
  25.     *)   
  26.         echo "Usage: $0 start|stop|restart" 
  27.         ;;   
  28.     esac  
  29. exit 0   
  30. [root@ClientNrpe ~]# chmod +x /etc/init.d/nrped    
  31. [root@ClientNrpe ~]# chkconfig --add nrped   
  32. [root@ClientNrpe ~]# chkconfig nrped on   
  33.     
  34. [root@ClientNrpe ~]# service nrped start   
  35. Starting NRPE daemon... done.   
  36. [root@ClientNrpe ~]# netstat -tnlp   
  37. Active Internet connections (only servers)   
  38. Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name      
  39. tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1031/sshd             
  40. tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1108/master           
  41. tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      22597/nrpe            
  42. tcp        0      0 :::22                       :::*                        LISTEN      1031/sshd             
  43. tcp        0      0 ::1:25                      :::*                        LISTEN      1108/master           
  44. tcp        0      0 :::5666                     :::*                        LISTEN      22597/nrpe 

三、監(jiān)控端安裝NRPE

1、安裝NRPE

  1. [root@Nagios ~]# tar xf nrpe-2.15.tar.gz    
  2. [root@Nagios ~]# cd nrpe-2.15   
  3. [root@Nagios nrpe-2.15]# ./configure    
  4. > --with-nrpe-user=nagios \   
  5. > --with-nrpe-group=nagios \   
  6. > --with-nagios-user=nagios \   
  7. > --with-nagios-group=nagios \   
  8. > --enable-command-args \   
  9. > --enable-ssl   
  10. [root@Nagios nrpe-2.15]# make all   
  11. [root@Nagios nrpe-2.15]# make install-plugin   
  12.     
  13. #安裝完成后,會在Nagios安裝目錄的libexec下生成check_nrpe的插件   
  14. [root@Nagios ~]# cd /usr/local/nagios/libexec/   
  15. [root@Nagios libexec]# ll -d check_nrpe    
  16. -rwxrwxr-x. 1 nagios nagios 76769 9月  28 08:07 check_nrpe 

2、check_nrpe的用法
 

  1. [root@Nagios libexec]# ./check_nrpe -h   
  2.     
  3. NRPE Plugin for Nagios   
  4. Copyright (c) 1999-2008 Ethan Galstad (nagios@nagios.org)   
  5. Version: 2.15   
  6. Last Modified: 09-06-2013   
  7. License: GPL v2 with exemptions (-l for more info)   
  8. SSL/TLS Available: Anonymous DH Mode, OpenSSL 0.9.6 or higher required   
  9.     
  10. Usage: check_nrpe -H <host> [ -b <bindaddr> ] [-4] [-6] [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]   
  11.     
  12. Options:   
  13.  -n         = Do no use SSL   
  14.  -u         = Make socket timeouts return an UNKNOWN state instead of CRITICAL   
  15.  <host>     = The address of the host running the NRPE daemon   
  16.  <bindaddr> = bind to local address   
  17.  -4         = user ipv4 only   
  18.  -6         = user ipv6 only   
  19.  [port]     = The port on which the daemon is running (default=5666)   
  20.  [timeout]  = Number of seconds before connection times out (default=10)   
  21.  [command]  = The name of the command that the remote daemon should run   
  22.  [arglist]  = Optional arguments that should be passed to the command.  Multiple   
  23.               arguments should be separated by a space.  If provided, this must be   
  24.               the last option supplied on the command line.   
  25.     
  26. Note:   
  27. This plugin requires that you have the NRPE daemon running on the remote host.   
  28. You must also have configured the daemon to associate a specific plugin command  
  29. with the [command] option you are specifying here.  Upon receipt of the   
  30. [command] argument, the NRPE daemon will run the appropriate plugin command and   
  31. send the plugin output and return code back to *this* plugin.  This allows you   
  32. to execute plugins on remote hosts and 'fake' the results to make Nagios think   
  33. the plugin is being run locally. 
通過NRPE監(jiān)控遠(yuǎn)程Linux主機(jī)要使用chech_nrpe插件進(jìn)行,其語法格式如下:
 
  1. check_nrpe -H <host> [-n] [-u] [-p <port>] [-t <timeout>] [-c <command>] [-a <arglist...>]   
  2.     
  3. [root@Nagios libexec]# ./check_nrpe -H 192.168.0.81   
  4. NRPE v2.15 


3、定義命令

  1. [root@Nagios ~]# cd /usr/local/nagios/etc/objects/   
  2. [root@Nagios objects]# vim commands.cfg    
  3. #增加到末尾行   
  4. define command{   
  5.         command_name    check_nrpe   
  6.         command_line    $USER1$/check_nrpe -H "$HOSTADDRESS$"  -c "$ARG1$" 

#p#

4、定義服務(wù)

  1. [root@Nagios objects]# cp windows.cfg linhost.cfg    
  2. [root@Nagios objects]# grep -v '^#' linhost.cfg |sed '/^$/d'   
  3. define host{   
  4.     use     linux-server       
  5.     host_name   linhost    
  6.     alias       My Linux Server      
  7.     address     192.168.0.81       
  8.     }   
  9. define service{   
  10.     use         generic-service   
  11.     host_name       linhost   
  12.     service_description CHECK USER   
  13.     check_command       check_nrpe!check_users   
  14.     }   
  15. define service{   
  16.     use         generic-service   
  17.     host_name       linhost   
  18.     service_description Load   
  19.     check_command       check_nrpe!check_load   
  20.     }   
  21. define service{   
  22.     use         generic-service   
  23.     host_name       linhost   
  24.     service_description SDA1   
  25.     check_command       check_nrpe!check_hda1   
  26.     }   
  27. define service{   
  28.     use         generic-service   
  29.     host_name       linhost   
  30.     service_description Zombie   
  31.     check_command       check_nrpe!check_zombie_procs   
  32.     }   
  33. define service{   
  34.     use         generic-service   
  35.     host_name       linhost   
  36.     service_description Total procs   
  37.     check_command       check_nrpe!check_total_procs   
  38.     } 

這里重點(diǎn)說下,Nagios服務(wù)端定義服務(wù)的命令完全是根據(jù)被監(jiān)控端NRPE中內(nèi)置的監(jiān)控命令,如下圖所示

wKioL1QnZhGQMN-ZAAM_Km8AoXQ787.jpg

5、啟動所定義的命令和服務(wù)

  1. [root@Nagios ~]# vim /usr/local/nagios/etc/nagios.cfg    
  2. #增加一行   
  3. cfg_file=/usr/local/nagios/etc/objects/linhost.cfg 

6、配置文件語法檢查

  1. [root@Nagios ~]# service nagios configtest   
  2.     
  3. Nagios Core 4.0.7   
  4. Copyright (c) 2009-present Nagios Core Development Team and Community Contributors   
  5. Copyright (c) 1999-2009 Ethan Galstad   
  6. Last Modified: 06-03-2014   
  7. License: GPL   
  8.     
  9. Website: http://www.nagios.org   
  10. Reading configuration data...   
  11.    Read main config file okay...   
  12.    Read object config files okay...   
  13.     
  14. Running pre-flight check on configuration data...   
  15.     
  16. Checking objects...   
  17.     Checked 20 services.   
  18.     Checked 3 hosts.   
  19.     Checked 2 host groups.   
  20.     Checked 0 service groups.   
  21.     Checked 1 contacts.   
  22.     Checked 1 contact groups.   
  23.     Checked 26 commands.   
  24.     Checked 5 time periods.   
  25.     Checked 0 host escalations.   
  26.     Checked 0 service escalations.   
  27. Checking for circular paths...   
  28.     Checked 3 hosts   
  29.     Checked 0 service dependencies   
  30.     Checked 0 host dependencies   
  31.     Checked 5 timeperiods   
  32. Checking global event handlers...   
  33. Checking obsessive compulsive processor commands...   
  34. Checking misc settings...   
  35.     
  36. Total Warnings: 0   
  37. Total Errors:   0   
  38.     
  39. Things look okay - No serious problems were detected during the pre-flight check   
  40. Object precache file created:   
  41. /usr/local/nagios/var/objects.precache 

7、重新啟動nagios服務(wù)

  1. [root@Nagios ~]# service nagios restart   
  2. Running configuration check...   
  3. Stopping nagios: done.   
  4. Starting nagios: done. 

8、打開Nagios web監(jiān)控頁面

1)首先點(diǎn)擊【Hosts】查看監(jiān)控主機(jī)狀態(tài)是否為UP

wKiom1Qm8WfyoR-sAAF5rctJNZ8410.jpg

2)其次點(diǎn)擊【Services】查看各監(jiān)控服務(wù)的狀態(tài)是否為OK

注意:在監(jiān)控新添加的主機(jī)linhost;出現(xiàn)狀態(tài)為CRITICAL,提示沒有那個文件或目錄。下面是解決辦法

wKiom1Qm8WfCZrd-AAb-FyGH-V4273.jpg

在監(jiān)控Linhost主機(jī)時出現(xiàn)一個CRITICAL的警告,查找解決辦法

wKioL1Qm8jyzbPBcAAEWP2KVKxc476.jpg

  1. ###被監(jiān)控端修改NRPE配置文件并重啟NRPE服務(wù)   
  2. [root@ClientNrpe etc]# vim nrpe.cfg    
  3. command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1  
  4. [root@ClientNrpe etc]# service nrped restart   
  5.     
  6. ###監(jiān)控端修改linhost.cfg配置文件并重啟nagios和httpd服務(wù)   
  7. [root@Nagios objects]# vim linhost.cfg    
  8. #注釋:原來這里是hda1,現(xiàn)在修改成sda1   
  9. define service{   
  10.         use                     generic-service   
  11.         host_name               linhost   
  12.         service_description     SDA1   
  13.         check_command           check_nrpe!check_sda1   
  14.         }   
  15. [root@Nagios ~]# service nagios restart   
  16. Running configuration check...   
  17. Stopping nagios: done.   
  18. Starting nagios: done.   
  19. [root@Nagios ~]# service httpd restart   
  20. 停止 httpd:                                               [確定]   
  21. 正在啟動 httpd:                                           [確定] 

再次點(diǎn)擊【services】即為刷新頁面,查看如下圖所示:

wKioL1Qm9JKADd8SAAa9TVtAuVc417.jpg

博文出自:http://467754239.blog.51cto.com/4878013/1558897

責(zé)任編輯:林師授 來源: 51CTO
相關(guān)推薦

2011-03-28 17:35:44

NagiosNRPE監(jiān)控

2011-03-24 11:03:05

Nagios監(jiān)控Linux

2011-03-23 09:47:03

Nagios監(jiān)控

2011-03-21 13:10:13

NagiosWindows

2011-03-23 10:17:25

Nagios監(jiān)控

2011-03-31 16:09:21

Redhat配置nagios

2011-03-21 14:53:27

Nagios監(jiān)控Linux

2014-10-28 11:01:36

LinuxNRPE

2011-03-28 17:29:47

nagiospluginnrpe

2011-03-23 09:11:40

Nagios監(jiān)控

2011-03-21 15:42:14

LinuxNagios

2011-03-21 14:53:36

Nagios監(jiān)控Linux

2011-04-06 14:24:20

Nagios監(jiān)控Linux

2011-03-21 14:53:27

Nagios監(jiān)控Linux

2011-04-06 14:24:21

Nagios監(jiān)控Linux

2011-03-22 09:07:13

Nagios監(jiān)控Linux

2011-03-24 10:08:39

Nagios監(jiān)控oracle

2011-03-04 10:47:06

Nagios監(jiān)控Sphinx

2011-04-06 14:24:28

nagios監(jiān)控Linux

2011-03-28 17:18:57

nagios監(jiān)控iostat
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號