软件安装---prometheus(笔记)

1.  Prometheus 的安装

1.1 下载地址

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

1.2 安装 Prometheus Server

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

1.2.1 上传安装包

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

1.2.2 解压安装包

  • 解压到/opt/module 目录下
[atguigu@hadoop202 software]$ tar -zxvf prometheus-2.29.1.linux-amd64.tar.gz -C 
/opt/module
  • 修改目录名
[atguigu@hadoop202 ~] cd /opt/module
[atguigu@hadoop202 module] mv prometheus-2.29.1.linux-amd64 prometheus-2.29.1

1.2.3 配置文件 prometheus.yml配置说明

vim prometheus.yml


# my global config
global:
  scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
  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
alerting:
  alertmanagers:
    - static_configs:
        - targets:
          # - alertmanager:9093

# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
  # - "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: "prometheus"

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

    static_configs:
      - targets: ["localhost:9090"]

配置说明:

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://hadoop202:9090/metrics 上拉取数据。
Prometheus 是可以在运行时自动加载配置的。启动时需要添加:--web.enable-lifecycle

1.3 安装 Pushgateway

Prometheus 在正常情况下是采用拉模式从产生 metric 的作业或者 exporter(比如专门监控主机的 NodeExporter)拉取监控数据。但是我们要监控的是 Flink on YARN 作业, 想要让 Prometheus 自动发现作业的提交、结束以及自动拉取数据显然是比较困难的。 PushGateway 就是一个中转组件,通过配置 Flink on YARN 作业将 metric 推到 PushGateway,Prometheus 再从 PushGateway 拉取就可以了。

1.3.1 上传安装包

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

1.3.2 解压安装包

  • 解压到/opt/module 目录下
[atguigu@hadoop202 software]$ tar -zxvf pushgateway-1.4.1.linux-amd64.tar.gz -C 
/opt/module
  • 修改目录名
[atguigu@hadoop202 ~] cd /opt/module
[atguigu@hadoop202 module] mv pushgateway-1.4.1.linux-amd64 pushgateway-1.4.1

1.4  安装 Alertmanager(选择性安装)

1.4.1 上传安装包

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

1.4.2 解压安装包

  • 解压到/opt/module 目录下
[atguigu@hadoop202 software]$ tar -zxvf alertmanager-0.23.0.linux-amd64.tar.gz -C 
/opt/module
  • 修改目录名
[atguigu@hadoop202 ~] cd /opt/module
[atguigu@hadoop202 module] mv alertmanager-0.23.0.linux-amd64 alertmanager-0.23.0

1.5 安装 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 版本的二进制包。

1.5.1 上传安装包

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

1.5.2 解压安装包

  • 解压到/opt/module 目录下
[atguigu@hadoop202 software]$ tar -zxvf node_exporter-1.2.2.linux-amd64.tar.gz -C 
/opt/module
  • 修改目录名
[atguigu@hadoop202 ~] cd /opt/module
[atguigu@hadoop202 module] mv node_exporter-1.2.2.linux-amd64 node_exporter-1.2.2
  •  启动并通过页面查看是否成功
执行./node_exporter
浏览器输入: http://hadoop202:9100/metrics ,可以看到当前 node exporter 获取到的当前主机的所有监控数据。

1.5.3 节点分发

  • 将解压后的目录分发到要监控的节点
[atguigu@hadoop202 module] xsync node_exporter-1.2.2

  • 修改 Prometheus 配置文件 prometheus.yml,在 1.2.3 的时候已经添加过配置
- targets: ['hadoop202:9100', 'hadoop203:9100', 'hadoop204:9100']

1.5.4 设置为开机自启

  • 创建 service 文件
[atguigu@hadoop202 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=atguigu
ExecStart= /opt/module/node_exporter-1.2.2/node_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target
  • 分发文件
[atguigu@hadoop202 module] sudo /home/atguigu/bin/xsync
/usr/lib/systemd/system/node_exporter.service
  • 设为开机自启动(所有机器都执行)
[atguigu@hadoop202 module] sudo systemctl enable node_exporter.service
  • 启动服务(所有机器都执行)
[atguigu@hadoop202 module] sudo systemctl start node_exporter.service

1.6 启 动 Prometheus Server 、 Pushgateway 和 Alertmanager

1.6.1 Prometheus Server 目录下执行启动命令

[atguigu@hadoop202 prometheus-2.29.1]$ nohup ./prometheus --config.file=prometheus.yml > ./prometheus.log 2>&1 &

1.6.2 Pushgateway 目录下执行启动命令

[atguigu@hadoop202 pushgateway-1.4.1]$ nohup ./pushgateway --web.listen-address :9091 > ./pushgateway.log 2>&1 &

1.6.3 在 Alertmanager 目录下启动

[atguigu@hadoop202 alertmanager-0.23.0]$ nohup ./alertmanager --config.file=alertmanager.yml > ./alertmanager.log 2>&1 &

1.6.4 打开 web 页面查看

  • 浏览器输入:http://hadoop202:9090/
  • 点击 Status,选中 Targets:

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

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值