一、安装docker、docker-compose
二、安装prometheus
1、安装目录准备
cd /home/xxxx
mkdir -p prometheus
chmod 777 prometheus
cd prometheus
mkdir -p grafana_data prometheus_data
chmod 777 grafana_data prometheus_data
2、编写docker-compose文件
vim docker-compose.yml
version: "3.7"
services:
node-exporter:
image: prom/node-exporter:latest
container_name: "node-exporter0"
ports:
- "9100:9100"
restart: always
prometheus:
image: prom/prometheus:latest
container_name: "prometheus0"
restart: always
ports:
- "9090:9090"
volumes:
- "./prometheus.yml:/etc/prometheus/prometheus.yml"
- "./prometheus_data:/prometheus"
grafana:
image: grafana/grafana
container_name: "grafana0"
ports:
- "3000:3000"
restart: always
volumes:
- "./grafana_data:/var/lib/grafana"
- "./grafana_log:/var/log/grafana"
- "./grafana_data/crypto_data:/crypto_data" # 宿主机的地址是冒号前面的,冒号后面的是容器地址,不可变,这个用来放sqlite数据库的位置。
3、编写prometheus.yml文件
vim prometheus.yml
global:
scrape_interval: 15s # 默认抓取周期
external_labels:
monitor: 'codelab-monitor'
scrape_configs:
- job_name: 'node-exporter' #服务的名称
scrape_interval: 5s
metrics_path: /metrics #获取指标的url
static_configs:
- targets: ['11.11.12.156:9100'] # 这个为监听指定服务服务的ip和port,需要修改为自己的ip,不能使用localhost和127.0.0.1
4、启动
docker-compose up -d
5、访问
localhost:9090 #普罗米修斯的监控页面
localhost:3000 #grafana界面,admin/admin
网友评论