服务器监控平台(Docker:grafana+prometheus+node_exporter)

如何通过Docker部署监控平台,包括安装NodeExporter、Prometheus和Grafana

AI导读:本文介绍了如何在Ubuntu 20.04上通过Docker部署监控平台,包括安装Node Exporter、Prometheus和Grafana。首先,用户需拉取相应的镜像并运行容器,随后创建Prometheus配置文件和数据存储文件夹。接着,指导用户使用Docker Compose进行统一管理,并提供了安装Docker Compose的步骤,包括检查版本、下载和赋予执行权限。文中还引用了一些相关的参考文章以供进一步阅读。

安装node_exporter

拉取node_exporter镜像

1
docker pull prom/node-exporter

运行node_exporter容器

1
2
3
4
docker run --rm \
--name=node-exporter \
-p 3100:9100 \
-d prom/node-exporter

安装prometheus

拉取prometheus镜像

1
docker pull prom/prometheus

在home目录下创建一个prometheus文件夹,文件夹下创建prometheus.yml,新增如下内容并保存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# my global config
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093

rule_files:
# - "first_rules.yml"
# - "second_rules.yml"

scrape_configs:
- job_name: "prometheus"
static_configs:
- targets: ["localhost:9090"]
- job_name: nodes
static_configs:
- targets: ['192.168.3.14:3100']

创建一个文件夹,例如/path/to/prometheus/data用于保存数据,指定容器启动

1
2
3
4
5
6
docker run -d --rm \
--name=prometheus \
-p 3090:9090 \
-v /path/to/prometheus.yml:/etc/prometheus/prometheus.yml \
-v /path/to/prometheus/data:/prometheus \
prom/prometheus
1
2
3
4
5
6
docker run -d --rm \
--name=prometheus \
-p 9080:9090 \
-v /root/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
-v /home/home/prometheus/data:/prometheus \
prom/prometheus

安装grafana

拉取grafana镜像

1
docker pull grafana/grafana-enterprise

启动grafana

1
2
3
4
docker run --rm -d \
-p 3000:3000 \
--name=grafana \
grafana/grafana-enterprise

docker-compose部署

创建docker-compose文件

1
2
# cd prometheus
vim docker-compose.yml

参考以下内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
version: "3.9"
services:
prometheus:
image: prom/prometheus:latest
container_name: Prometheus
mem_limit: 1g
restart: always
ports:
- 3090:9090
volumes:
# - /path/to/prometheus.yml:/etc/prometheus/prometheus.yml
- /root/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro

grafana:
image: grafana/grafana:latest
container_name: Grafana
mem_limit: 300m
restart: always
ports:
- 3000:3000
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro

node-exporter:
image: prom/node-exporter
container_name: Node-exporter
restart: always
ports:
- 3100:9100
volumes:
- /proc:/host/proc:ro
- /sys:/host/sys:ro
- /:/rootfs:ro
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro

启动

1
docker-compose -f docker_compose.yml up -d

安装dockers compose

通过 Docker 官方提供的安装脚本(适用于 Linux 和 macOS)

  1. 检查当前版本

    1
    docker-compose --version
  2. 下载最新版本的 Docker Compose

    1
    sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
  3. 为 Docker Compose 二进制文件添加执行权限

    1
    sudo chmod +x /usr/local/bin/docker-compose
  4. 验证安装是否成功

    1
    docker-compose --version

参考文章:
Ubuntu20.04下部署linux资源监控平台(docker部署)grafana+prometheus+node_exporter(docker+离线包)_prometheus ubuntu 20.04-CSDN博客

Ubuntu20.04容器化部署Prometheus监控服务-CSDN博客

Getting started | Prometheus

作者

Janki

发布于

2024-05-22

更新于

2024-09-04

许可协议

评论