栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

prometheus-basic

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

prometheus-basic


文章目录
  • 前言
  • 一、basic_auth加密的引入
  • 二、使用步骤
    • 1.生成basic_auth密钥
    • 2.将密钥文件写入config.yml文件内
    • 3.查看prometheus相关参数
    • 4.修改prometheus配置
    • 5.启动服务
      • 5.1 service模式
      • 5.2 docker模式
    • 六.访问测试
    • 在这里插入图片描述 测试正常
  • 总结
  • 参考


前言

记录一下prometheus-basic_auth加密的开启


一、basic_auth加密的引入

平常使用prom都是没有加密的安全措施的,有一些节点直接暴漏在公网上了,不安全。现在使用basic_auth加密,可以加个密码,安全一些。

二、使用步骤 1.生成basic_auth密钥

安装工具包并生成加密后密码

#安装工具包
yum install -y httpd-tools
#生成加密密码
htpasswd -nBC 12 '' | tr -d ':n'
New password:               # 这里设置密码为123456,实际使用请按照自己的集群需求定义密码
Re-type new password:
#生成的密码信息
$2y$12$mMnPuKlOQ97ff4NjDsQTMukAtRS/ILpjxjEQrCN0vefs0CBLe/hi6
2.将密钥文件写入config.yml文件内

准备配置文件

cat > ./config.yml< 
3.查看prometheus相关参数 

查看prometheus配置项

prometheus --help
	--web.config.file=""       [EXPERIMENTAL] Path to configuration file that can enable TLS or authentication.

在运行时增加- -web.config.file配置即可启用加密


4.修改prometheus配置

修改配置,增加basic_auth配置

scrape_configs:
  - job_name: 'prometheus'
    basic_auth:
      username: admin
      password: 123456
    static_configs:
    - targets: ['prometheus:9090']

5.启动服务 5.1 service模式

修改/usr/lib/systemd/system/prometheus.service文件,在ExecStart后面追加–web.config.file=/xx/xx/xx/config.yml

例:

cat /usr/lib/systemd/system/prometheus.service 

[Unit]
  Description=https://prometheus.io

  [Service]
  Restart=on-failure
  ExecStart=/usr/local/prometheus/prometheus --config.file=/usr/local/prometheus/prometheus.yml --web.config.file=/usr/local/prometheus/config.yml

  [Install]
  WantedBy=multi-user.target
5.2 docker模式

修改镜像,在服务启动脚本命令内增加–web.config.file配置,

例:

CMD        [ "--config.file=/etc/prometheus/prometheus.yml", 
             "--storage.tsdb.path=/prometheus", 
             "--web.console.libraries=/usr/share/prometheus/console_libraries", 
             "--web.console.templates=/usr/share/prometheus/consoles", 
             "--web.config.file=/etc/prometheus/config.yml" ]

镜像制作完毕之后,在启动容器时,将config.yml传递到/etc/prometheus/config.yml位置即可

  prometheus:
    image: prometheus:1
    volumes:
      - type: bind
        source: ./xxx/xxx/config.yml
        target: /etc/prometheus/config.yml
        read_only: true

六.访问测试
测试正常 总结

basic_auth能起到简单的保护作用,比使用tls密钥使用更方便,在一些特定场景有奇效

参考

二、Prometheus TLS加密认证和基于 basic_auth 用户名密码访问:link

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/963276.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号