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

相关推荐
树℡独6 小时前
ns-3仿真之应用层(五)
服务器·网络·tcp/ip·ns3
a41324477 小时前
ubuntu 25 安装vllm
linux·服务器·ubuntu·vllm
Configure-Handler7 小时前
buildroot System configuration
java·服务器·数据库
津津有味道8 小时前
易语言TCP服务端接收刷卡数据并向客户端读卡器发送指令
服务器·网络协议·tcp·易语言
Fᴏʀ ʏ꯭ᴏ꯭ᴜ꯭.8 小时前
Keepalived VIP迁移邮件告警配置指南
运维·服务器·笔记
Genie cloud9 小时前
1Panel SSL证书申请完整教程
服务器·网络协议·云计算·ssl
!chen9 小时前
linux服务器静默安装Oracle26ai
linux·运维·服务器
莫大3309 小时前
2核2G云服务器PHP8.5+MySQL9.0+Nginx(LNMP)安装WordPress网站详细教程
运维·服务器·nginx
2501_9277730710 小时前
imx6驱动
linux·运维·服务器
hy____12310 小时前
Linux_进程间通信
linux·运维·服务器