Docker Compose 部署监控系统 Prometheus + Grafana + Node Exporter + Cadvisor
前言
Prometheus + Grafana + Node Exporter + Cadvisor
是一款开源的服务器系统状态监控平台系统,用于管理和存储各服务器的实时信息数据,方便监控和排查服务器故障.博主经过一段时间的安装,配置,测试也基本满足了个人以及中小企业团队对于日志管理的需求.整合了相对详细的部署和配置教程分享给大家.
本教程使用docker-compose
整合部署,参考 stefanprodan/dockprom.
项目流程
服务端:部署Prometheus + Grafana
到主监控服务器
客户端:部署Node Exporter + Cadvisor
到需要被监控的服务器
常规流程
客户端通过Node Exporter
采集系统状态信息,Cadvisor
采集docker
容器信息,并开放端口,由服务端Prometheus
进行抓取,并由Grafana
提供前端展示.
服务器部署 Prometheus + Grafana
拉取代码
git clone -b master https://github.com/stefanprodan/dockprom prom
创建 cadday 密码
docker run --rm caddy caddy hash-password --plaintext 'youtpasswd' # 获取 hash 密码 JDJhJDE0JHJmeldKeDB0NjJnY0tjQk5wZXVYaC50QjdSbi9aVlVZeFYyV012UkI2Y
docker-compose.yml
volumes:
创建数据目录
cd prom mkdir prometheus_data grafana_data # 创建数据目录
修改docker-compose.yml
中顶级卷配置到指定目录用于存储数据
volumes: prometheus_data: driver: local driver_opts: type: 'none' o: 'bind' device: '/root/prom/prometheus_data' grafana_data: driver: local driver_opts: type: 'none' o: 'bind' device: '/root/prom/grafana_data'
配置 grafana 密码
yourpasswd
修改为你的grafana
登陆密码
environment: - GF_SECURITY_ADMIN_USER=${ADMIN_USER:-admin} - GF_SECURITY_ADMIN_PASSWORD=${ADMIN_PASSWORD:-yourpasswd} - GF_USERS_ALLOW_SIGN_UP=false
配置 caddy 密码
修改上文生成的caddy hash
密码
environment: - ADMIN_USER=${ADMIN_USER:-admin} - ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin} - ADMIN_PASSWORD_HASH=${ADMIN_PASSWORD_HASH:-JDJhJDE0JHJmeldKeDB0NjJnY0tjQk5wZXVYaC50QjdSbi9aVlVZeFYyV012UkI2Y
配置 prometheus.yml
创建独立配置目录
在./prometheus
创建jobs
目录,创建独立配置文件:
nodeexporter.yml
cadvisor.yml
prometheus.yml
pushgateway.yml
独立配置文件
参考示例./prometheus/jobs/nodeexporter.yml
- targets: - "127.127.127.127:9100" labels: hostname: Server - targets: - "127.127.127.128:9100" labels: hostname: Server1 - targets: - "127.127.127.129:9100" labels: hostname: Server2
参考示例./prometheus/jobs/cadvisor.yml
- targets: - "127.127.127.127:8080" labels: hostname: Server - targets: - "127.127.127.128:8080" labels: hostname: Server1 - targets: - "127.127.127.129:8080" labels: hostname: Server2
配置 prometheus.yml
参考修改独立配置文件路径./prometheus/prometheus.yml
scrape_configs: - job_name: 'nodeexporter' file_sd_configs: - files: - "/etc/prometheus/jobs/nodeexporter.yml" refresh_interval: 5s - job_name: 'cadvisor' file_sd_configs: - files: - "/etc/prometheus/jobs/cadvisor.yml" refresh_interval: 5s - job_name: 'prometheus' file_sd_configs: - files: - "/etc/prometheus/jobs/prometheus.yml" refresh_interval: 5s - job_name: 'pushgateway' file_sd_configs: - files: - "/etc/prometheus/jobs/pushgateway.yml" refresh_interval: 5s
客户端配置
docker-compose.yml
version: '3.2' services: nodeexporter: image: prom/node-exporter:v1.1.2 container_name: nodeexporter volumes: - /proc:/host/proc:ro - /sys:/host/sys:ro - /:/rootfs:ro # ports: # - 9100:9100 environment: TZ: Asia/Shanghai command: - '--path.procfs=/host/proc' - '--path.rootfs=/rootfs' - '--path.sysfs=/host/sys' - '--collector.filesystem.ignored-mount-points=^/(sys|proc|dev|host|etc)($$|/)' labels: org.label-schema.group: "monitoring" restart: always network_mode: host cadvisor: image: gcr.io/cadvisor/cadvisor:v0.39.0 container_name: cadvisor volumes: - /:/rootfs:ro - /var/run:/var/run:rw - /sys:/sys:ro - /var/lib/docker:/var/lib/docker:ro #- /cgroup:/cgroup:ro #doesn't work on MacOS only for Linux ports: - 8080:8080 environment: TZ: Asia/Shanghai labels: org.label-schema.group: "monitoring" restart: always
结语
Prometheus
的安装部署教程已经分享给大家,欢迎大家留言交流.
本站提供免费和付费的技术支持.你可以通过留言,邮件,QQ的方式来进行技术交流和免费咨询.同时也可以付费支持的方式获得相关的技术支持,项目部署配置等服务.具体相关详情请点击查看 技术支持页面