docker安裝prometheus (轉)

 

總覽                   
服務 端口 是否有web界面 作用

prometheus

9090 作爲監控主服務器,拉取並存儲時序數據

node-exporter

9100 收集內核公​​開的硬件和操作系統指標

grafana

3000 數據展示可視化

cadvisor

9595 收集宿主機上運行的所有容器的性能數據

 

一、安裝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

prometheus使用的是UTC時間,比當前的北京時間晚8個小時,可勾選Use local time選項使用本地時間

 

二、安裝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配置文件,重啓後會同步到容器內部

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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目錄讀寫權限

# grafana是以grafana用戶啓動,不是以root用戶啓動

 

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

選擇8919這個模板

https://grafana.com/grafana/dashboards/8919

 

 

 

四、安裝cadvisor

docker pull google/cadvisor

# 拉取鏡像

 

docker run -d \
--name=cadvisor2020 \
--volume=/:/rootfs:ro \
--volume=/var/run:/var/run:rw \
--volume=/sys:/sys:ro \
--volume=/var/lib/docker/:/var/lib/docker:ro \
--volume=/cgroup:/cgroup:ro \
--publish=9595:8080 \
--detach=true \
--privileged=true \
google/cadvisor

# 啓動容器

 

firewall-cmd --zone=public --add-port=9595/tcp --permanent

firewall-cmd --reload

# 開放防火牆9595端口

 

訪問

http://192.168.1.113:9595/

 

http://192.168.1.113:9595/metrics

 

 
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章