linux环境中安装NRPE插件执行远程"本地资源"检查?NRPE安装?

需求描述:

  在安装完nagios之后,需要对本地资源进行监控,比如磁盘空间的使用,进程数,swap空间,等等.这些都不是通过网络提供出来的,

  所以,都是本地资源,可以通过NRPE插件实现在客户端中采集数据,然后通过网络传递给监控服务器,由监控服务器实现对传递过来

  的数据进行判断.

环境描述:

  操作系统:RedHat6.6 x64

安装过程:

----客户端----

1.关闭selinux

[[email protected] ~]# sed -i ‘s/SELINUX=.*/SELINUX=disabled/g‘ /etc/selinux/config
[[email protected] ~]# getenforce
Permissive

2.下载,上传nagios-plugins插件和nrpe插件

nagios-plugins下载地址:https://www.nagios.org/downloads/nagios-plugins/

nrpe下载地址:https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz

[[email protected] software]# ls -ltr
total 3080
-rw-r--r--. 1 root root  419695 Jul 31 16:18 nrpe-2.15.tar.gz
-rw-r--r--. 1 root root 2728818 Jul 31 16:18 nagios-plugins-2.2.1.tar.gz

3.安装nrpe之前需要先安装nagios-plugins

  3.1安装需需要的软件包

yum install -y gcc glibc glibc-common make gettext automake autoconf wget openssl-devel net-snmp net-snmp-utils

  3.2解压,编译,安装

[[email protected] software]# tar -zxf nagios-plugins-2.2.1.tar.gz
[[email protected] software]# cd nagios-plugins-2.2.1
[[email protected] nagios-plugins-2.2.1]# ./configure [[email protected] nagios-plugins-2.2.1]# make[[email protected] nagios-plugins-2.2.1]# make install

4.创建nagios用户组,用户

[[email protected] nagios-plugins-2.2.1]# groupadd nagios
[[email protected] nagios-plugins-2.2.1]# useradd -r -g nagios nagios

5.解压,编译,安装nrpe

[[email protected] software]# tar zxf nrpe-2.15.tar.gz
[[email protected] software]# cd nrpe-2.15
[[email protected] nrpe-2.15]# ./configure [[email protected] nrpe-2.15]# make all  [[email protected] nrpe-2.15]# make install-daemon          #安装nrpe命令.[[email protected] nrpe-2.15]# make install-daemon-config   #安装nrpe配置文件/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/usr/bin/install -c -m 644 -o nagios -g nagios sample-config/nrpe.cfg /usr/local/nagios/etc

6.编辑nrpe.cfg(/usr/local/nagios/etc/nrpe.cfg)配置文件,增加监控主机的地址

allowed_hosts=127.0.0.1,192.168.53.25      #找到allowed_hosts,增加监控主机的地址.

7.将nrpe的启动脚本加入到/etc/init.d目录,加入到开机启动

[[email protected] etc]# cd /opt/software/nrpe-2.15
[[email protected] nrpe-2.15]# cp init-script /etc/init.d/nrpe
[[email protected] nrpe-2.15]# chmod +x /etc/init.d/nrpe
[[email protected] nrpe-2.15]# chkconfig --add nrpe
[[email protected] nrpe-2.15]# chkconfig --list | grep nrpe
nrpe               0:off    1:off    2:on    3:on    4:on    5:on    6:off

8.启动nrpe服务,查看程序监听的端口

[[email protected] nrpe-2.15]# service nrpe start
Starting nrpe:                                             [  OK  ]
[[email protected] nrpe-2.15]# ps -ef | grep nrpe
nagios   23979     1  0 16:43 ?        00:00:00 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
root     23982  1050  0 16:43 pts/0    00:00:00 grep nrpe

[[email protected] nrpe-2.15]# netstat -ntlp | grep nrpetcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      23979/nrpe           #nrpe监听端口是5666tcp        0      0 :::5666                     :::*                        LISTEN      23979/nrpe  

----监控服务器----

1.关闭selinux

[[email protected] ~]# sed -i ‘s/SELINUX=.*/SELINUX=disabled/g‘ /etc/selinux/config
[[email protected] ~]# getenforce
Permissive

2.上传nrpe包,解压,编译,安装

[[email protected] softwares]# tar zxf nrpe-2.15.tar.gz
[[email protected] softwares]# cd nrpe-2.15
[[email protected] nrpe-2.15]# ./configure [[email protected] nrpe-2.15]# make all[[email protected] nrpe-2.15]# make install-plugin         #安装check_nrpe插件而不是nrpe命令,要注意.

3.检查nrpe_check插件已经正确安装

[[email protected] nrpe-2.15]# ls /usr/local/nagios/libexec/check_nrpe
/usr/local/nagios/libexec/check_nrpe

4.在nagios的commands.cfg中加入nrpe命令

define command {    command_name check_nrpe    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$}

#特别注意不要有中文的中划线

5.创建主机配置文件,修改cfg文件的权限

define host {

    use                     linux-server    host_name               192.168.53.26    address                 192.168.53.26}

define service {

    use                     generic-service,graphed-service           ; Name of service template to use    host_name               192.168.53.26    service_description     System_Load    check_command           check_nrpe!check_load}

define service {    use                 generic-service,graphed-service    host_name           192.168.53.26    service_description disk_usage    check_command       check_nrpe!check_disk}

[[email protected] objects]# chown nagios:nagios 192.168.53.26.cfg

7.创建nagios配置文件的目录,将配置文件归类存放

mkdir -p /usr/local/nagios/etc/objects/commands
mkdir -p /usr/local/nagios/etc/objects/timeperiods
mkdir -p /usr/local/nagios/etc/objects/contacts
mkdir -p /usr/local/nagios/etc/objects/contactgroups
mkdir -p /usr/local/nagios/etc/objects/hosts
mkdir -p /usr/local/nagios/etc/objects/hostgroups
mkdir -p /usr/local/nagios/etc/objects/services
mkdir -p /usr/local/nagios/etc/objects/servicegroups
mkdir -p /usr/local/nagios/etc/objects/templates
mkdir -p /usr/local/nagios/etc/objects/others

将文件归类到具体的路径中:

[[email protected] objects]# ls -ltrtotal 96-rw-rw-r--. 1 nagios nagios  1797 Jul 31 11:38 contacts.cfg-rw-rw-r--. 1 nagios nagios  3512 Jul 31 11:38 timeperiods.cfg-rw-rw-r--. 1 nagios nagios  4074 Jul 31 11:38 windows.cfg-rw-rw-r--. 1 nagios nagios  3001 Jul 31 11:38 printer.cfg-rw-rw-r--. 1 nagios nagios  3484 Jul 31 11:38 switch.cfg-rw-rw-r--. 1 nagios nagios 12869 Jul 31 14:44 templates.cfg-rw-rw-r--. 1 nagios nagios  4905 Jul 31 14:47 localhost.cfg-rw-rw-r--. 1 nagios nagios  7120 Jul 31 16:54 commands.cfg-rw-r--r--. 1 nagios nagios   446 Jul 31 17:03 192.168.53.26.cfgdrwxr-xr-x. 2 root   root    4096 Jul 31 17:09 commandsdrwxr-xr-x. 2 root   root    4096 Jul 31 17:09 timeperiodsdrwxr-xr-x. 2 root   root    4096 Jul 31 17:09 contactsdrwxr-xr-x. 2 root   root    4096 Jul 31 17:09 contactgroupsdrwxr-xr-x. 2 root   root    4096 Jul 31 17:09 hostsdrwxr-xr-x. 2 root   root    4096 Jul 31 17:09 hostgroupsdrwxr-xr-x. 2 root   root    4096 Jul 31 17:09 servicesdrwxr-xr-x. 2 root   root    4096 Jul 31 17:09 servicegroupsdrwxr-xr-x. 2 root   root    4096 Jul 31 17:09 templatesdrwxr-xr-x. 2 root   root    4096 Jul 31 17:09 others[[email protected] objects]# mv 192.168.53.26.cfg hosts/[[email protected] objects]# mv localhost.cfg hosts/[[email protected] objects]# mv commands.cfg commands[[email protected] objects]# mv windows.cfg switch.cfg printer.cfg others/[[email protected] objects]# mv templates.cfg templates/[[email protected] objects]# mv timeperiods.cfg timeperiods/[[email protected] objects]# mv contacts.cfg contacts

8.修改nagios.cfg配置文件,增加cfg_dir配置,将cfg_file的都注释掉

cfg_dir=/usr/local/nagios/etc/objects/commands
cfg_dir=/usr/local/nagios/etc/objects/timeperiods
cfg_dir=/usr/local/nagios/etc/objects/contacts
cfg_dir=/usr/local/nagios/etc/objects/contactgroups
cfg_dir=/usr/local/nagios/etc/objects/hosts
cfg_dir=/usr/local/nagios/etc/objects/hostgroups
cfg_dir=/usr/local/nagios/etc/objects/services
cfg_dir=/usr/local/nagios/etc/objects/servicegroups
cfg_dir=/usr/local/nagios/etc/objects/templates             #不配置others目录,目的是对这些其他的设备不进行监控

# You can specify individual object config files as shown below:
#cfg_file=/usr/local/nagios/etc/objects/commands.cfg
#cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
#cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
#cfg_file=/usr/local/nagios/etc/objects/templates.cfg

# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

9.重启nagios

[[email protected] objects]# service nagios restart
Running configuration check... Stopping nagios: .done.
Starting nagios: Running configuration check... done.

10.查看监控页面

备注:系统负载已经能够正常的检查了.但是NRPE: Command ‘check_disk‘ not defined,有这个错误.

11.NRPE: Command ‘check_disk‘ not defined 处理,在客户端的nrpe.cfg中配置check_disk命令及告警

command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p / -C -w 20% -c 10% -p /boot    #指定检查特定的分区,设定告警,验证的百分比.#command后面的中括号内,就是定义的nrpe的命令.在server端调用的就是这个命令,然后在客户端执行,也可理解这个命令就是等号后面一长串的别名.

12.重启客户端的nrpe

[[email protected] etc]# service nrpe restart
Shutting down nrpe:                                        [  OK  ]
Starting nrpe:                                             [  OK  ]

13.查看nagios的页面

备注:已经能够监控到远程的磁盘空间使用情况了,并且设置了告警,其他的命令可以模拟这个.具体的调度命令要在libexec目录中.或者自行安装插件和命令.

另:

  • 针对磁盘空间设置告警值,检查哪个目录都是在客户端的nrpe.cfg文件中配置的.其他的检查也是在客户端配置告警百分比
  • 监控端,不需要启动nrpe进程,nrpe进程只是在客户端启动

文档创建时间:2018年7月31日18:05:31

原文地址:https://www.cnblogs.com/chuanzhang053/p/9397441.html

时间: 2024-07-29 05:32:59

linux环境中安装NRPE插件执行远程"本地资源"检查?NRPE安装?的相关文章

linux环境中执行Mysql脚本

1.首先进入shell~ 2.进入服务器后,输入mysql -h localhost -u root -p,进入MySql: 3.输入MySql密码: 4.将脚本复制到服务器,具体怎么做,可以用Xftp; 5.例如,我执行的test.sql,在/usr/local/test.sql目录下,在shell中输入source /usr/local/test.sql linux环境中执行Mysql脚本,布布扣,bubuko.com

[软件测试]Linux环境中简单清爽的Google Test (GTest)测试环境搭建(初级使用)

本文将介绍单元测试工具google test(GTEST)在linux操作系统中测试环境的搭建方法.本文属于google test使用的基础教程.在linux中使用google test之前,需要对如下知识有一些了解: (1)C/C++编程方法 (2)makefile的编写 (3)linux命令行操作 (4)GTEST背景知识:它是用来干什么的?它用什么语言编写的?它的一些基本语法?等等 以上知识不需要做到熟能生巧,只要达到入门级别,使用GTEST不会费任何力气,毕竟GTEST也不是一个高门槛的

WebRtc 研究笔记1 Arch linux 环境中下载, 编译

开篇第一句,我觉得是最最重要的: 注意: WebRtc 源码的编译基础工作: 翻墙!  一定要在命令行, 让Git Svn 等命令访问到google的服务器,否则会出现各种异常 我的环境是 ArchLinux X64, 翻墙的方法: 1.各种VPN 2.修改hosts 3.各种代理服务器 ... 使用到的软件包 jdk 1.6 ( jdk1.7 无法编译), svn, git 环境变量: // /etc/profile # java export JAVA_HOME=/opt/jdk expor

LINUX环境中tomcat启动错误:The servlets named X and Y are both mapped to the url-pattern [/Z] which is not permitted

最近有一个问题困扰了我3天,我在windows部署项目无误后,准备将项目发布到阿里云linux服务器上,发现启动报错了:LINUX环境中tomcat启动错误:The servlets named X and Y are both mapped to the url-pattern [/Z] which is not permitted,首先想到的是肯定部署代码或者项目配置文件的事,怀疑有可能是jar包出错了,果不其然,在项目的WebContent\WEB-INF\lib发现了servlet-ap

linux环境中通过useradd命令,创建用户的时候指定用户的base-dir

需求说明: 今天一个同事,问了一个这样的问题,在linux环境中,创建用户的时候,默认的是在/home目录下创建一个与用户名相同的家目录, 如何能够将这个/home更换成一个其他的,比如/opt/app下,研究了下,在此记录下 操作过程: 1.通过查看useradd命令的帮助文档,知道创建用户base_dir的配置在/etc/default/useradd文件中 [[email protected] ~]# cat /etc/default/useradd # useradd defaults

linux环境中通过/dev/urandom设备产生随机密码

需求说明: 今天在调试SVN的时候,需要创建用户的随机密码,想了下,在linux环境中是否能够生成呢,就搜索了下, 然后结合看到的帖子,分析一个可以生成密码的命令,在此记录下. 操作过程: 1.通过/dev/urandom工具生成随机密码 [[email protected] ~]# cat /dev/urandom | tr -dc a-zA-Z0-9#@ | head -c 13;echo[email protected][[email protected] ~]# cat /dev/ura

linux环境中安装iotop命令,解决-bash: iotop: command not found问题

需求描述: 今天在测试环境中,准备查看mysql各个线程占用的io的情况,准备使用iotop命令来查看,发现没有这个命令 [[email protected] Packages]# iotop -bash: iotop: command not found 问题解决 1.挂载系统镜像,找到iotop的rpm包,然后进行安装 [[email protected] Packages]# iotop -bash: iotop: command not found [[email protected]

Linux环境中各系统目录含义

在搭建Linux环境之后,各个系统目录的含义及保存哪类文件,详细说明如下: 1./bin:一般为可执行的二进制文件,为所有用户使用. 2./sbin:一般为可执行的二进制文件,只提供给管理员使用. 3./dev:设备文件,例如:网卡,磁盘等 4./etc:配置文件 5./home:用户的家目录 6./lib:共享库和内核模块 7./media和/mnt:挂载点 8./opt:可选的软件安装路径(已经不常用) 9./root:管理员的家目录 10./srv:服务运行的中间数据 11./tmp:临时

.NET程序员项目开发必知必会—Dev环境中的集成测试用例执行时上下文环境检查(实战)

Microsoft.NET 解决方案,项目开发必知必会. 从这篇文章开始我将分享一系列我认为在实际工作中很有必要的一些.NET项目开发的核心技术点,所以我称为必知必会.尽管这一些列是使用.NET/C#来展现,但是同样适用于其他类似的OO技术平台,这些技术点可能称不上完整的技术,但是它是经验的总结,是掉过多少坑之后的觉醒,所以有必要花几分钟时间记住它,在真实的项目开发中你就知道是多么的有帮助.好了,废话不说了,进入主题. 我们在开发服务时为了调试方便会在本地进行一个基本的模块测试,你也可以认为是集