服务器多节点 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,查看仪表盘是否显示所有服务器的监控数据。

相关推荐
HAPPY酷11 分钟前
linux安装mysql常出现的问题
linux·运维·服务器·python·mysql·adb
Stringzhua7 小时前
Linux多网卡组Bond0Bond1Bond4
运维·服务器·网络
HHONGQI1237 小时前
Linux 基础入门操作 前言 VIM的基本操作 2
linux·运维·服务器·vim
王伯爵8 小时前
接入网和核心网之间的承载网详细介绍
服务器·网络·数据库
丘陵哈哈8 小时前
Docker学习笔记
笔记·学习·docker
小峰编程9 小时前
谈Linux之磁盘管理——万字详解
linux·运维·服务器·经验分享·笔记·centos·运维开发
乐渔leyu9 小时前
Debian 12 服务器搭建Beego环境
服务器·debian·beego
archko9 小时前
telophoto源码查看记录
java·服务器·前端
s区元素10 小时前
grafana+node_exporter应用
grafana
麻芝汤圆10 小时前
Linux操作系统的计算机体系结构与网络安全的深度关联
大数据·linux·运维·服务器·网络·安全·web安全