官网地址:
HTTPS and authentication | Prometheus
结合之前的看 alertManager部署安装、告警规则配置详解及告警消息推送_alertmanager 安装-CSDN博客
version: '3.8' services: prometheus: image: bitnami/prometheus:3.0.0 container_name: prometheus hostname: prometheus ports: - "9090:9090" # Prometheus Web UI 端口 volumes: - ./prometheus.yml:/etc/prometheus/prometheus.yml - ./prometheus-data:/prometheus - ./rules:/rules - ./webconfig.yml:/etc/prometheus/web.yml # 添加此行挂载 web 配置 - ./tls:/etc/prometheus/tls #使用https方式 command: - '--config.file=/etc/prometheus/prometheus.yml' - '--web.external-url=http://192.168.118.20:9090/' #这种方法可以走nginx - '--web.enable-lifecycle' - '--storage.tsdb.retention.time=90d' - "--storage.tsdb.path=/prometheus" - "--web.enable-admin-api" - "--web.config.file=/etc/prometheus/web.yml" # 添加此行引用 web 配置 restart: always
创建webconfig.yaml
tls_server_config:
cert_file: /etc/prometheus/tls/server.crt
key_file: /etc/prometheus/tls/server.key
basic_auth_users:
admin: '$2a$10$IeiTxu.y6Hd9lCAwExctAeXc1Zf.gRVYoFgwZ.dkOWY3IO77sodoS' # 自动生成的真实哈希
basic_auth_users的密码加密方式 使用
方式一:linux自己生成
htpasswd -nBC 10 admin
方式二: 使用在线 Bcrypt Generator - Online Hash Generator and Checker
使用https方式 增加 证书 简单样例 放到tls下
# Step 1: 生成自签名证书和私钥 openssl req -x509 -newkey rsa:2048 \ -keyout server.key -out server.crt \ -days 365 \ -nodes \ -subj "/C=CN/ST=Beijing/L=Beijing/O=Example/CN=localhost"
java端如何调用: 在请求头中 增加Authorization 可以;客户端访问使用base64
promAuth = Base64.getEncoder().encodeToString((promUserName + ":" +promPwd).getBytes(StandardCharsets.UTF_8)); request.header("Authorization", "Basic " + promAuth);