Prometheus : Basic 認証と HTTPS を有効にする2022/11/17 |
|
Prometheus のエンドポイントアクセスに対して、Basic 認証と HTTPS を有効にします。
|
|
| [1] | |
| [2] | Prometheus の設定です。 |
|
[root@dlp ~]#
dnf -y install httpd-tools # bcrypt hash でパスワード生成 # ユーザー名は任意の名称で OK [root@dlp ~]# htpasswd -nB admin New password: Re-type new password: admin:$2y$05$LKuSwM2V.u/3.9CsByLeBuNUp4IeiB5oSUl4UcdXSQOcXlyPTqtDO
[root@dlp ~]#
cp /etc/pki/tls/certs/{server.crt,server.key} /etc/prometheus/ [root@dlp ~]# chown prometheus. /etc/prometheus/{server.crt,server.key}
[root@dlp ~]#
vi /etc/prometheus/web.yml # 新規作成 # 自身の証明書を指定 tls_server_config: cert_file: server.crt key_file: server.key # 生成したユーザーとパスワードを指定 basic_auth_users: admin: $2y$05$LKuSwM2V.u/3.9CsByLeBuNUp4IeiB5oSUl4UcdXSQOcXlyPTqtDO
[root@dlp ~]#
vi /etc/default/prometheus # 追記 PROMETHEUS_OPTS='--config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus/data --web.console.libraries=/usr/share/prometheus/console_libraries --web.console.templates=/usr/share/prometheus/consoles --web.config.file=/etc/prometheus/web.yml'
[root@dlp ~]#
vi /etc/prometheus/prometheus.yml
.....
.....
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: "prometheus"
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
# 認証と証明書の設定を追記
scheme: https
tls_config:
cert_file: /etc/prometheus/server.crt
key_file: /etc/prometheus/server.key
# 自己署名の証明書の場合は [true]
insecure_skip_verify: true
basic_auth:
username: 'admin'
password: 'password'
static_configs:
# 正規の証明書の場合は証明書に登録のホスト名と合わせる
- targets: ["localhost:9090"]
[root@dlp ~]# systemctl restart prometheus
|
| [3] | Prometheus のエンドポイントへ Web アクセス (HTTPS) して、設定通り、認証できれば OK です。 |
|
|
| Sponsored Link |
|
|