基於docker容器部署Prometheus服務 普羅米修斯 監控



參考 https://blog.csdn.net/lvjianzhaoa/article/details/102917567

克隆3個centos7     192.168.67.130 131 132

關防火牆和selinux
firewall-cmd --state
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i s#'SELINUX=enabled'#'SELINUX=disabled'#g /etc/selinux/config
130 131 132  安裝docker  https://www.cnblogs.com/hanxing/p/7806156.html
130 131 132  安裝node-exporter
docker run -d --name node -p 9100:9100 -v /proc:/host/proc -v /sys:/host/sys -v /:/rootfs --net=host prom/node-exporter --path.procfs /host/proc --path.sysfs /host/sys --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
http://192.168.67.132:9100/ 驗證
130 131 132  安裝cadvisor
docker run -v /:/rootfs:ro -v /var/run:/var/run/:rw -v /sys:/sys:ro -v /var/lib/docker:/var/lib/docker:ro -p 8080:8080 -d --name=cadvisor --net=host google/cadvisor:latest

docker ps 檢查發現cadvisor是exit,百度解決方案
mount -o remount,rw '/sys/fs/cgroup'
ln -s /sys/fs/cgroup/cpu,cpuacct /sys/fs/cgroup/cpuacct,cpu
再次啟動解決
docker start cadvisor
docker ps

驗證 http://192.168.67.132:8080/containers/

130  安裝prometheus
docker run -d -p 9090:9090 --name prometheus --net=host prom/prometheus  (啟動時加 --privileged=true  就可以編輯文件  不然是Readonly 就得映射文件)
docker cp prometheus:/etc/prometheus/prometheus.yml   ~/
vim  ~/prometheus.yml

- targets: ['localhost:9090','localhost:8080','localhost:9100','192.168.67.131:8080','192.168.67.131:9100','192.168.67.132:8080','192.168.67.132:9100']


//用於指定監控本機的9090、8080、9100這三個端口,另外添加另外兩台docker主機的8080、9100這兩個端口。
//8080端口運行的是cAdvisor服務
//9100端口運行的是node-exporter服務
//9090端口運行的就是Prometheus服務


docker rm prometheus -f //將剛才運行的容器刪除

docker run -d -p 9090:9090 --name prometheus --net=host -v /root/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus
//重新運行一個prometheus容器,將剛才修改完成的配置文件掛載到容器中

谷歌瀏覽器驗證 (360和ie不行)
http://192.168.67.130:9090/

 

130  安裝grafana

mkdir grafana-storage
chmod 777 -R grafana-storage/
docker run -d -p 3000:3000 --name grafana -v /root/grafana-storage:/var/lib/grafana -e "GF_SECURITY_ADMIN_PASSWORD=123.com" grafana/grafana

這時提示

Status: Downloaded newer image for docker.io/grafana/grafana:latest
WARNING: IPv4 forwarding is disabled. Networking will not work.

  

[root@my130 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1762e46c607c grafana/grafana "/run.sh" 2 hours ago Created grafana
03da6ce1bdc2 prom/prometheus "/bin/prometheus -..." 4 hours ago Up 4 hours prometheus
cb420d6af9f5 google/cadvisor "/usr/bin/cadvisor..." 5 hours ago Up 4 hours cadvisor
cf32d582a81e prom/node-exporter "/bin/node_exporte..." 8 hours ago Up 8 hours node

 grafana的狀態為 Created,全部重啟一下

systemctl restart docker

docker ps -a -q | xargs docker start

[root@my130 ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1762e46c607c grafana/grafana "/run.sh" 3 hours ago Up 19 seconds 0.0.0.0:3000->3000/tcp grafana
03da6ce1bdc2 prom/prometheus "/bin/prometheus -..." 4 hours ago Up 17 seconds prometheus
cb420d6af9f5 google/cadvisor "/usr/bin/cadvisor..." 5 hours ago Up 7 seconds cadvisor
cf32d582a81e prom/node-exporter "/bin/node_exporte..." 8 hours ago Up 5 seconds

瀏覽器訪問 http://192.168.67.130:3000/                 admin   123.com

 

 

 

 

 

 

 

 訪問 官網 獲取模板  https://grafana.com/     (https://grafana.com/grafana/dashboards/?dataSource=prometheus)    Products   -->  Dashboards   

 

 

 接着導入(推薦 11461 )

 

  

填入id Load  ( node_exporter 的圖形模板1860)

 

 

 

 

 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM