小飞知识库 | YeLu🤠MiLu🤪 小飞知识库 | YeLu🤠MiLu🤪
  • 函数式编程
  • Spring
  • SpringMVC
  • SpringBoot
  • SpringCloud
  • Mybatis
  • JVM
  • JUC并发编程
  • 设计模式
  • 单元测试
  • Redis
  • RabbitMQ
  • mysql
  • oracle
  • linux
  • nginx
  • docker
  • elasticSearch
  • windows
  • 虚拟机
  • 监控系统
  • https
  • 内网穿透
  • 前端文章

    • JavaScript
  • 页面

    • HTML
    • CSS
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • TypeScript
    • JS设计模式总结
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 版本管理

    • Git笔记
  • 项目构建

    • maven
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • JAR包相关
  • 关于
  • 收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

YeLu

爱技术的YeLu🤠
  • 函数式编程
  • Spring
  • SpringMVC
  • SpringBoot
  • SpringCloud
  • Mybatis
  • JVM
  • JUC并发编程
  • 设计模式
  • 单元测试
  • Redis
  • RabbitMQ
  • mysql
  • oracle
  • linux
  • nginx
  • docker
  • elasticSearch
  • windows
  • 虚拟机
  • 监控系统
  • https
  • 内网穿透
  • 前端文章

    • JavaScript
  • 页面

    • HTML
    • CSS
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • TypeScript
    • JS设计模式总结
  • 技术文档
  • GitHub技巧
  • Nodejs
  • 博客搭建
  • 版本管理

    • Git笔记
  • 项目构建

    • maven
  • 学习
  • 面试
  • 心情杂货
  • 实用技巧
  • 友情链接
  • JAR包相关
  • 关于
  • 收藏
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • linux笔记

  • nginx笔记

  • docker笔记

  • windows笔记

  • ElasticSearch

  • 虚拟机

  • 监控系统

    • prometheus

      • Docker安装prometheus
        • 创建挂载目录
        • 准备prometheus.yml
        • 准备webconfig.yml
        • 准备docker脚本
        • 访问测试
      • Prometheus采集Springboot应用
    • grafana

  • 运维
  • 监控系统
  • prometheus
YeLu🤠
2025-02-19
目录

Docker安装prometheus

# 创建挂载目录

# /opt/prometheus/prometheus_data目录,准备用来挂载放置prometheus的数据
# /opt/prometheus/config目录,准备用来放置prometheus的配置文件
# /opt/prometheus/rules目录,准备用来挂载放置prometheus的规则文件
mkdir -p /opt/prometheus/{data,config,rules}
# 授权相关文件夹权限
chmod -R 777 /opt/prometheus/prometheus_data
chmod -R 777 /opt/prometheus/config
chmod -R 777 /opt/prometheus/rules
1
2
3
4
5
6
7
8

# 准备prometheus.yml

准备全局配置文件如下

查看详情
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"
  # 这里匹配指定目录下所有的.rules文件
  - /prometheus/rules/*.rules

# 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=<job_name>` to any timeseries scraped from this config.
  - job_name: "prometheus"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.

    static_configs:
      - targets: ["localhost:9090"] 
### 下面进行 SpringBoot 应用配置
  - job_name: "applicationName"

    # metrics_path defaults to '/metrics'
    # scheme defaults to 'http'.
    scrape_interval: 5s # 5秒调用一次端口获取数据
    metrics_path: '/actuator/prometheus' # actuator 暴露的端口地址
    static_configs:
      - targets: ["ip:port"]
    basic_auth: # 接口用户权限认证
      username: 'admin'  # 用户名
      password: 'xxxx'  # 明文密码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

再 目录 /opt/prometheus/config 下创建 prometheus.yml 文件 并且复制以上内容

prometheus配置项说明

  • global:全局配置 (如果有内部单独设定,会覆盖这个参数)
  • alerting:告警插件定义。这里会设定alertmanager这个报警插件
  • rule_files:告警规则。 按照设定参数进行扫描加载,用于自定义报警规则,其报警媒介和route路由由alertmanager插件实现
  • scrape_configs:采集配置。配置数据源,包含分组job_name以及具体target。又分为静态配置和服务发现
  • remote_write:用于远程存储写配置
  • remote_read:用于远程读配置

# 准备webconfig.yml

  • Prometheus 使用 Basic Auth 进行安全防护,需要这个配置
  • 在日常prometheus的使用中是没有安全加密措施的,可能会导致监控信息,敏感信息遭遇泄漏。在这种情况下需要保护对Prometheus的访问
  • Prometheus于2.24版本(包括2.24)之后提供Basic Auth功能进行加密访问,在浏览器登录UI的时候需要输入用户密码,访问Prometheus api的时候也需要加上用户密码。
  • 由于Prometheus访问需要认证,如果有grafana,需要修改grafana相关步骤

官方文档:HTTPS and authentication | Prometheus (opens new window)

内容如下:

查看详情
basic_auth_users:
  admin: $2a$10$D0ySOfXfNmSuXMlqjnjzXOAiexvhex9a2iPOwn9m7Xx3qSwsuevKK # 加密后的密码 用户 admin
1
2

再 目录 /opt/prometheus/config 下创建 webconfig.yml 文件 并且复制以上内容

密码在线生成地址 (opens new window)

# 准备docker脚本

# 启动 prometheus
# config.file:指定容器中,配置文件的位置
# web.enable-lifecycle:启动此项后,当配置文件发生变化后,可通过HTTP API 发送 post 请求到 /-/reload,实现热加载,如:curl -X POST http://47.105.39.189:9090/-/reload
# -v /etc/localtime:/etc/localtime:ro表示让容器使用宿主机的时间, :ro表示只读(注:此方式只针对宿主机和容器的时区文件均为/etc/localtime)
docker run -d \
  -p 9090:9090 \
  --name prometheus3.0.0 \
  --restart=always \
  -v /etc/localtime:/etc/localtime:ro \
  -v /opt/prometheus/prometheus_data:/prometheus \
  -v /opt/prometheus/rules:/prometheus/rules \
  -v /opt/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml \
  -v /opt/prometheus/config/webconfig.yml:/etc/prometheus/webconfig.yml \
  prom/prometheus:v3.0.0 \
  --web.config.file=/etc/prometheus/webconfig.yml \
  --config.file=/etc/prometheus/prometheus.yml \
  --web.enable-lifecycle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

# 访问测试

http://ip:9090/ 输入设置的用户名和密码

查看 job_name 配置的已接入的系统
最近更新: 2025/07/30, 15:37:56
安装centos7
Prometheus采集Springboot应用

← 安装centos7 Prometheus采集Springboot应用→

最近更新
01
服务端配置
07-30
02
frp 安装
07-30
03
Prometheus采集Springboot应用
02-20
更多文章>
Theme by Vdoing | Copyright © 2019-2025 | YeLu🤠MiLu🤪 | MIT License 蜀ICP备2024116879号 | 川公网安备51012202001998号
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
欢迎你,我的朋友
看板娘