参考 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)