为 Promethus 配置https访问

一、序言

本篇将介绍如何使用数字证书为Promethus 访问提供加密功能,由于是实验环境证书由openssl生成,操作指南来自官网手册:https://prometheus.io/docs/guides/tls-encryption/

在生产环境中prometheus可能会放在后端,证书一般配置在前端。

二、生成ssl证书

复制代码
openssl req \
  -x509 \
  -newkey rsa:4096 \
  -nodes \
  -keyout prometheus.key \
  -out prometheus.crt \
  -subj "/CN=192.168.25.225"
  • -subj "/CN=192.168.25.225" : 指定服务器地址或者域名

查看证书文件:

复制代码
ls /root/certificate/
clike 复制代码
prometheus.crt  prometheus.key

三、配置Promethus

认证也是这个文件,认证操作指导:https://prometheus.io/docs/guides/basic-auth

1. 创建web-config.yml 文件配置证书

clike 复制代码
tls_server_config:
  cert_file: /root/certificate/prometheus.crt
  key_file: /root/certificate/prometheus.key

2. 修改prometheus.yml文件

复制代码
scrape_configs:
  - job_name: "node"
    metrics_path: "/metrics"
    scheme: "https"		# 协议这里需要选择https
    tls_config:
      ca_file: /root/certificate/prometheus.crt
      insecure_skip_verify: true
    static_configs:
    - targets: ['localhost:9090']

添加tls_config配置:

  • ca_file:指定公钥位置
  • insecure_skip_verify: 禁用服务器对证书验证(因为是自建证书所以必须开启)

3. Prometheus 启动时指定web-config.yml配置文件

复制代码
./prometheus \
  --config.file=./prometheus.yml \
  --web.config.file=./web-config.yml 

4. 使用https访问Prometheus

复制代码
curl --cacert /root/certificate/prometheus.crt  https://192.168.25.225:9090/api/v1/label/job/values | jq
clike 复制代码
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    68  100    68    0     0   4008      0 --:--:-- --:--:-- --:--:--  4533
{
  "status": "success",
  "data": [
    "node",
    "prometheus",
    "promethus",
    "test"
  ]
}

或者跳过证书:

复制代码
curl -k  https://192.168.25.225:9090/api/v1/label/job/values | jq
clike 复制代码
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100    68  100    68    0     0   3944      0 --:--:-- --:--:-- --:--:--  4250
{
  "status": "success",
  "data": [
    "node",
    "prometheus",
    "promethus",
    "test"
  ]
}
相关推荐
早退的程序员29 分钟前
记一次 Maven 3.8.3 无法下载 HTTP 仓库依赖的排查历程
java·http·maven
拾忆,想起2 小时前
超时重传 vs 快速重传:TCP双保险如何拯救网络丢包?
java·开发语言·网络·数据库·网络协议·tcp/ip·php
2021_fc3 小时前
WebSocket技术分享
网络·websocket·网络协议
zizisuo3 小时前
为什么TCP设计中要设计ACK不重传?
网络·网络协议·tcp/ip
GhostGuardian4 小时前
DNS报文结构全解析
网络·网络协议
宁雨桥5 小时前
WebSocket 完全指南:从原理到实战,搭建实时通信桥梁
网络·websocket·网络协议
xinxinhenmeihao5 小时前
爬虫导致IP被封号了如何解封?
爬虫·网络协议·tcp/ip
草莓熊Lotso5 小时前
Linux 基础开发工具入门:软件包管理器的全方位实操指南
linux·运维·服务器·c++·人工智能·网络协议·rpc
拾忆,想起5 小时前
TCP滑动窗口:网络世界的“智能流量阀门”
java·网络·数据库·网络协议·tcp/ip·php·哈希算法
止水编程 water_proof6 小时前
Java--HTTP(上)
网络·网络协议·http