Docker容器与虚拟化技术:OpenEuler 部署 Prometheus 与 Grafana

目录

一、实验

1.环境

[2.OpenEuler 部署 Prometheus](#2.OpenEuler 部署 Prometheus)

[3.OpenEuler 部署 Grafana](#3.OpenEuler 部署 Grafana)

4.使用cpolar内网穿透

二、问题

1.拉取镜像失败

2.如何导入Grafana监控模板(ES)


一、实验

1.环境

(1)主机

表1 主机

|-------|--------------|---------------|-------------------------------------------------------------|-----------|
| 系统 | 架构 | 版本 | IP | 备注 |
| Linux | openEuler | 22.03 LTS SP2 | 192.168.204.145(动态) 192.168.204.141(静态) 192.168.204.142(静态) | |
| | docker | 25.0.3 | | |
| | cpolar (客户端) | 3.12 | | 服务器端 3.22 |

(2)查看系统版本

bash 复制代码
[root@localhost ~]# cat /etc/os-release

(3) 查看网络ip

bash 复制代码
[root@localhost ~]# ip addr

(4) 查看docker版本

bash 复制代码
[root@localhost ~]# docker --version

2.OpenEuler 部署 Prometheus

(1) 拉取Prometheus镜像

bash 复制代码
[root@localhost ~]# docker pull prom/prometheus

(2)拉取数据收集镜像

用于机器系统数据收集

bash 复制代码
[root@localhost ~]# docker pull prom/node-exporter

用于收集宿主机上的docker容器数据

bash 复制代码
[root@localhost ~]# docker pull google/cadvisor

(3)创建node-exporter容器

bash 复制代码
[root@localhost ~]# docker run -d --name node-exporter --restart=always -p 9100:9100 -v "/proc:/host/proc:ro" -v "/sys:/host/sys:ro" -v "/:/rootfs:ro" prom/node-exporter

(4)监听端口

bash 复制代码
[root@localhost ~]# netstat -antlp | grep 9100

(5)访问

bash 复制代码
http://192.168.204.141:9100/metrics

(6)创建cadvisor容器

bash 复制代码
[root@localhost ~]# docker run -v /:/rootfs:ro -v /var/run:/var/run:rw -v /sys:/sys:ro -v /var/lib/docker/:/var/lib/docker:ro -v /dev/disk/:/dev/disk:ro -p 8080:8080 -d --name=cadvisor --restart=always google/cadvisor:latest

(7) 监听端口

bash 复制代码
[root@localhost ~]# netstat -antlp | grep 8080

(8)访问

bash 复制代码
http://192.168.204.141:8080/metrics

(9)创建配置文件

bash 复制代码
[root@localhost ~]# mkdir /opt/prometheus
[root@localhost ~]# cd /opt/prometheus/
[root@localhost prometheus]# vim prometheus.yml

第一种方式:(容器地址)

bash 复制代码
global:
  scrape_interval:     60s
  evaluation_interval: 60s

scrape_configs:

  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus

  - job_name: linux
    static_configs:
      - targets: ['172.17.0.7:9100']
        labels:
          instance: localhost
 
  - job_name: cadvisor
    static_configs:
      - targets: ['172.17.0.8:8080']
        labels:
          instance: cAdvisor

第二种方式:(宿主机地址)

bash 复制代码
global:
  scrape_interval:     60s
  evaluation_interval: 60s

scrape_configs:

  - job_name: prometheus
    static_configs:
      - targets: ['localhost:9090']
        labels:
          instance: prometheus

  - job_name: linux
    static_configs:
      - targets: ['192.168.204.141:9100']
        labels:
          instance: localhost
 
  - job_name: cadvisor
    static_configs:
      - targets: ['192.168.204.141:8080']
        labels:
          instance: cAdvisor

(10) 创建Prometheus容器

bash 复制代码
[root@localhost prometheus]# docker run  -d --name prometheus --restart=always -p 9090:9090 -v /opt/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml prom/prometheus

(11)监听端口

bash 复制代码
[root@localhost prometheus]# netstat -antlp | grep 9090

(12)访问

bash 复制代码
http://192.168.204.141:9090/graph

访问targets(第一种方式的宿主机地址)

bash 复制代码
http://192.168.204.141:9090/targets

访问targets(第二种方式的容器地址)

bash 复制代码
http://192.168.204.141:9090/targets

3.OpenEuler 部署 Grafana

(1)拉取Grafana镜像

bash 复制代码
[root@localhost ~]# docker pull grafana/grafana

(2)创建目录

授权

bash 复制代码
[root@localhost ~]# mkdir /opt/grafana-storage
[root@localhost ~]# chmod 777 -R /opt/grafana-storage

(3)创建Grafana容器

bash 复制代码
[root@localhost ~]# docker run -d --name grafana --restart=always -p 3000:3000 --name=grafana -v /opt/grafana-storage:/var/lib/grafana grafana/grafana

(4)监听端口

bash 复制代码
[root@localhost ~]# netstat -antlp | grep 3000

(5)访问

bash 复制代码
http://192.168.204.141:3000

(6)登录

默认的用户名和密码都是admin

设置新密码

跳转首页

(7)添加数据源

弹出页面

选择Prometheus

输入URL

保存并测试

(8)查看Grafana监控模板的官网

bash 复制代码
https://grafana.com/grafana/dashboards/

(9)导入Grafana监控模板(主机)

选择

弹出页面

导入

导入主机的监控模板,模板id为8919

修改

完成

4.使用cpolar内网穿透

(1)固定二级子域名地址

登录cpolar官网,点击左侧的预留,找到保留二级子域名,为远程服务器连接保留一个固定二级子域名地址

bash 复制代码
https://dashboard.cpolar.com/get-started

(2)创建隧道

bash 复制代码
域名类型:选择二级子域名
 
预留的http地址:复制粘贴官网保留成功的地址,Prometheus
 
地区选择:China VIP

(3) 查看隧道列表

(4)查看在线隧道列表

(5)二级子域名地址访问

bash 复制代码
http://prometheus.vip.cpolar.cn/graph
bash 复制代码
http://prometheus.vip.cpolar.cn/targets

(6) Grafana添加数据源

bash 复制代码
http://prometheus.vip.cpolar.cn

保存并测试

导入

(7)导入主机的监控模板

模板id为8919

完成

二、问题

1.拉取镜像失败

(1)报错

bash 复制代码
Get "https://registry-1.docker.io/v2/": tls: failed to verify certificate: x509: certificate has expired or is not yet valid: current time 2024-04-01T14:17:15+08:00 is before 2024-04-04T00:00:00Z

(2)原因分析

时间未同步。

(3)解决方法

同步时间:

bash 复制代码
[root@localhost ~]# ntpdate cn.pool.ntp.org

成功:

2.如何导入Grafana监控模板(ES)

添加数据源

保存并测试

导入

导入ES的监控模板,模板id为878

修改

相关推荐
卷无止境8 小时前
Windows 上丝滑开发 Python,并稳定构建 Docker 镜像
后端·python·docker
吕海洋12 小时前
目前可用的docker源2026.08
运维·docker·容器
gsls20080815 小时前
Penpot Docker 部署与 MCP 服务配置文档
运维·docker·容器·原型·penpot
xrlfreedom16 小时前
大厂 MCP 面试实录:本地 Server 远程化改造中的技术选型与落地实践
docker·json schema·mcp
艾伦_耶格宇20 小时前
【DOCKER容器实战】-2MySQL
运维·docker·容器
禅口魔心21 小时前
RK3576开发——Docker部署
docker·嵌入式linux
随便做点啥1 天前
32卡×4090 24GB,Qwen3.8-27B-FP8 集群部署报告
服务器·经验分享·docker·vllm
玉&心1 天前
在grafana中加入elasticsearch的日志dashboard
elasticsearch·grafana
To_OC1 天前
跑了3个Docker容器后,我终于搞懂镜像和容器到底啥关系
后端·docker·容器
tryCbest1 天前
Docker 从零到精通:知识与跨平台使用指南
docker·容器