对登录密码进行哈希处理
root@localhost:# htpasswd -nBC 10 "" | tr -d ':\n'; echo
New password: #输入要设置的密码
Re-type new password: #再次输入要设置的密码
$2y$10$4aR1PU21mC.VB7c/HYigNeyVwsG7U1xzgVbvULbqkaE.YsRU8oJpi #对密码哈希过的值
创建身份认证配置文件
cat > basic_auth.yaml << EOF
basic_auth_users:
prometheus: $2y$10$4aR1PU21mC.VB7c/HYigNeyVwsG7U1xzgVbvULbqkaE.YsRU8oJpi
EOF
- 用户名:prometheus
- 密码:$2y$10$4aR1PU21mC.VB7c/HYigNeyVwsG7U1xzgVbvULbqkaE.YsRU8oJpi
在启动配置中新增密码认证配置信息
cat > /etc/systemd/system/prometheus.service << EOF
[Unit]
Description=Prometheus Server
Documentation=https://prometheus.io/docs/introduction/overview/
After=network.target
[Service]
Restart=on-failure
WorkingDirectory=/apps/prometheus/
ExecStart=/apps/prometheus/prometheus \
--config.file=/apps/prometheus/prometheus.yml \
--web.enable-lifecycle \
--storage.tsdb.retention=30d \
--web.enable-admin-api \
--web.config.file="/apps/prometheus/basic_auth.yaml"
[Install]
WantedBy=multi-user.target
EOF
重启服务或者重载服务配置使其生效
重启服务
systemctl daemon-reload && systemctl restart prometheus
重载服务配置
curl -u "prometheus:Seca@2024" -X POST "http://10.84.3.125:9090/-/reload"
仅登录用户可评论,点击 登录