备注:以下操作均在root权限下进行的操作
安装前置环境:
已安装docker
已安装docker-compose
在/opt目录新建目录prom
在对应的prom目录下分别创建prometheus、alertmanager,grafana相关目录
mkdir -p /opt/prom/{prometheus,prometheus/data,alertmanager,grafana}
#prom目录结构
prom/
├── alertmanager
├── grafana
└── prometheus
└── data
赋予相关目录对应的权限
chmod 777 /opt/prom/{prometheus/data,grafana}
编写docker-compose.yml文件,放在目录/opt/prom下
touch /opt/prom/docker-compose.yml
vim /opt/prom/docker-compose.yml
docker-compose.yml文件内容
version: '3.3'
services:
node-exporter:
image: prom/node-exporter:latest
ports:
- "9101:9100" #node-exporter默认端口9100,不过由于metersphere的node-exporter已经占用了9100了,这里调整为9101
networks:
- prom
dingtalk:
image: timonwong/prometheus-webhook-dingtalk:latest
volumes:
- type: bind
source: ./alertmanager/config.yml
target: /etc/prometheus-webhook-dingtalk/config.yml
read_only: true
ports:
- "8060:8060"
networks:
- prom
alertmanager:
depends_on:
- dingtalk
image: prom/alertmanager:latest
volumes:
- type: bind
source: ./alertmanager/alertmanager.yml
target: /etc/alertmanager/alertmanager.yml
read_only: true
ports:
- "9093:9093"
- "9094:9094"
networks:
- prom
prometheus:
depends_on:
- alertmanager
image: prom/prometheus:latest
volumes:
- type: bind
source: ./prometheus/prometheus.yml
target: /etc/prometheus/prometheus.yml
read_only: true
- type: bind
source: ./prometheus/alert-rules.yml
target: /etc/prometheus/alert-rules.yml
read_only: true
- type: volume
source: prometheus
target: /prometheus
ports:
- "9200:9090" #prometheus默认端口9090,不过ms-prometheus占用该端口,这里换成9200
networks:
- prom
grafana:
depends_on:
- prometheus
image: grafana/grafana:latest
volumes:
- type: volume
source: grafana
target: /var/lib/grafana
ports:
- "3000:3000"
networks:
- prom
volumes:
prometheus:
driver: local
driver_opts:
type: none
o: bind
device: /opt/prom/prometheus/data
grafana:
driver: local
driver_opts:
type: none
o: bind
device: /opt/prom/grafana
networks:
prom:
driver: bridge
编写prometheus的配置文件prometheus.yml,放在/opt/prom/prometheus目录下
touch /opt/prom/prometheus/prometheus.yml
vim /opt/prom/prometheus/prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
alerting:
alertmanagers:
- static_configs:
- targets:
- alertmanager:9093
rule_files:
- "*rules.yml&