天气:雨转阴
Docker环境准备官方安装文档
# 卸载旧 软件
yum remove docker
docker-client
docker-client-latest
docker-common
docker-latest
docker-latest-logrotate
docker-logrotate
docker-engine
# 设置 docker 安装库
yum install -y yum-utils
yum-config-manager
--add-repo
https://download.docker.com/linux/centos/docker-ce.repo
# 安装 docker-engine,直接装最新版本
yum install docker-ce docker-ce-cli containerd.io docker-compose-plugin
# 启动 docker
systemctl start/stop/restart docker
Prometheus 日志方案
prometheus 提供了监控 服务器资源 中 数据搜集、存储、处理、可视化、告警 一套完整的解决方案
使用 Prometheus 监控两台 Docker Host A 、B、C
Node Exporter 容器部署
- Prometheus Server 容器化部署在 Docker Host A ;
- Exporter 有多种,详见 官方文档; 使用 NodeExporter 负责收集host硬件和操作系统数据,运行在所有的 DockerHost 上;cAdvisor 负责收集容器的数据,同样运行在所有 Docker Host 上。
- Grafana 显示多维数据,容器化部署在 Docker Host A 上
github文档;参考博客。node_exporter 用于监控主机系统。不建议将其部署为Docker容器,因为它需要访问主机系统。请注意,您要监视的任何非根安装点都需要绑定到容器中。如果启动容器进行主机监视,请指定path.rootfs参数。此参数必须与host root的bind-mount中的路径匹配。node_exporter将path.rootfs用作访问主机文件系统的前缀。
docker run -d --restart on-failure:3 --name prometheus-node-exporter --net="host" -v /proc:/host/proc -v /sys:/host/sys -v /:/rootfs prom/node-exporter --path.rootfs /host --collector.filesystem.ignored-mount-points "^/(sys|proc|dev|host|etc)($|/)" # --net=host,则 container 直接使用 host 的端口,不需映射 # 访问地址:ip:9100/metrics
P.S. 开放防火墙端口
# 开放 9100 等端口 firewall-cmd --permanent --zone=public --add-port=9100/tcp firewall-cmd --permanent --zone=public --add-port=8080/tcp firewall-cmd --permanent --zone=public --add-port=9090/tcp firewall-cmd --permanent --zone=public --add-port=3000/tcp # 重新加载防火墙 firewall-cmd --reload # 查看防火墙已经开放的端口 firewall-cmd --list-allcAdvisor 容器部署
docker run --net="host" --restart on-failure:3 -v /:/rootfs:ro -v /var/run:/var/run:rw -v /sys:/sys:ro -v /var/lib/docker:/var/lib/docker:ro -d --name=prometheus-cadvisor google/cadvisor # 配置 host 网络后 cAdvisor 可以直接与 node-exporter 通信, # 访问地址:ip:8080/metricsPrometheus Server 容器部署
创建 挂载文件: vim /root/prometheus/prometheus.yml
# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
# - alertmanager:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
# - "first_rules.yml"
# - "second_rules.yml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['ipA:9100','ipA:8080','ipA:9090','……']
docker run --net host -v /root/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml -d --name prometheus-server prom/prometheus # 只部署一台 Docker Host 即可 # 访问地址:ip:9090/metrics, ip:9090Grafana 容器部署
docker run -i --net host -e GF_SERVER_ROOT_URL=http://grafana.server.name -e GF_SECURITY_ADMIN_PASSWORD=my_grafana@pass -d --name prometheus-grafana grafana/grafana # 只部署一台 Docker Host 即可 # 访问地址: ip:3000 admin my_grafana@pass
- 配置 grafana 的 datasource,即页面展示数据来源;
- 配置 grafana 的 dashboard,即 以什么形式(仪表/线性图等)展示 prometheus 的哪些多维数据。可以从 官网 搜索和下载,再 import 到 dashboard.



