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

相关推荐
网络小白不怕黑2 小时前
Docker容器网络:四大模式解析与自定义网络
运维·docker·容器
程序员zgh6 小时前
Linux系统常用命令集合
linux·运维·服务器·c语言·开发语言·c++
gwd2006 小时前
如何快速设置 Docker 代理设置
运维·人工智能·docker·容器
紫郢剑侠7 小时前
飞秋@Windows +iptux@Linux,打造内网跨平台IM环境
linux·运维·服务器·im·qq
保持低旋律节奏7 小时前
linux——调试
linux·运维·服务器
牛奶咖啡137 小时前
Linux系统故障排查思路实践教程(下)
linux·运维·服务器·su命令切换用户问题解决·文件打开过多问题解决·linux网络故障问题解决·linux故障排查思路
一苓二肆7 小时前
代码常用工具使用
git·vscode·docker·github·vim
weixin_521431128 小时前
Docker容器技术
运维·docker·容器
xdxghy09218 小时前
mini centos7+k3s部署(镜像拉取解决版)
linux·运维·服务器·阿里云·运维开发