proemtheus TSL加密认证
参考:二、Prometheus TLS加密认证和基于 basic_auth 用户名密码访问_李在奋斗的博客-CSDN博客_prometheus 密码
上次写了一个通过nginx反向代理实现Prometheus
prometheppromethues设置安全认证_无情的搬砖机器的博客-CSDN博客下面总结一下,Prometheus自带的安全认证方式:
一、prometheus
1、安装密码工具 yum -y install httpd-tools
生成的密钥先拷贝下来,后面需要写道配置文件中
2、生成密码:htpasswd -nBC 12 '' | tr -d ':\n'
3、启用TSL,准备证书
openssl req -new -newkey rsa:2048 -days 3650 -nodes -x509 -keyout prometheus.key -out prometheus.crt -subj "/C=CN/ST=Beijing/L=Guangzhou/O=Ctyun/CN=localhost"
4、设置配置文件
mkdir config
mv prometheus.yml prometheus.crt prometheus.key config
[root@evm-test prometheus]# ll
total 203044
drwxr-xr-x 2 root root 90 Jun 28 04:41 config
drwxr-xr-x 2 3434 3434 38 Jun 20 13:27 console_libraries
drwxr-xr-x 2 3434 3434 173 Jun 20 13:27 consoles
drwxr-xr-x 9 root root 240 Jun 28 03:00 data
-rw-r--r-- 1 3434 3434 11357 Jun 20 13:27 LICENSE
-rw-r--r-- 1 3434 3434 3773 Jun 20 13:27 NOTICE
-rwxr-xr-x 1 3434 3434 108069824 Jun 20 13:24 prometheus
-rwxr-xr-x 1 3434 3434 99826736 Jun 20 13:26 promtool
[root@evm-c7j1a8ape0h3uq7dl640 prometheus]# ll
touch config.yml
[root@evm-test prometheus]# ll config/
total 16
-rw-r--r-- 1 root root 162 Jun 28 03:34 config.yml
-rw-r--r-- 1 root root 1277 Jun 28 02:22 prometheus.crt
-rw-r--r-- 1 root root 1704 Jun 28 02:22 prometheus.key
-rw-r--r-- 1 3434 3434 1097 Jun 28 03:26 prometheus.yml
5、编辑配置文件
vim prometheus.yml 此处的password为自己设置的密码如:123456

vim config.yml admin后面是htpasswd -nBC 12 '' | tr -d ':\n'生成的加密信息

6、配置system服务
vi /usr/lib/systemd/system/prometheus.service
[Unit]Description=https://prometheus.io[Service]Restart=on-failureExecStart=/data/opt/prometheus/prometheus --config.file=/data/opt/prometheus/c
onfig/prometheus.yml --web.config.file=/data/opt/prometheus/config/config.yml --
web.listen-address=:18091 --web.enable-lifecycle[Install]WantedBy=multi-user.target
7、启动:systemctl start prometheus,查看日志:journal -f -u prometheus
二、pushgateway
1、生成密码:htpasswd -nBC 12 '' | tr -d ':\n'
2、vi config.yml
basic_auth_users:admin: *****生成加密的密码粘贴在这****
3、配置system服务
vi /usr/lib/systemd/system/pushgateway.service
[Unit]
Description=pushgateway
After=network.target[Service]
ExecStart=/data/opt/pushgateway/pushgateway --web.listen-address=:19091 --web.con
fig.file=/data/opt/pushgateway/config.yml
Restart=on-failure[Install]
WantedBy=multi-user.target
4、systemctl start pushgateway
总结:其实如果环境要求不是很高,Prometheus可以不设置TLS,因为设置了安全证书这些访问的是https请求,java代码修改起来还要适配
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
