prometheus 集成 grafana 保姆级别安装部署

前言

本文 grafana 展示效果只需要 prometheus + node_exporter + grafana 其他的选择安装

环境和版本号

系统: CentOS 7.9

prometheus: 2.54.1

pushgateway: 1.9.0

node_exporter: 1.8.2

alertmanager: 0.27.0

grafana:11.2.0

官网:https://prometheus.io/

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

1.安装 Prometheus Server

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

1.1.下载

复制代码
wget https://github.com/prometheus/prometheus/releases/download/v2.54.1/prometheus-2.54.1.linux-amd64.tar.gz

1.2.安装部署

➢ 解压到/opt/module 目录下

复制代码
tar -zxf prometheus-2.54.1.linux-amd64.tar.gz -C /opt/module/

➢ 修改目录名

复制代码
cd /opt/module
mv prometheus-2.54.1.linux-amd64  prometheus

➢ 修改目录权限

复制代码
chown -R root:root prometheus

1.3.修改配置文件prometheus.yml

vim prometheus.yml

在 scrape_configs 配置修改为

复制代码
# Alertmanager configuration
alerting:
  alertmanagers:
    - static_configs:
        - targets:
           - hadoop102:9093
           
scrape_configs:
  - job_name: "prometheus"
    static_configs:
      - targets: ["localhost:9090"]

  - job_name: 'pushgateway'
    static_configs:
      - targets: ['hadoop102:9091']
        labels:
          instance: pushgateway

  - job_name: 'node_exporter'
    static_configs:
      - targets: ['hadoop102:9100']

1.4.启动

复制代码
[root@hadoop102 prometheus]# nohup ./prometheus --config.file=prometheus.yml > ./prometheus.log 2>&1 &

打开 web 页面查看

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

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

(后面会安装部署pushgateway 和 node exporter 安装以后才会显示)

2.安装 Pushgateway(选择安装)

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

是否需要 Pushgateway

长时间运行的服务(例如 Node Exporter): 通常不需要 Pushgateway,因为 Prometheus 可以定期从 Node Exporter 拉取指标数据。

短期任务(例如批处理作业、一次性任务): 可能需要 Pushgateway,因为这些任务的生命周期短暂,Prometheus 可能无法定期拉取这些任务的指标数据。在这种情况下,短期任务会将指标数据推送到 Pushgateway,然后 Prometheus 从 Pushgateway 拉取数据。

2.1.下载

复制代码
wget https://github.com/prometheus/pushgateway/releases/download/v1.9.0/pushgateway-1.9.0.linux-amd64.tar.gz

2.2.安装部署

➢ 解压到/opt/module 目录下

复制代码
tar -zxf pushgateway-1.9.0.linux-amd64.tar.gz -C /opt/module/

➢ 修改目录名

复制代码
cd /opt/module
mv pushgateway-1.9.0.linux-amd64  pushgateway

➢ 修改目录权限

复制代码
 chown -R root:root pushgateway

2.3.启动

复制代码
[root@hadoop102 pushgateway]# nohup ./pushgateway --web.listen-address :9091 > ./pushgateway.log 2>&1 &

3.安装 Alertmanager(选择安装)

如果你需要处理告警和通知,Alertmanager 是必需的。Alertmanager 会接收 Prometheus 的告警,按照规则处理(例如,发送电子邮件、Slack 通知等),然后将处理后的告警信息发送到你定义的通知渠道。

3.1.下载

复制代码
wget https://github.com/prometheus/alertmanager/releases/download/v0.27.0/alertmanager-0.27.0.linux-amd64.tar.gz

3.2.安装部署

➢ 解压到/opt/module 目录下

复制代码
tar -zxf alertmanager-0.27.0.linux-amd64.tar.gz -C /opt/module/

➢ 修改目录名

复制代码
cd /opt/module
mv alertmanager-0.27.0.linux-amd64  alertmanager

➢ 修改目录权限

复制代码
chown -R root:root alertmanager

3.3.启动

复制代码
[root@hadoop102 alertmanager]# nohup ./alertmanager --config.file=alertmanager.yml > ./alertmanager.log 2>&1 &

打开 web 页面查看

浏览器输入:http://hadoop102:9093/

4.安装 Node Exporter

说明:如有多台服务器,需要每台服务器都安装Node Exporter

在 Prometheus 的架构设计中,Prometheus Server 主要负责数据的收集,存储并且对外提供数据查询支持,而实际的监控样本数据的收集则是由 Exporter 完成。因此为了能够监控到某些东西,如主机的 CPU 使用率,我们需要使用到 Exporter。Prometheus 周期性的从 Exporter 暴露的 HTTP 服务地址(通常是/metrics)拉取监控样本数据

4.1.下载

复制代码
wget https://github.com/prometheus/node_exporter/releases/download/v1.8.2/node_exporter-1.8.2.linux-amd64.tar.gz

4.2.安装部署

➢ 解压到/opt/module 目录下

复制代码
tar -zxf node_exporter-1.8.2.linux-amd64.tar.gz -C /opt/module/

➢ 修改目录名

复制代码
cd /opt/module
mv node_exporter-1.8.2.linux-amd64  node_exporter

➢ 修改目录权限

复制代码
chown -R root:root node_exporter

➢ 启动并通过页面查看是否成功

执行 ./node_exporter

浏览器输入:http://hadoop102:9100

4.3.设置为开机自启

➢ 创建 service 文件

复制代码
cat > /usr/lib/systemd/system/node_exporter.service << 'EOF'
[Unit]
Description=node_exporter
Documentation=https://github.com/prometheus/node_exporter
After=network.target

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

[Install]
WantedBy=multi-user.target
EOF

➢修改目录权限

复制代码
 chown -R root:root node_exporter

➢ 设为开机自启动

复制代码
sudo systemctl enable node_exporter.service

➢ 启动服务

复制代码
sudo systemctl start node_exporter.service

5.Prometheus 和 Grafana 集成

grafana 是一款采用 Go 语言编写的开源应用,主要用于大规模指标数据的可视化展现,

是网络架构和应用分析中最流行的时序数据展示工具,目前已经支持绝大部分常用的时序数

据库。下载地址https://grafana.com/grafana/download

5.1.下载

复制代码
wget https://dl.grafana.com/enterprise/release/grafana-enterprise-11.2.0.linux-amd64.tar.gz

5.2.安装部署

➢ 解压到/opt/module 目录下

复制代码
tar -zxf grafana-enterprise-11.2.0.linux-amd64.tar.gz -C /opt/module/

➢ 修改目录名

复制代码
cd /opt/module
mv grafana-v11.2.0  grafana

➢ 修改目录权限

复制代码
chown -R root:root grafana     

➢ 配置为中文

vim /opt/module/grafana/conf/defaults.ini

复制代码
# Default UI language (supported IETF language tag, such as en-US)
#default_language = en-US
default_language = zh-Hans

5.3.启动

cd /opt/module/grafana

复制代码
nohup ./bin/grafana-server web > ./grafana.log 2>&1 &

➢ 打开 web http://hadoop102:3000 默认用户名和密码:admin

5.4 添加数据源Prometheus


输入prometheus地址:

http://hadoop102:9090/

5.5 手动创建仪表盘 Dashboard



去市场搜一个模板

https://grafana.com/grafana/dashboards/

输入市场ID: 12633

效果如下:

至此部署完毕

相关推荐
牛奶咖啡1321 小时前
Prometheus+Grafana构建云原生分布式监控系统(十三)_Prometheus数据模型及其PromQL
云原生·prometheus·prometheus数据类型·promql使用场景·promql表达式解析·promql数据类型·监控系统的方法论与指标
AC赳赳老秦2 天前
外文文献精读:DeepSeek翻译并解析顶会论文核心技术要点
前端·flutter·zookeeper·自动化·rabbitmq·prometheus·deepseek
qq_312920113 天前
Proxmox VE 监控:把集群指标秒级推送到 InfluxDB 2.x,Grafana 大屏一步到位
运维·grafana
牛奶咖啡133 天前
Prometheus+Grafana构建云原生分布式监控系统(十二)_基于DNS的服务发现
云原生·prometheus·dns·搭建自己的dns服务器·使用bind搭建dns服务器·配置正向解析·基于dns的服务发现
A-刘晨阳4 天前
Prometheus + Grafana + Alertmanager 实现邮件监控告警及配置告警信息
运维·云计算·grafana·prometheus·监控·邮件
饺子大魔王的男人4 天前
告别服务器失联!Prometheus+Alertmanager+cpolar 让监控告警不局限于内网
运维·服务器·prometheus
电话交换机IPPBX-3CX5 天前
如何使用 Grafana 可视化你的 3CX 呼叫中心电话系统
grafana·ip pbx·电话交换机·企业电话系统
牛奶咖啡135 天前
Prometheus+Grafana构建云原生分布式监控系统(十一)_基于consul的服务发现
云原生·prometheus·consul的安装部署·consul服务自动发现·consul服务的注册删除·consul服务的更新·实现自动去consul注册服务
Otto_10276 天前
在 OpenStack Rocky 中部署 Prometheus + Grafana
openstack·grafana·prometheus
牛奶咖啡136 天前
Prometheus+Grafana构建云原生分布式监控系统(十)_prometheus的服务发现机制(一)
云原生·prometheus·prometheus服务发现·静态服务发现·动态服务发现·基于文件的服务发现配置实践·prometheus标签重写