服务器多节点 Grafana、Prometheus 和 Node-Exporter Docker版本部署指南

要在多台服务器上部署 Grafana、Prometheus 和 Node-Exporter,并且其中一台服务器专门用于 Grafana 和 Prometheus 的部署

1. 准备工作

  • 服务器信息

    • Server 1:用于部署 Grafana 和 Prometheus。

    • Server 2-n:用于部署 Node-Exporter。

  • Docker:确保所有服务器上已安装 Docker 和 Docker Compose。

https://getdocker.quickso.cn/

2. 在 Server 1 上部署 Grafana 和 Prometheus

2.1 创建 Docker Compose 文件

在 Server 1 上创建一个 docker-compose.yml 文件,内容如下:

复制代码
version: '3'

services:
  prometheus:
    image: prom/prometheus
    container_name: prometheus
    ports:
      - "9090:9090"
    volumes:
      - ./prometheus.yml:/etc/prometheus/prometheus.yml
    command:
      - '--config.file=/etc/prometheus/prometheus.yml'
    restart: always

  grafana:
    image: grafana/grafana
    container_name: grafana
    ports:
      - "3000:3000"
    volumes:
      - grafana-storage:/var/lib/grafana
    environment:
      - GF_SECURITY_ADMIN_PASSWORD=admin
    restart: always

  node-exporter:
    image: prom/node-exporter
    container_name: node-exporter
    ports:
      - "9100:9100"
    restart: always

volumes:
  grafana-storage:
2.2 创建 Prometheus 配置文件

在 Server 1 上创建一个 prometheus.yml 文件,内容如下:

复制代码
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: 'node-exporter'
    static_configs:
      - targets: ['server2:9100', 'server3:9100', 'server4:9100', 'server5:9100', 'server6:9100']
2.3 启动服务

在 Server 1 上运行以下命令启动:

复制代码
docker-compose up -d

3.在 Server 2-n 上部署 Node-Exporter,并开放端口

复制代码
docker run -d \
  --name node-exporter \
  -p 9100:9100 \
  --restart always \
  prom/node-exporter

4. 配置 Grafana

4.1 访问 Grafana

在浏览器中访问 http://<Server1-IP>:3000,使用默认用户名 admin 和密码 admin 登录。

4.2 添加 Prometheus 数据源
  1. 在 Grafana 中,点击左侧菜单的 Configuration -> Data Sources

  2. 点击 Add data source ,选择 Prometheus

  3. URL 字段中输入 http://localhost:9090,然后点击 Save & Test

4.3 导入 Node-Exporter 仪表盘
  1. 在 Grafana 中,点击左侧菜单的 + -> Import

  2. Grafana.com Dashboard 字段中输入 1860,然后点击 Load

  3. 选择 Prometheus 数据源,然后点击 Import


4. 验证部署

  • Prometheus :访问 http://<Server1-IP>:9090/targets,确保所有 Node-Exporter 目标(包括 Server 1)的状态为 UP

  • Grafana :访问 http://<Server1-IP>:3000,查看仪表盘是否显示所有服务器的监控数据。

相关推荐
爬山算法31 分钟前
Hibernate(30)Hibernate的Named Query是什么?
服务器·前端·hibernate
AC赳赳老秦37 分钟前
Shell 脚本批量生成:DeepSeek 辅助编写服务器运维自动化指令
运维·服务器·前端·vue.js·数据分析·自动化·deepseek
菜鸟思维44 分钟前
优化NextJs 项目的Docker 镜像 从3.62G 优化到 296.85M
docker
学Linux的语莫1 小时前
linux的root目录缓存清理
linux·运维·服务器
oMcLin1 小时前
如何在 SUSE Linux Enterprise Server 15 上部署并优化 K3s 集群,提升轻量级容器化应用的资源利用率?
linux·运维·服务器
怣疯knight1 小时前
Docker Desktop 4.55.0版本安装成功教程
windows·docker
Ghost Face...1 小时前
深入解析YT6801驱动模块架构
linux·运维·服务器
东方佑2 小时前
使用Docker Compose一键部署OnlyOffice:完整指南与配置解析
运维·docker·容器
赵文宇(温玉)2 小时前
Docker的价值、特点、创新与关键技术
运维·docker·容器
m0_726965982 小时前
玩转(坏)服务器【一】
运维·服务器