prometheus学习系列十一: Prometheus 安全

prometheus安全

我们这里说的安全主要是基本认证和https2种, 目前这2种安全在prometheus中都没有的, 需要借助第三方软件实现, 这里以nginx为例。

基本认证

配置基本认证

在前面的部署中,我们部署完毕prometheus server 后, 可以通过对应的http://192.168.100.10:9090就可以访问到我们的 表达式浏览器, 进行promql的查询了。 这是很不安全, 必要情况下,我们需要加入基本认证, 只有认证过的用户才能访问页面,进行数据的查询。

[[email protected] ~]# yum install httpd-tools  nginx
[[email protected] ~]# cd  /etc/nginx
[[email protected] nginx]# htpasswd -c /etc/nginx/.htpasswd admin

[[email protected] conf.d]# cat prometheus.linuxpanda.tech.conf
    server {
        listen 80;
        server_name prometheus.linuxpanda.tech ;

        location / {
            auth_basic           "Prometheus";
            auth_basic_user_file /etc/nginx/.htpasswd;
            proxy_pass           http://localhost:9090/;
        }
    }
[[email protected] conf.d]# pwd
/etc/nginx/conf.d
[[email protected] conf.d]# cat prometheus.linuxpanda.tech.conf
    server {
        listen 80;
        server_name prometheus.linuxpanda.tech ;

        location / {
            auth_basic           "Prometheus";
            auth_basic_user_file /etc/nginx/.htpasswd;
            proxy_pass           http://localhost:9090/;
        }
    }

[[email protected] conf.d]# systemctl restart nginx
[[email protected] conf.d]# systemctl status nginx 

[[email protected] system]# pwd
/usr/lib/systemd/system
[[email protected] system]# cat prometheus.service
[Unit]
Description=prometheus
After=network.target 

[Service]
User=prometheus
Group=prometheus
WorkingDirectory=/usr/local/prometheus/prometheus
ExecStart=/usr/local/prometheus/prometheus/prometheus --web.external-url=http://prometheus.linuxpanda.tech
[Install]
WantedBy=multi-user.target

[[email protected] system]# systemctl daemon-reload
[[email protected] system]# sytemctl restart prometheus
-bash: sytemctl: command not found
[[email protected] system]# systemctl restart prometheus
[[email protected] system]# systemctl status prometheus 

测试

配置域名解析

由于我们使用的是prometheus.linuxpanda.tech 这个域名, 我们需要确保这个域名能正常解析到对应的ip地址上面, 这里使用host绑定方式。

# 在我宿主机的hosts文件中加入如下行
192.168.100.10   prometheus.linuxpanda.tech 

登陆

在浏览器输入prometheus.linuxpanda.tech 这个域名后, 效果图如下,

输入我们前面设置的账户和密码 admin/admin 登陆后,效果如下。

https

配置https是需要证书的, 正式环境中的域名是需要花钱的,我们这里使用openssl这个软件来生成一个自签证书测试使用。

https配置

[[email protected] nginx]# cd /etc/nginx/
[[email protected] nginx]# mkdir ssl
[[email protected] nginx]# cd ssl/
[[email protected] ssl]# openssl req  -x509 -newkey rsa:4096  -nodes  -keyout prometheus.linuxpanda.tech.key -out prometheus.linuxpanda.tech.crt
Generating a 4096 bit RSA private key
.............................................................++
...................................................................................................................................................++
writing new private key to ‘prometheus.linuxpanda.tech.key‘
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.‘, the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:Bei
Locality Name (eg, city) [Default City]:^C
[[email protected] ssl]# openssl req  -x509 -newkey rsa:4096  -nodes  -keyout prometheus.linuxpanda.tech.key -out prometheus.linuxpanda.tech.crt
Generating a 4096 bit RSA private key
..............................................................................................................................................................++
...............................................................++
writing new private key to ‘prometheus.linuxpanda.tech.key‘
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter ‘.‘, the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:BEIJING
Locality Name (eg, city) [Default City]:BEIJING
Organization Name (eg, company) [Default Company Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server‘s hostname) []:prometheus.linuxpanda.tech
Email Address []:

[[email protected] conf.d]# pwd
/etc/nginx/conf.d
[[email protected] conf.d]# cat prometheus.linuxpanda.tech.conf
    server {
        listen 80;
        listen 443 ssl;
        server_name prometheus.linuxpanda.tech ;
        ssl_certificate     ssl/prometheus.linuxpanda.tech.crt;
        ssl_certificate_key ssl/prometheus.linuxpanda.tech.key;
        location / {
            auth_basic           "Prometheus";
            auth_basic_user_file /etc/nginx/.htpasswd;
            proxy_pass           http://localhost:9090/;
        }
    }

[[email protected] conf.d]# systemctl restart nginx
[[email protected] conf.d]# systemctl status nginx 

测试

在浏览器输入https://prometheus.linuxpanda.tech 这个域名后,也是会提示不安全的, 那是因为我们使用的是openssl自签证书,忽略证书信息,继续访问,可以访问到如下页面。

原文地址:https://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_liunx_68_prometheus_security.html

时间: 2024-08-30 14:17:12

prometheus学习系列十一: Prometheus 安全的相关文章

Prometheus学习系列(六)之Prometheus 查询说明

前言 本文来自Prometheus官网手册和 Prometheus简介 Prothetheus查询 Prometheus提供一个函数式的表达式语言PromQL (Prometheus Query Language),可以使用户实时地查找和聚合时间序列数据.表达式计算结果可以在图表中展示,也可以在表达式浏览器中以表格形式展示,或者作为数据源, 以HTTP API的方式提供给外部系统使用. 一.例子 本文档仅供参考, 对于学习,从几个例子开始可能更容易. 二.表达式语言数据类型 在Prometheu

Prometheus学习系列(九)之Prometheus 联盟、迁移

前言 本文来自Prometheus官网手册 和 Prometheus简介 FEDERATION 允许Prometheus服务器从另一台Prometheus服务器抓取选定的时间序列. 一,用例 联盟有不同的用例.通常,它用于实现可扩展的Prometheus监控设置或将相关指标从一个服务的Prometheus拉到另一个服务. 1.1 分层联盟 分层联盟使Prometheus可以扩展到具有数十个数据中心和数百万个节点的环境.在此用例中,联合拓扑就像一棵树,更高级别的Prometheus服务器从大量从属

prometheus学习系列一: Prometheus简介

Prometheus简介 prometheus受启发于Google的Brogmon监控系统(相似kubernetes是从Brog系统演变而来), 从2012年开始由google工程师Soundcloud以开源形式进行研发,并且与2015年早起对外发布早期版本. 2016年5月继kubernetes之后成为第二个加入CNCF基金会的项目,童年6月正式发布1.0版本.2017年底发布基于全兴存储层的2.0版本,能更好地与容器平台.云平台配合. prometheus的优势 prometheus是基于一

Prometheus学习系列(八)之Prometheus HTTP API说明

前言 本文来自Prometheus官网手册 和 Prometheus简介 HTTP API 在Prometheus服务器上的/api/v1下可以访问当前稳定的HTTP API. 将在该端点下添加任何非中断添加项. 一.格式概述 API返回是JSON格式,每个请求成功的返回值都是以2xx开头的编码.如果API处理的是无效请求,返回一个JSON错误对象,并返回下面的错误码: 400 Bad Request.当参数错误或者丢失时. 422 Unprocessable Entity.当一个表达式不能被执

Quartz.NET学习系列(十一)--- Quartz.NET持久化及客户端服务器模式

持久化         Quartz.NET如果不进行数据库相关配置,则默认的执行模式为内存模式,优点是执行速度快,确定就是数据无法存储,宕机了需要重新开始. 持久化只需要做如下配置(以SQLServer为例) NameValueCollection properties = new NameValueCollection(); //存储类型 properties["quartz.jobStore.type"] = "Quartz.Impl.AdoJobStore.JobSt

hadoop 入门学习系列十一----hue安装

1. hue整体架构 2.解压hue 3.安装依赖 yum install gmp-devel 4. 编译 make apps 5.修改hue的配置文件 desktop/conf/hue.ini 6.启动hue 7.Hue与hadoop集成 在hadoop的core-site.xml里增加配置 <property> <name>hadoop.proxyuser.hue.hosts</name> <value>*</value> </prop

MVC3+EF4.1学习系列(十一)----EF4.1常见的问题解决

博客写了10篇了~有很多朋友私信问了一些问题,而且很多问题 大家问的都一样 这里说说这些常见问题的解决办法.如果大家有更好的解决办法~也希望分享出来 问题大概为这几个 一.ef4.1 codeFirst 修改表结构 增加字段等 EF code first需要重新生成库导致数据丢失的问题. 二.ef4.1 没有了edmx等复杂的东西 变得简单 干净  但如何使用存储过程,存储过程可以返回表 可以返回数值 也有可能是执行修改 删除 增加等  该怎么做? 三.ef4.1 如何使用数据库视图?每个视图都

Castle学习系列(十一)---Windsor性能检测

Windsor提供了容器性能检测的功能,只需在程序启动的时候后添加一下代码 var diagnostic = LifecycledComponentsReleasePolicy.GetTrackedComponentsDiagnostic(_container.Kernel); var counter = LifecycledComponentsReleasePolicy.GetTrackedComponentsPerformanceCounter(new PerformanceMetricsF

Quartz.NET学习系列

Quartz.NET是一个开源的任务调度引擎,对于周期性的任务,持续性的任务提供了很好的支持,并支持持久化,集群等功能.一下是我这个对于Quartz.NET的学习记录: 源码下载地址http://yunpan.cn/cZcHVh7W3SB3X  访问密码d45a 由于博客编辑器的问题,部分代码可能显示不完全,可点击 这个按钮来获取完整的源码 Quartz.NET学习系列(一)--- 快速入门 Quartz.NET学习系列(二)--- 简单触发器 Quartz.NET学习系列(三)--- Cron