mkdir -p /home/porschan/le16/17-prometheus
cd /home/porschan/le16/17-prometheus
ocker-compose.yml创建文件
nano /home/porschan/le16/17-prometheus/docker-compose.yml
内容如下
services:
# VictoriaMetrics - 指标存储和查询[citation:3]
victoriametrics:
image: victoriametrics/victoria-metrics:latest
container_name: victoriametrics
ports:
- 8428:8428
volumes:
- /home/porschan/le16/17-prometheus/victoriametrics/data:/storage
command:
- '--storageDataPath=/storage'
- '--httpListenAddr=:8428'
- '--retentionPeriod=30d'
restart: unless-stopped
user: root
mac_address: 4e:e5:5e:04:71:f2
networks:
macvlan18:
ipv4_address: 192.168.18.160
# Prometheus - 指标采集
prometheus:
image: prom/prometheus:latest
container_name: prometheus
ports:
- 9090:9090
volumes:
- /home/porschan/le16/17-prometheus/prometheus/conf/prometheus.yml:/etc/prometheus/prometheus.yml
- /home/porschan/le16/17-prometheus/prometheus/data:/prometheus
command:
- '--config.file=/etc/prometheus/prometheus.yml'
- '--storage.tsdb.path=/prometheus'
- '--storage.tsdb.retention.time=30d'
- '--web.enable-lifecycle'
restart: unless-stopped
user: root
depends_on:
- victoriametrics
mac_address: 4e:e5:5e:04:71:f1
networks:
macvlan18:
ipv4_address: 192.168.18.161
# Grafana - 数据可视化
grafana:
image: grafana/grafana:latest
container_name: grafana
ports:
- 3000:3000
environment:
- GF_SECURITY_ADMIN_PASSWORD=admin
- GF_INSTALL_PLUGINS=grafana-clock-panel
volumes:
- /home/porschan/le16/17-prometheus/grafana/data:/var/lib/grafana
- /home/porschan/le16/17-prometheus/grafana/provisioning:/etc/grafana/provisioning
restart: unless-stopped
# if you are running as root then set it to 0
# else find the right id with the id -u command
user: root
mac_address: 4e:e5:5e:04:71:f3
depends_on:
- prometheus
networks:
macvlan18:
ipv4_address: 192.168.18.162
networks:
macvlan18:
external: true
name: macvlan18
prometheus/conf/prometheus.yml创建目录
mkdir -p /home/porschan/le16/17-prometheus/prometheus/conf
创建文件
nano /home/porschan/le16/17-prometheus/prometheus/conf/prometheus.yml
内容如下
global:
scrape_interval: 15s
evaluation_interval: 15s
# 远程写入到 VictoriaMetrics
remote_write:
- url: http://192.168.18.160:8428/api/v1/write
# 远程从 VictoriaMetrics 读取
remote_read:
- url: http://192.168.18.160:8428/api/v1/read
scrape_configs:
# 监控 Prometheus 自身
- job_name: 'prometheus'
static_configs:
- targets: ['192.168.18.161:9090']
metrics_path: /metrics
# 监控 VictoriaMetrics
- job_name: 'victoriametrics'
static_configs:
- targets: ['192.168.18.160:8428']
metrics_path: /metrics
sudo docker compose up -d
如果没有创建 macvlan,请执行该命令:docker network create -d macvlan --subnet=192.168.18.0/24 --ip-range=192.168.18.0/24 --gateway=192.168.18.254 -o parent=ens18 macvlan18