Prometheus介绍&部署

普罗米修斯概述

Prometheus是最初在SoundCloud上构建的开源系统监视和警报工具包 。自2012年成立以来,许多公司和组织都采用了Prometheus,该项目拥有非常活跃的开发人员和用户社区。现在,它是一个独立的开源项目,并且独立于任何公司进行维护。为了强调这一点并阐明项目的治理结构,Prometheus 于2016年加入了 Cloud Native Computing Foundation,这是继Kubernetes之后的第二个托管项目。
在这里插入图片描述

Prometheus 的优点

非常少的外部依赖,安装使用超简单
已经有非常多的系统集成 例如:docker HAProxy Nginx JMX等等
服务自动化发现
直接集成到代码
设计思想是按照分布式、微服务架构来实现的
Prometheus 的特性

一个多维数据模型,其中包含通过度量标准名称和键/值对标识的时间序列数据
PromQL,一种灵活的查询语言 ,可利用此维度
不依赖分布式存储;单服务器节点是自治的
时间序列收集通过HTTP上的拉模型进行
通过中间网关支持推送时间序列
通过服务发现或静态配置发现目标
多种图形和仪表板支持模式
组件

Prometheus生态系统包含多个组件

其中许多是可选的:
Prometheus Server:服务端;收集和储存时间序列数据;
Client Library:客户端库;目的在于为那些期望原生提供Instrumentation功能的应用程序提供便捷的开发途径
Exporters :指标暴露器
Push Gateway:接收那些通常由短期作业生成的指标数据的网关
Prometheus Service Discovery(sd):服务动态发现待监控的Target,发送告警信息
Prometheus scrape:数据采集器
Alertmanager:由告警规则对接
Instrumentation:应用程序内置的指标暴露器
Data Visualization(Dashboards):(prome-UI界面)

  • 大多数Prometheus组件都是用Go编写的,因此易于构建和部署为静态二进制文件。

Prometheus原理架构图

下说明了Prometheu的体系结构及其某些生态系统组件:
在这里插入图片描述

prometheus部署

主机名:prometheus 192.168.3.11 安装包:prometheus-2.27.1.linux-amd64.tar.gz
主机名:server1 192.168.3.12 安装包:node_exporter-1.1.2.linux-amd64.tar.gz
主机名:server2 192.168.3.13

准备工作关闭防火墙及安全机制,修改主机名
[root@localhost ~]# hostnamectl set-hostname prometheus
[root@localhost ~]# vim /etc/resolv.conf 
[root@localhost ~]# ntpdate ntp.aliyun.com
 9 Dec 09:58:33 ntpdate[65752]: adjust time server 203.107.6.88 offset 0.002275 sec
[root@localhost ~]# systemctl stop firewalld.service 
[root@localhost ~]# systemctl disable firewalld.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0
安装包
[root@localhost local]# tar -zxvf prometheus-2.27.1.linux-amd64.tar.gz -C /usr/local
[root@localhost local]# cd prometheus-2.27.1.linux-amd64/
[root@localhost prometheus-2.27.1.linux-amd64]# vim prometheus.ym1
[root@localhost prometheus-2.27.1.linux-amd64]# cat prometheus.ym1
my global config
global:
  scrape_interval:     15s
  evaluation_interval:
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - alertmanager:9093
rule_files:
- "first_rules.yml"
- "second_rules.yml"
    - job_name: 'prometheus'
      static_configs:
      - targets: ['localhost:9090']
[root@localhost prometheus-2.27.1.linux-amd64]# ./prometheus   #开启

在这里插入图片描述
详细讲解,如下

vim prometheus.yml
my global config
global:		##全局组件
  scrape_interval:     15s # Set the scrape interval to every 15 seconds. Default is every 1 minute. ##每隔多久抓取一次指标,不设置默认1分钟
  evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.	 ##内置告警规则的评估周期
 #scrape_timeout is set to the global default (10s).

# Alertmanager configuration		##对接的altermanager(第三方告警模块)
alerting:
  alertmanagers:
  - static_configs:
    - targets:
      - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:		##告警规则;告警规则可以使用yml规则去书写
- "first_rules.yml"
- "second_rules.yml"

# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:		##数据采集模块
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.		##对于所抓取的指标数据采集的来源在意job_name来定义
  	- job_name: 'prometheus'		##对于指标需要打上的标签,对于PrometheusSQL(查询语句)的标签:比如prometheus{target='values'}

  	 # metrics_path defaults to '/metrics' 		 ##收集数据的路径;展示使用metrics模式
    	 # scheme defaults to 'http'.		##默认抓取的方式是http

   	 static_configs:		##对于Prometheus的静态配置监听端口具体数据收集的位置 默认的端口9090
   	 - targets: ['localhost:9090']	
访问web页面
./prometheus		##直接开启Prometheus
netstat -antp | grep 9090		##另开一个终端查看9090端口

在这里插入图片描述
查看表达式浏览器
访问192.168.3.11:9090 ##查看采集数据 Prometheus会进行周期性的采集数据(完整的),多次周期性(在一个时间区间内)采集的数据集合,形成时间序列
在这里插入图片描述
访问192.168.3.11:9090/metrics:查看prometheus自带的内键指标
在这里插入图片描述
部署监控其他节点
prometheus想要监控其他节点,则需要借助node_exporter,下载地:https://prometheus.io/docs/concepts/data_model/,腾讯云盘prometheus安装包

5.1、解压安装包,命令优化路径,设置服务控制,开启服务
server1,2,3节点操作:上传压缩包加载node_exporter

[root@localhost ~]# rz
[root@localhost ~]# ls
anaconda-ks.cfg                         uuu.sh    文档
fc.sh                                   zuoye.sh  下载
fuhao.sh                                公共      音乐
initial-setup-ks.cfg                    模板      桌面
mybak.sh                                视频
node_exporter-1.1.2.linux-amd64.tar.gz  图片
[root@localhost ~]# tar -zxvf node_exporter-1.1.2.linux-amd64.tar.gz 
node_exporter-1.1.2.linux-amd64/
node_exporter-1.1.2.linux-amd64/LICENSE
node_exporter-1.1.2.linux-amd64/NOTICE
node_exporter-1.1.2.linux-amd64/node_exporter
[root@localhost ~]# cd node_exporter-1.1.2.linux-amd64/
[root@localhost node_exporter-1.1.2.linux-amd64]# cp node_exporter /usr/local/bin/

开启服务方法

./node_exporter
再开一个会话查询端口号 netstat -antp | grep 9100		

```![在这里插入图片描述](https://img-blog.csdnimg.cn/3828d8dd5f01420087091abb61b7546c.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ZC05bCP55m95ZGi,size_20,color_FFFFFF,t_70,g_se,x_16)

![在这里插入图片描述](https://img-blog.csdnimg.cn/2f3c188cdee44f1ba8f8be56d60e2f0e.png)
访问192.168.35.12:9100 查看抓取内容在这里插入代码片在这里插入代码片
![在这里插入图片描述](https://img-blog.csdnimg.cn/522d7b981afb43f09010d9ec41239ab1.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ZC05bCP55m95ZGi,size_20,color_FFFFFF,t_70,g_se,x_16)
![在这里插入图片描述](https://img-blog.csdnimg.cn/dcbcfd74dc3f441bb88f257499603ef7.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ZC05bCP55m95ZGi,size_20,color_FFFFFF,t_70,g_se,x_16)

访问http://192.168.3.11:9090/ 点击—>status—>targets
![在这里插入图片描述](https://img-blog.csdnimg.cn/88cc459f25ab4c4e8971fcb52840edc4.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5ZC05bCP55m95ZGi,size_20,color_FFFFFF,t_70,g_se,x_16)

加入其他节点监控端
需要在192.168.3.11 prometheus服务端停止prometheus修改配置文件添加静态targets才能使得server1节点加入
cd /usr/local/prometheus-2.27.1.linux-amd64/
vim prometheus.yml		##配置文件的最后添加以下内容
  - job_name: 'nodes'
    static_configs:
    - targets:
      - 192.168.3.12:9100
      - 192.168.3.13:9100

在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值