栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Go语言

Prometheus 的安装

Go语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Prometheus 的安装

文章目录
  • 安装 Prometheus Server
    • 上传安装包
    • 解压安装包
    • 修改配置文件 prometheus.yml
  • 安装 Pushgateway
    • 上传安装包
    • 解压安装包
  • 安装 Alertmanager(选择性安装)
    • 上传安装包
    • 解压安装包
  • 安装 Node Exporter(选择性安装)
    • 上传安装包
    • 解压安装包
    • 节点分发
    • 设置为开机自启
  • 启 动 Prometheus Server 、 Pushgateway 和Alertmanager
    • Prometheus Server 目录下执行启动命令
    • Pushgateway 目录下执行启动命令
    • 在 Alertmanager 目录下启动
    • 打开 web 页面查看

官网:https://prometheus.io/
下载地址:https://prometheus.io/download/

下载如下四个组件
Prometheus Server
Pushgateway
Alertmanager(选择性安装)
Node Exporter(选择性安装)

安装 Prometheus Server

Prometheus 基于 Golang 编写,编译后的软件包,不依赖于任何的第三方依赖。只需要下载对应平台的二进制包,解压并且添加基本的配置即可正常启动Prometheus Server。

上传安装包

上传 prometheus-2.29.1.linux-amd64.tar.gz 到虚拟机的/opt/software 目录

解压安装包

➢ 解压到/opt/module 目录下

[root@hadoop102 software]$ tar -zxvf prometheus-2.29.1.linux-amd64.tar.gz -C /opt/module

➢ 修改目录名

[root@hadoop102 ~] cd /opt/module
[root@hadoop102 module] mv prometheus-2.29.1.linux-amd64 prometheus-2.29.1
修改配置文件 prometheus.yml
[root@hadoop102 prometheus-2.29.1]$ vim prometheus.yml

在 scrape_configs 配置项下添加配置:

一定要注意格式

scrape_configs:
  # The job name is added as a label `job=` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ['hadoop102:9090']

 # 添加 PushGateway 监控配置
  - job_name: 'pushgateway'

    static_configs:
      - targets: ['hadoop102:9091']
        labels:
          instance: pushgateway
      # 添加 Node Exporter 监控配置
  - job_name: 'node exporter'

    static_configs:
      - targets: ['hadoop102:9100', 'hadoop103:9100', 'hadoop104:9100']

配置说明:
1、global 配置块:控制 Prometheus 服务器的全局配置
➢ scrape_interval:配置拉取数据的时间间隔,默认为 1 分钟。
➢ evaluation_interval:规则验证(生成 alert)的时间间隔,默认为 1 分钟。
2、rule_files 配置块:规则配置文件
3、scrape_configs 配置块:配置采集目标相关, prometheus 监视的目标。Prometheus
自身的运行信息可以通过 HTTP 访问,所以 Prometheus 可以监控自己的运行数据。
➢ job_name:监控作业的名称
➢ static_configs:表示静态目标配置,就是固定从某个 target 拉取数据
➢ targets : 指 定 监 控 的 目 标 , 其 实 就 是 从 哪 儿 拉 取 数 据 。 Prometheus 会 从
http://hadoop102:9090/metrics 上拉取数据。
Prometheus 是可以在运行时自动加载配置的。启动时需要添加:–web.enable-lifecycle

安装 Pushgateway 上传安装包

上传 pushgateway-1.4.1.linux-amd64.tar.gz 到虚拟机的/opt/software 目录

解压安装包

➢ 解压到/opt/module 目录下

[root@hadoop102 software]$ tar -zxvf pushgateway-1.4.1.linux-amd64.tar.gz -C /opt/module

➢ 修改目录名

[root@hadoop102 ~] cd /opt/module
[root@hadoop102 module] mv pushgateway-1.4.1.linux-amd64 pushgateway-1.4.1
安装 Alertmanager(选择性安装) 上传安装包

上传 alertmanager-0.23.0.linux-amd64.tar.gz 到虚拟机的/opt/software 目录

解压安装包

➢ 解压到/opt/module 目录下

[root@hadoop102 software]$ tar -zxvf alertmanager-0.23.0.linux-amd64.tar.gz -C /opt/module

➢ 修改目录名

[root@hadoop102 ~] cd /opt/module
[root@hadoop102 module] mv alertmanager-0.23.0.linux-amd64 alertmanager-0.23.0
安装 Node Exporter(选择性安装)

在 Prometheus 的架构设计中,Prometheus Server 主要负责数据的收集,存储并且对外提供数据查询支持,而实际的监控样本数据的收集则是由 Exporter 完成。因此为了能够监控到某些东西,如主机的 CPU 使用率,我们需要使用到 Exporter。Prometheus 周期性的从 Exporter 暴露的 HTTP 服务地址(通常是/metrics)拉取监控样本数据。
Exporter 可以是一个相对开放的概念,其可以是一个独立运行的程序独立于监控目标以外,也可以是直接内置在监控目标中。只要能够向 Prometheus 提供标准格式的监控样本数据即可。
为了能够采集到主机的运行指标如 CPU, 内存,磁盘等信息。我们可以使用 Node Exporter。Node Exporter 同样采用 Golang 编写,并且不存在任何的第三方依赖,只需要下载,解压即可运行。可以从 https://prometheus.io/download/ 获取最新的 node exporter 版本的二进制包。

上传安装包

上传 node_exporter-1.2.2.linux-amd64.tar.gz 到虚拟机的/opt/software 目录

解压安装包

➢ 解压到/opt/module 目录下

[root@hadoop102 software]$ tar -zxvf node_exporter-1.2.2.linux-amd64.tar.gz -C /opt/module

➢ 修改目录名

[root@hadoop102 ~] cd /opt/module
[root@hadoop102 module] mv node_exporter-1.2.2.linux-amd64 node_exporter-1.2.2

➢ 启动并通过页面查看是否成功
执行./node_exporter
浏览器输入:http://hadoop102:9100/metrics,可以看到当前 node exporter 获取
到的当前主机的所有监控数据。

节点分发

➢ 将解压后的目录分发到要监控的节点

[root@hadoop102 module] xsync node_exporter-1.2.2

➢ 修改 Prometheus 配置文件 prometheus.yml,

 - targets: ['hadoop202:9100', 'hadoop203:9100', 'hadoop204:9100']
设置为开机自启

➢ 创建 service 文件

[root@hadoop102 module] sudo vim /usr/lib/systemd/system/node_exporter.service


[Unit]
Description=node_export
Documentation=https://github.com/prometheus/node_exporter
After=network.target

[Service]
Type=simple
User=root
ExecStart= /opt/module/node_exporter-1.2.2/node_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target

➢ 分发文件

[root@hadoop102 module] xsync /usr/lib/systemd/system/node_exporter.service

➢ 设为开机自启动(所有机器都执行)

[root@hadoop102 module] sudo systemctl enable node_exporter.service

➢ 启动服务(所有机器都执行)

[root@hadoop102 module] sudo systemctl start node_exporter.service
启 动 Prometheus Server 、 Pushgateway 和Alertmanager Prometheus Server 目录下执行启动命令
[root@hadoop102 prometheus-2.29.1]$ nohup ./prometheus --config.file=prometheus.yml > ./prometheus.log 2>&1 &
Pushgateway 目录下执行启动命令
[root@hadoop102 pushgateway-1.4.1]$ nohup ./pushgateway --web.listen-address :9091 > ./pushgateway.log 2>&1 &
在 Alertmanager 目录下启动
[root@hadoop102 alertmanager-0.23.0]$ nohup ./alertmanager--config.file=alertmanager.yml > ./alertmanager.log 2>&1 &
打开 web 页面查看

➢ 浏览器输入:http://hadoop102:9090/

点击 Status,选中 Targets:

prometheus、pushgateway 和 node exporter 都是 up 状态,表示安装启动成功:

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/903894.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号