21 PostgreSQL 监控2 趋势监控数据收集和分析 nagios 实时监控部署和自定义监控|学习笔记(二)

本文涉及的产品
云原生数据库 PolarDB MySQL 版,Serverless 5000PCU 100GB
简介: 快速学习21 PostgreSQL 监控2 趋势监控数据收集和分析 nagios 实时监控部署和自定义监控

开发者学堂课程【PostgreSQL快速入门21 PostgreSQL 监控2 趋势监控数据收集和分析nagios实时监控部署和自定义监控】学习笔记,与课程紧密联系,让用户快速学习知识。

课程地址:https://developer.aliyun.com/learning/course/16/detail/80


21 PostgreSQL 监控2 趋势监控数据收集和分析 nagios 实时监控部署和自定义监控


三、nagios 客户端安装

1、安装 nagios-pluging 下载最新稳定版

例如此时监控另一台服务器,在另一台服务器上输入

wget http://prdownloads. sourceforge.net/ sourceforge/nagiosplug/nagios-plugins-1.5.tar.gz

[root@db-172-16-3-39 soft_bak]# tar -zxvf nagios-plugins-1.5. t ar . gz

[root@db-172-16-3-39 soft_bak]# cd nagios-plugins-1.5添加执行监控脚本的用户.可以忽略.因为你可能会用 postgres 用户进行监控.

[root@db-172-16-3-39 nagios-plugins-1.5]# useradd nagios

下载完成后编译安装

[root@db-172-16-3-39 nagios-plugins-1.5]#./configure --with-nagios-user=postgres --with-nagios-group=postgres --

prefix=/opt/nagios         //我们使用的为 nagios 安装,若不想使用 nagios 监控,可以使用 postgre。若有些操作只能连接后监控,那么使用 postgre 用户监控,此处修改为 postgre 即可

[root@db-172-16-3-39 nagios-plugins-1.5]# make

[root@db-172-16-3-38 nagios-plugins-1.5]# make install

[root@db-172-16-3-39 nagios-plugins-1.5]# chown nagios:nagios / opt/nagios

[root@db-172-16-3-39 nagios-plugins-1.5]# chown -E nagios:nagios /opt/nagios/libexec

2、安装 xinetd 服务

[root@db-172-16-3-39 nagios-plugins-1.5]# yum install -y xinetd

3、安装 NRPE - Nagios Remote Plugin Executor

NRPE 是一个远程的插件, nagios server 通过 check_nrpe 来调用远端的这个插件监控远端服务.(nagios 通过调用nrpe 服务探测客户端状态,nrpe 再调用远程服务端脚本来达到监控目的)

其实 nagios server 通过 check_by_ssh 也可以来监控远端服务.只是使用 check_by_ssh 的 CPU 开销比较大.当被监控的服务很多的时候.就不适用了.所以推荐使用 check_nrpe.

image.png

图中有一个统一接口,例如返回值有统一规定,返回内容中也有一些统一的格式

NRPE 下载地址

http: //downloads.sourceforge.net/ project/nagios/ nrpe-2.x/ nrpe-2.15/nrpe-2.15. tar . gz?r=&ts=133786540&use_mirror=hivelocity

image.png

nrpe 已经更新到2.15,下载2.15版本

解压

[root@db-172-16-3-39 soft_bak]# tar -zxvf nrpe-2.15. tar . gz

[root@db-172-16-3-39 soft_bak]# cd nrpe-2.15   //nrpe 安装在客户端

[root@db-172-16-3-39 nrpe-2.15]# . /configure --prefix=/ opt/nagios // 安装到 opt/nagios 客户端

[root@db-172-16-3-39 nrpe-2.15]# make all

[root@db-172-16-3-39 nrpe-2.15]# make install-plugin

[root@db-172-16-3-39 nrpe-2.15]# make install-daemon

[root@db-172-16-3-39 nrpe-2.15]# make install-daemon-config

[root@db-172-16-3-39 nrpe-2.15]# make install-xinetd  //通过配置 xinetd 启上述服务

编辑 xinetd nrpe 配置文件.(注意此处不使用 nagios,使用 postgres)

修改 only_from,允许本地 lp 和 nagios server ip 连接.新增 log_type 配置.不写日志.

[root@db-172-16-3-33 nrpe-2.15]# vi /etc/xinetd.d/nrpe

#default : on

#description: NRPE (Nagios Remote Plugin Executor )

service nrpe

{

flags =REUSE

socket_type = stream

port = 5666

wait = no

user = postgres

group =  postgres

server=/opt/nagios/bin/nrpe

server_args =-c/opt/nagios/etc/nrpe.cfg--inetd

log_ on_ failure +=USERID

disable= no

only_ from=127.0.0.1 172.16.3.150    //only_from 需要添加主机,例如客户端为172.16.3.150

log_type =FILE/dev/null    //可以不写日志,将日志写入空文件

}

修改/etc/services

[root@db-172-16-3-39 nrpe-2.15]# vi /etc/services

nrpe 5666/tcp # NRPE,添加到文件末尾

每次修改/etc/xinetd.d/nrpe或/opt/nagios/etc/nrpe.cfg后需要重启 xinetd 服务.

[root@db-172-16-3-39 nrpe-2.15]# service xinetd restart //启动服务

Stopping xinetd: [FAILED]

Starting xinetd: [ OK ]

查看 nrpe 是否正常启动

[root@db-172-16-3-39 rarpe-2.15]# netstat -anpo|grep xinetd

tcp 0 00.0.0.0:5666 0.0.0.0:*LISTEN 933/xinetd off (0. 00/0/0)

unix 2[ ] DGRAM 7822940 933/xinetd

//例如此处输入netstat -anp|grep 5666,结果可以看到5666已经监控起来

[root@db-172-16-3-39 nrpe-2.15]# netstat -at|grep nrpe

tcp 0 0*:nrpe *:* LTSTEN

使用 check_nrpe 命令检查nrpe后台进程是否启动.

[root@db-172-16-3-39 nrpe-2.15]#/opt/nagios/libexec/ check_nrpe -H localhost   //使用check_nrpe 检测

NRPE v2.15     //NRPE 版本为2.15

以上返回表示正常.

使用 check_nrpe 通过tcp调用远端/opt/nagios/etc/nrpe.cfg 中配置的 command.

[root@db-172-16-3-39 nrpe-2.15]#/opt/nagios/libexec/ check_nrpe -H localhost -c check_load      //通过 tcp 远端调用查看是否可以正常检测到负载

OK - load average:0.00,0.02,0.00| load1=0.000;15.000;30.00;0;load5=0.020;10.000;25.000;0; load15=0.000;5.000; 20.000;0;  //检测正常

nagios server 也是通过调用 check_nrpe 来检测远端服务.所以在 nagios server 端需要安装 check_nrpe 插件.


四、nagios 服务端配置

安装 check_nrpe 插件.注意 prefi x与客户端不一样.还有只需要安装插件即可.

[root@db-172-16-3-33 soft_bak]# tar -zxvf nrpe-2.15. tar . gz

[root@db-172-16-3-33 soft_bak]# cd nrpe-2.15

[root@db-172-16-3-33 nrpe-2.15]# ./ configure --prefix=/ opt/nagios-4.0.3    //服务端放到opt/nagios 下

[root@db-172-16-3-33 nrpe-2.15]# make all

[root@db-172-16-3-33 nrpe-2.15]# make install-plugin

配置主配置文件/opt/nagios-4.0.3/etc/nagios.cfg

# You can specify individual object config files as shown below;

cfg_file=/opt/nagios-4.0.3/etc/ objects/ commands. cfg

cfg_file=/opt/nagios-4.0.3/etc/objects/contacts.cfg  //包含联系人

cfg_file=/ opt/nagios-4.0.3/etc/objects/ timeperiods.cfg  //超时

cfg_file=/opt/nagios-4.0.3/etc/objects templates.cfg  //模板

#Definitions for monitoring the local (Linux) host

cfg_file=/opt/nagios-4.0.3/ etc/objects/localhost.cfg

nagios 启动时会解析并加载这些配置文件.

编辑/opt/nagios-4.0.3/etc/objects/commands.cfg

将 check_nrpe 添加进去.

[root@db-172-16-3-33 db_servers]# vi /opt/nagios-4.0.3/etc/objects/ commands. Cfg

# add by digoal

define command {

command name check nrpe

command_line $USER1$/check_nrpe -H $HDSTADDRESS$ -c $AEG1$

} //通过用户进行调用 nrpe 探测主机地址  -c 为服务端提供的 argument $HDSTADDRESS$与$AEG1$ 后期传入

上面的 $USER1$ 定义在环境变量文件:/opt/nagios-4.0.3/etc/resource.cfg(接着在 resource.cfg 中配置环境变量)

#Sets $USER1$ to be the path to the plugins

$USER1$=/ opt/nagios-4.0.3/libexec   //进入后看到 USER1 已经定义好,不需要再进行修改

# Sets $USER2$ to be the path to event handlers

$USER2$=/opt/nagios-4.0.3/libexec/eventhanders

# Store some usernames and passwords (hidden from the CGIs)

#$USER3$=someuser

#$USER4$=somepassword

(可选)定义一个 linux 主机模板.名为 linux-box,原始的模板也在 templates.cfg 这个文件中.后面也会用到原始模板:

[root@db-172-16-3-33 db_servers]# vi / opt/nagios-4.0.3/ etc/objects/ templates.cfg

# add by digoal

#host template linux-box  //什么主机

define host {

name linux-box : Name of this template

use generic-host: Inherit default values

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

register 0   :DONT REGISTER THIS - ITS A TEMPLATE

}

配置完后可以检查配置文件,输入

/opt/nagios-4.0.3/bin/nagios -v /opt/nagios-4.0.3/etc/nagios.cfg

当然我们也可以定制配置文件目录,目录中以 cfg 结尾的文件,在 nagios 启动时都会解析和加载.修改主配置文件.在OBJECT CONFIGURATION FILE 配置组中新增如下行:

cfg_dir=/opt/nagios-4.0.3/etc/db_servers   //例如将所有的服务器配置文件定义到 db_servers 文件中

新建目录,修改权限

[root@db-172-16-3-33 etc]# mkdir -p / opt/nagios-4.0.3/ etc/ db_servers

[root@db-172-16-3-33 etc]# chown nagios : nagios /opt/nagios-4.0.3/etc/db_servers  //将权限赋予给 nagios 用户

在该目录中新建配置文件:

配置主机:

[root@db-172-16-3-33 etc]# cd / opt/nagios-4.0.3/ etc/ db_servers/

[root@db-172-16-3-33 db_servers]# vi hosts.cfg

define host{   //定义一台主机,该主机为监控主机3_33

use linux-box ; Inherit default values from a template    //使用 linux-box 的 template

host_name db_3_33 : The name we' re giving to this server

alias postgresql_3_33 :A longer name for the server

address 172.16.3.38 :IP address of the server

}

[root@db-172-16-3-33 db_servers]# chown nagios:nagios hosts.cfg

配置主机对应的服务∶

[root@db-172-16-3-33 db_servers]# cd /opt/nagios-4.0.3/etc/db_servers/

[root@db-172-16-3-33 db_servers]#vi services.cfg

define service {    //新增 service 文件,为监控内容

use generic-service

host_name db_3_33: this is host.host_name   //主机名为3_33

service_description Current Users

check_command check_nrpe| check_users :check_users对应客户湍/ opt/nagios/ etc/nrpe.cfg中定义的 command,后面亦如此

远程调用 check_nrpe,里面的 command为check_users,后面将 check_users 替换为/opt/nagios/libexec/check_users -w 5 -c 10,执行该命令

}      //远程调用check_nrpe

define service{

use generic-service

host_name db_3_33

service_description CPU Load

check_command check_nrpe | check_load

}

define service{

use generic-service

host_name db_3_3

service_description / dev/hda1 Free Space

check_command check_nrpe!check_hda1

}

define service{

use generic-service

host_name db_3_3

service_description / dev/hda2 Free Space

check_command check_nrpe!check_hda2

}

define service{

use generic-service

host_name db_3_33

service_description Total Processes

check_command check_nrpel check_total_procs

}

define service{

use generic-service

host_name db_3_33

service_description Zombie Processes

check_command check_nrpe! check_zombie _procs

}

服务定义好后修改配置文件权限

[root@db-172-16-3-33 db_servers]# chown nagios:nagios *. cfg

//显示结果都为 nagios 用户

检测配置文件是否合法

[root@db-172-16-3-33 db_servers]#/ opt/nagios-4.0.3/bin/ nagios -v /opt/nagios-4.0.3/ etc/nagios.cfg

image.png

过程显示如图:显示目前监控13个服务、2台主机

如果配置文件没有错误的话,重启 nagios

nagios 显示截图如下:

image.png

Nagios 左侧菜单栏 Hosts,点击就会发现有两台主机。点击 Services 可以看有多少服务。PENDING 表示目前还没有对它进行探测,过一段时间就会探测,因为有时间间隔,探测后状态才会变成正常状态。

重启服务:

[root@db-172-16-3-33 db_servers]# service nagios restart

Running configuration check . . done.

Stopping nagios: done.

Starting nagios: done.

客户端对应的 nrpe.cfg 配置

[root@db-172-16-3-39 nrpe-2.15]#vi/opt/nagio/etc/nrpe.cfg

command[check_users]=/opt/nagios/libexec/check_users -w 5 -c 10

command[check_load]=/opt/nagios/libexec/check_load-w15,10,5-c 30,25,20

command[check_hda1 ]=/opt/nagios/libexcec/ check_disk -w 20% -c 10% -p/

command[check_zombie_procs]=/ opt/nagios/libexec/ check_procs -w 5 -c 10 -s z

command[check_total_procs]=/ opt/nagios/libezec/check_ procs -w 150 -c 200

自定义监控也是配置这些东西.配置完后需要重启 xinetd 服务.

[rootedb-172-16-3-39 rarpe-2.15]# service xinetd restart

Stopping xinetd: [ OK ]

Starting xinetd: [ OK ]

相关实践学习
使用PolarDB和ECS搭建门户网站
本场景主要介绍基于PolarDB和ECS实现搭建门户网站。
阿里云数据库产品家族及特性
阿里云智能数据库产品团队一直致力于不断健全产品体系,提升产品性能,打磨产品功能,从而帮助客户实现更加极致的弹性能力、具备更强的扩展能力、并利用云设施进一步降低企业成本。以云原生+分布式为核心技术抓手,打造以自研的在线事务型(OLTP)数据库Polar DB和在线分析型(OLAP)数据库Analytic DB为代表的新一代企业级云原生数据库产品体系, 结合NoSQL数据库、数据库生态工具、云原生智能化数据库管控平台,为阿里巴巴经济体以及各个行业的企业客户和开发者提供从公共云到混合云再到私有云的完整解决方案,提供基于云基础设施进行数据从处理、到存储、再到计算与分析的一体化解决方案。本节课带你了解阿里云数据库产品家族及特性。
相关文章
|
运维 监控 数据可视化
ELK日志监控分析系统的探索与实践(二):利用Metricbeat监控服务器系统指标
在ELK日志监控分析系统的探索与实践(一)中,我们介绍了如何利用ELK+Filebeat监控Springboot项目的日志,本篇则是重点介绍如何利用ELk+Metricbeat监控服务器系统CPU、内存、磁盘等系统指标。
ELK日志监控分析系统的探索与实践(二):利用Metricbeat监控服务器系统指标
|
2月前
|
存储 Prometheus 监控
性能监控之国产时序库TDengine TDinsight dashboard 指标解析
【2月更文挑战第1天】性能监控之国产时序库TDengine TDinsight dashboard 指标解析
251 1
性能监控之国产时序库TDengine TDinsight dashboard 指标解析
|
6月前
|
存储 监控 前端开发
Zabbix分布式监控实战(一)——Zabbix 5.0监控平台搭建与被监控端的添加
Zabbix分布式监控实战(一)——Zabbix 5.0监控平台搭建与被监控端的添加
255 0
|
6月前
|
存储 消息中间件 监控
代码级别监控:常见的全链路监控工具介绍
代码级别监控:常见的全链路监控工具介绍
|
11月前
|
SQL 存储 缓存
MySQL性能监控全掌握,快来get关键指标及采集方法!
数据库中间件监控实战,MySQL中哪些指标比较关键以及如何采集这些指标了。帮助提早发现问题,提升数据库可用性。
1394 0
|
运维 监控 算法
Zabbix与乐维监控对比分析(八)——其他功能篇
本篇是Zabbix与乐维监控对比分析专题系列文章的第八篇,也是最后一篇,包括二者知识库、CMDB系统集成与ITSM系统集成等功能的对比分析。
123 0
Zabbix与乐维监控对比分析(八)——其他功能篇
|
运维 监控 算法
如何使用日志分析监控神农系统
我们将 SLS 的智能异常分析功能中的文本分析功能调整为模板发现和模板匹配两个子任务,提高了其在模板管理和应用上的灵活性。这里以对内部神农系统的运行日志监控为例,介绍改版后任务的使用场景与流程。
382 1
如何使用日志分析监控神农系统
|
数据采集 运维 监控
Zabbix与乐维监控对比分析(七)——网络功能篇
本篇是Zabbix与乐维监控对比专题系列文章的第七篇——网络功能篇,具体包括IP地址管理、网络端口映射发现、网络配置备份、专线监控等功能的对比分析
208 0
Zabbix与乐维监控对比分析(七)——网络功能篇
|
运维 监控 数据可视化
Zabbix与乐维监控对比分析(六)——图形图表篇
本篇是Zabbix与乐维监控对比分析专题系列文章的第六篇——图形图表篇,包括二者在模板图形及模板表格等功能的对比分析。
128 1
Zabbix与乐维监控对比分析(六)——图形图表篇
|
运维 监控 数据可视化
Zabbix与乐维监控对比分析(五)——可视化篇
前面我们详细介绍了Zabbix与乐维监控的架构与性能、Agent管理、自动发现、权限管理、对象管理、告警管理方面的对比分析,相信大家对二者的对比分析有了相对深入的了解,接下来我们将对二者的可视化功能进行对比分析。可视化是当代IT监控的一个创举,让IT监控很大程度摆脱枯燥烦杂的数据,使得监控过程变得更直观。
198 0
Zabbix与乐维监控对比分析(五)——可视化篇

热门文章

最新文章