docker安裝prometheus
一、安裝prometheus server
docker pull prom/prometheus
# 拉取prometheus映象
docker run -d --name prometheus2020 prom/prometheus
# 啟動容器
docker cp -a prometheus2020:/etc/prometheus/ $PWD/prometheus
# 複製容器內部的配置檔案到宿主機,不用事先建立$PWD/prometheus目錄
docker rm -f prometheus2020
# 刪除容器
docker run -d --name prometheus2020 -p 9090:9090 -v $PWD/prometheus:/etc/prometheus prom/prometheus
# 啟動容器
firewall-cmd --zone=public --add-port=9090/tcp --permanent
firewall-cmd --reload
# 開放防火牆9090埠
訪問
http://192.168.1.113:9090
二、安裝node-exporter
docker pull prom/node-exporter
# 拉取映象
docker run -d --name node-exporter2020 -p 9100:9100 -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" --net="host" prom/node-exporter
# 啟動容器
firewall-cmd --zone=public --add-port=9100/tcp --permanent
firewall-cmd --reload
# 開放防火牆9100埠
訪問
http://192.168.1.113:9100/metrics
vim prometheus/prometheus.yml
# 修改宿主機prometheus配置檔案,重啟後會同步到容器內部
scrape_configs: # The job name is added as a label `job=<job_name>` to any timeseries scraped from this config. - job_name: 'prometheus' # metrics_path defaults to '/metrics' # scheme defaults to 'http'. static_configs: - targets: ['192.168.1.113:9090'] labels: instance: prometheus - job_name: 'centos_1' static_configs: - targets: ['192.168.1.113:9100'] labels: instance: centos_1
docker restart prometheus2020
重啟容器
此時再訪問
http://192.168.1.113:9090/targets
三、安裝grafana
docker pull grafana/grafana
# 拉取映象
mkdir grafana
# 在宿主機的當前目錄下建立grafana目錄
chmod 777 -R ./grafana/
# 賦予grafana目錄讀寫許可權
docker run -d --name=grafana2020 -p 3000:3000 -v $PWD/grafana:/var/lib/grafana grafana/grafana
# 啟動容器
firewall-cmd --zone=public --add-port=3000/tcp --permanent
firewall-cmd --reload
# 開放防火牆3000埠
訪問
http://192.168.1.113:3000/
使用者名稱:admin
密碼:admin
修改密碼為:123456
並二次確認
首頁:
新增資料來源,選擇Prometheus:
配置Prometheus資料來源:
測試一下並儲存:
配置模板
可在官網搜尋一個模板
https://grafana.com/grafana/dashboards?dataSource=prometheus
選擇8989這個模板
https://grafana.com/grafana/dashboards/8919