一、主机部署Prometheus、cadvisor、grafana、node-exporter
1、部署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 --detach=true --name=cadvisor google/cadvisor
2、部署node-EXporter,收集硬件和系统信息
docker run -d -p 9100:9100 -v /proc:/host/proc -v /sys:/host/sys -v /:/rootfs prom/node-exporter --path.procfs /host/proc --path.sysfs /host/sys --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"
3、部署prometheus-server服务
先启动一个prometheus服务,目的是复制他的配置文件,修改配置文件,prometheus挂载这个文件
mkdir /prometheus
docker run -d --name test -P prom/prometheus
docker cp test:/etc/prometheus/prometheus.yml /prometheus
#编辑prometheus配置文件
#以下添加的ip都将会被监控起来
global:scrape_interval: 15sevaluation_interval: 15sscrape_configs:
- job_name: prometheusstatic_configs:- targets: ['10.10.80.167:9090','10.10.80.167:8080']labels:instance: centos7- job_name: localhoststatic_configs:- targets: ['10.10.80.167:9100']labels:instance: centos7- job_name: jumpserverstatic_configs:- targets: ['10.10.200.15:9100','10.10.200.15:8080']labels:instance: jumpserver重新运行prometheus服务收集cAdvisor和nodexporter的信息到prometheus
docker rm -f test
docker run -d --name prometheus --net host -p 9090:9090 -v /prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus4、部署grafana
mkdir /grafana
chmod 777 -R /grafana
docker run -d -p 3000:3000 --name grafana -v /grafana:/var/lib/grafana -e "GF_SECURITY_ADMIN_PASSWORD=123.com" grafana/grafana
访问测试,默认账号密码:admin,admin
添加数据源
填入prometheus地址,保存退出
2、被监控主机上部署node-exporter,cadvisor
#从监控主机上将node-exporter镜像,cadvisor镜像导出,然后在客户端上导入。(也可以直接按上述命令下载)
客户端IP地址:10.10.200.245 10.10.200.246 10.10.200.15
/usr/local/bin/docker load -i cadvisor.tar.gz
/usr/local/bin/docker load -i node.tar.gz
导入镜像后,启动容器
/usr/local/bin/docker run -d -p 9100:9100 -v /proc:/host/proc -v /sys:/host/sys -v /:/rootfs prom/node-exporter --path.procfs /host/proc --path.sysfs /host/sys --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)"/usr/local/bin/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 --detach=true --name=cadvisor
google/cadvisor容器启动正常后,回到prometheus服务端,修改配置文件
[root@localhost ~]# vim /opt/prometheus/prometheus.yml
global:scrape_interval: 15sevaluation_interval: 15sscrape_configs:
- job_name: prometheusstatic_configs:- targets: ['10.10.80.167:9090','10.10.80.167:8080']labels:instance: centos7- job_name: localhoststatic_configs:- targets: ['10.10.80.167:9100']labels:instance: centos7
- job_name: jumpserverstatic_configs:- targets: ['10.10.200.15:9100','10.10.200.15:8080']labels:instance: jumpserver
- job_name: FileZ-245static_configs:- targets: ['10.10.200.245:9100','10.10.200.245:8080']labels:instance: FileZ-245
- job_name: FileZ-246static_configs:- targets: ['10.10.200.246:9100','10.10.200.246:8080']labels:instance: FileZ-246
添加看板展示效果,首先添加展示主机的看板
其次添加展示容器的看板:
可以直接import 11600
效果如下:
上述job都需要在被监控端上部署cadvisor和node-exporter容器。