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

效果如下:

至此部署完毕

相关推荐
Alone80468 小时前
prometheus概念
prometheus
研究司马懿2 天前
【云原生监控】Prometheus监控系统
云原生·prometheus·监控系统·promesql·企业级监控·二进制部署
wgc891782 天前
监控系列之-Grafana面板展示及制作
grafana
豆瑞瑞2 天前
压测服务器并使用 Grafana 进行可视化
grafana
研究司马懿2 天前
【云原生监控】Prometheus之PushGateway
云原生·prometheus·云原生监控·企业级监控系统·promesql
Aray12343 天前
Using Prometheus+Grafana+VMware-exporter to monitor VMware EXSi Hosts and VMs
grafana·prometheus
行走的山峰3 天前
在grafana上配置显示全部node资源信息概览
grafana
一瓢一瓢的饮 alanchan3 天前
【运维监控】系列文章汇总索引
java·运维·kafka·grafana·prometheus·influxdb·运维监控
MarkHD4 天前
Prometheus+grafana+kafka_exporter监控kafka运行情况
kafka·grafana·prometheus
MarkHD4 天前
Prometheus+grafana监控flink运行情况
flink·grafana·prometheus