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

相关推荐
Li&&Tao4 分钟前
docker 常用命令
docker·容器·eureka
码上淘金15 分钟前
【Prometheus 】通过 Pushgateway 上报指标数据
prometheus
BD_Marathon1 小时前
Ubuntu:Mysql服务器
服务器·mysql·ubuntu
Jiude2 小时前
MinIO 社区版被故意阉割,Web管理功能全面移除。我来试试国产RustFS
后端·docker·架构
飞询2 小时前
Docker 安装 Elasticsearch 9
elasticsearch·docker
0wioiw03 小时前
Ubuntu基础(监控重启和查找程序)
linux·服务器·ubuntu
艾希逐月3 小时前
TCP数据的发送和接收
服务器·网络·tcp/ip
胡斌附体4 小时前
linux测试端口是否可被外部访问
linux·运维·服务器·python·测试·端口测试·临时服务器
大锦终4 小时前
【Linux】常用基本指令
linux·运维·服务器·centos
知北游天4 小时前
Linux:多线程---深入互斥&&浅谈同步
linux·运维·服务器