一、Prometheus和Grafana搭建

一、服务端Prometheus二进制安装
https://prometheus.io/

下载过慢可使用迅雷下载

tar -zxvf prometheus-2.53.0.linux-amd64.tar.gz

启动

./prometheus --config.file=prometheus.yml

将其配置为系统服务:

vim /usr/lib/systemd/system/prometheus.service
[Unit]
Description=https://prometheus.io

[Service]
Restart=on-failure
ExecStart=/prometheus/prometheus-2.53.0/prometheus --config.file=/prometheus/prometheus-2.53.0/prometheus.yml --storage.tsdb.path=/prometheus/data --storage.tsdb.retention.time=60d --web.enable-lifecycle
[Install]
WantedBy=multi-user.target

web.enable-lifecycle是让prometheus热重启,开启以后请求reload

curl -XPOST http://ip:9090/-/reload或者浏览器直接请求

启动Prometheus:

systemctl start prometheus

查看Prometheus状态:

systemctl status prometheus

访问地址:http://127.0.0.1:9090

二、Grafana安装
https://grafana.com/grafana/download
tar -zxvf grafana-enterprise-11.1.0.linux-amd64.tar.gz

将其配置为系统服务:

vim /usr/lib/systemd/system/grafana.service
[Unit]
Description=https://docs.grafana.org

[Service]
Restart=on-failure
ExecStart=/prometheus/grafana/bin/grafana-server --config=/prometheus/grafana/conf/defaults.ini --homepath=/prometheus/grafana/
[Install]
WantedBy=multi-user.target

修改defaults.ini:

default_language = zh-Hans

启动grafana:

systemctl start grafana

查看grafana状态:

systemctl status grafana

访问地址:http://127.0.0.1:3000 默认账号密码都是admin

三、客户端node_exporter安装
https://prometheus.io/download/
tar -zxvf attachment\;\ filename\=node_exporter-1.8.1.linux-amd64.tar.gz

将其配置为系统服务:

vim /usr/lib/systemd/system/node_exporter.service
[Unit]
Description=node_exporter
Documentation=https://prometheus.io
[Service]
Restart=on-failure
ExecStart=/prometheus/node_exporter/node_exporter 
[Install]
WantedBy=multi-user.target

启动node_exporter:

systemctl start node_exporter

查看node_exporter状态:

systemctl status node_exporter

访问地址:http://127.0.0.1:9100/metrics

四、将node_exporter加到Prometheus中

修改prometheus.yml,在scrape_configs下添加

  - job_name: "node_exporter"
    static_configs:
      - targets: ["192.168.0.1:9100","192.168.0.2:9100"]
# targets处可添加多个节点

重新加载配置文件

curl -XPOST http://127.0.0.1:9090/-/reload

之后在Prometheus的status下的targets下可以看到node_exporter

五、Grafana添加仪表盘

1.添加prometheus

连接-》数据源-》添加新数据源-》选择prometheus-》在connection处添加prometheus地址-》save & test

2.添加仪表板

仪表板-》新建仪表板-》导入仪表板-》在https://grafana.com/grafana/dashboards选择仪表板并copy id to clipboard-》在导入仪表板的界面粘贴ID并加载

模板下载样例:https://grafana.com/grafana/dashboards/16098-node-exporter-dashboard-20240520-job/ ,内网环境使用JSON导入

相关推荐

  1. PrometheusGrafana

    2024-07-10 03:40:03       27 阅读
  2. JVM监控环境Grafana+Prometheus+Micrometer

    2024-07-10 03:40:03       54 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-07-10 03:40:03       99 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-07-10 03:40:03       107 阅读
  3. 在Django里面运行非项目文件

    2024-07-10 03:40:03       90 阅读
  4. Python语言-面向对象

    2024-07-10 03:40:03       98 阅读

热门阅读

  1. 指向如此神奇:揭示Js函数this的10个惊人事实!

    2024-07-10 03:40:03       27 阅读
  2. k8s 使用 helm 文件部署 8.12.2 es 分角色集群

    2024-07-10 03:40:03       22 阅读
  3. 数据编码的艺术:sklearn中的数据转换秘籍

    2024-07-10 03:40:03       26 阅读
  4. android pdf框架-11,查看图片

    2024-07-10 03:40:03       22 阅读
  5. 深入探索:scikit-learn中递归特征消除(RFE)的奥秘

    2024-07-10 03:40:03       30 阅读
  6. 需求分析分类和层级、分析步骤

    2024-07-10 03:40:03       25 阅读
  7. js list to tree

    2024-07-10 03:40:03       20 阅读
  8. 02更新用户在线状态

    2024-07-10 03:40:03       23 阅读
  9. CSS魔法:link与@import的秘密较量

    2024-07-10 03:40:03       23 阅读
  10. 第12章:软件系统分析与设计

    2024-07-10 03:40:03       22 阅读
  11. Rust入门实战 编写Minecraft启动器#2建立资源模型

    2024-07-10 03:40:03       26 阅读