为 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"
  ]
}
相关推荐
不染尘.16 小时前
UDP客户服务器模型和UDP协议
服务器·网络·网络协议·计算机网络·udp
爬山算法19 小时前
Netty(21)Netty的SSL/TLS支持是如何实现的?
网络·网络协议·ssl
渡我白衣19 小时前
计算机组成原理(7):定点数的编码表示
汇编·人工智能·嵌入式硬件·网络协议·机器学习·硬件工程
Bruce_Liuxiaowei21 小时前
网站敏感文件_目录大全(分类记忆+风险标注)
运维·网络·网络协议·http·网络安全·https
猛喝威士忌21 小时前
【虚拟机】使用OpenWrt作为虚拟机集群的软路由(下)
linux·网络协议
2401_8904430221 小时前
传输层协议TCP
网络·网络协议·tcp/ip
玥轩_5211 天前
静态路由原理 及实验案例
网络·网络协议·网络安全·智能路由器·路由器·交换机
charlee441 天前
使用cpp-httplib发布HTTP服务
c++·http·json·cpp-httplib
while(1){yan}1 天前
数据链路层与物理层
java·网络·网络协议
大白同学4211 天前
UDP Socket编程的三级跳:简单到复杂的优雅过渡
网络·网络协议·udp