使用nagios nrpe监控远程Linux主机

监控linux本地主机时,我们可以直接更改配置文件进行监控,如果需要监控的主机与nagios不在同一机器上,即监控远程linux主机时,我们需要借助NRPE插件实现。
nrpe工作原理图:

远程主机的操作

下载Nagios Plugins和NRPE

  1. cd /tmp
  2. wget http://iweb.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz
  3. wget http://iweb.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz

创建nagios帐号

  1. useradd nagios
  2. passwd nagios

安装nagios-plugin

  1. cd /tmp
  2. tar xvfz nagios-plugins-1.4.16.tar.gz
  3. cd nagios-plugins-1.4.16
  4. export LDFLAGS=-ldl
  5.  
  6. ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround
  7. make
  8. make install
  9.  
  10. chown nagios.nagios /usr/local/nagios
  11. chown -R nagios.nagios /usr/local/nagios/libexec/

安装NRPE

  1. cd /tmp
  2. tar xvfz nrpe-2.13.tar.gz
  3. cd nrpe-2.13
  4.  
  5. ./configure
  6. make all
  7. make install-plugin
  8. make install-daemon
  9. make install-daemon-config
  10. yum install xinetd
  11. make install-xinetd

配置NRPE以守护进程运行

1、更改/etc/xinetd.d/nrpe文件,设置允许nagios服务器连接,如nagios服务器的ip为192.168.1.2:

  1. only_from       = 127.0.0.1 192.168.1.2

2、在/etc/services结尾增加:

  1. nrpe 5666/tcp # NRPE

3、启动xinetd

  1. service xinetd restart

4、验证nrpe是否监听

  1. netstat -at | grep nrpe

5、测试nrpe是否正常运行

  1. /usr/local/nagios/libexec/check_nrpe -H localhost
  2. NRPE v2.13

6、更改 /usr/local/nagios/etc/nrpe.cfg
nrpe.cfg文件里包含需要监控远程主机的命令,如:

  1. command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
  2. command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

nagios服务器的操作

首先安装nagios,参考:https://www.centos.bz/2012/02/centos-install-nagios/

下载安装NRPE

  1. cd /tmp
  2. wget http://iweb.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz
  3. tar xvfz nrpe-2.13.tar.gz
  4. cd nrpe-2.13
  5. ./configure
  6. make all
  7. make install-plugin

测试是否正常:

  1. /usr/local/nagios/libexec/check_nrpe -H 192.168.1.3
  2. NRPE v2.13

为监控远程主机定义host和service

1、定义check_nrpe命令
在文件/usr/local/nagios/etc/objects/commands.cfg后面增加:

  1. # 'check_nrpe' command definition
  2. define command{
  3. command_name check_nrpe
  4. command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$
  5. }

2、创建/usr/local/nagios/etc/objects/remotehost.cfg
host定义示例:

  1. define host{
  2. use linux-server
  3. host_name remotehost
  4. address 192.168.1.3
  5. }

Service定义示例:

  1. define service{
  2. use generic-service
  3. service_description Root Partition
  4. check_command check_nrpe!check_disk
  5. }

之后重载nagios配置文件使其生效

  1. service nagios reload

参考:http://www.thegeekstuff.com/2008/06/how-to-monitor-remote-linux-host-using-nagios-30/

标签:LinuxIOS监控 发布于:2019-11-23 06:17:29