安装 Docker
安装 Grafana
安装 Prometheus
安装 Node Exporter
添加 Node

安装 Docker

curl -fsSL https://get.docker.com |bash

安装 Grafana

docker run -d --name=grafana -p 3000:3000 grafana/grafana

  • 默认账号密码均为 admin

安装 prometheus

docker run -d --name prometheus -p 9090:9090 -v /root/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus --storage.tsdb.retention.time=14d

  • 如果报错需要手动创建/root/prometheus/prometheus.yml
1
2
3
4
5
6
7
8
9
10
global:
scrape_interval: 15s
evaluation_interval: 15s

scrape_configs:
- job_name: prometheus
static_configs:
- targets: ['127.0.0.1:9090']
labels:
instance: prometheus

安装 Node Exporter

  • 一键脚本 bash -c "$(curl -sL https://raw.githubusercontent.com/uerax/script/master/node-exporter.sh)" @

下载对应版本

添加 Node

  • 要注意由于 Grafana 和 Prometheus 都是安装在 Docker 里, 无法用 127.0.0.1 进行互相访问, 需要用 ip address 查询 Docker 对应的 IP 段才可以访问
1
2
3
4
5
6
7
8
9
scrape_configs:
- job_name: 'linux'
static_configs:
- targets: ['127.0.0.1:9100']
labels:
server_name: 'server1'
- targets: ['127.0.0.1:9100']
labels:
server_name: 'server2'