Prometheus : Basic 認証と HTTPS を有効にする2024/09/06 |
|
Prometheus のエンドポイントアクセスに対して、Basic 認証と HTTPS を有効にします。 |
|
| [1] |
事前に SSL/TLS 証明書を取得 または
自己署名の証明書を作成しておきます。 |
| [2] | Prometheus の設定です。 |
|
root@dlp:~ #
pkg install -y apache24 # bcrypt hash でパスワード生成 # ユーザー名は任意の名称で OK root@dlp:~ # htpasswd -nB admin New password: Re-type new password: admin:$2y$05$.Ne.2SccDPsUYWquhSu3OOebB85g3pde/7nnrWmrIOnVw8x2KJDyS
root@dlp:~ #
cp /usr/local/etc/ssl/server.crt /usr/local/etc/ssl/server.key /usr/local/etc/ root@dlp:~ # chown prometheus:prometheus /usr/local/etc/server.crt /usr/local/etc/server.key
root@dlp:~ #
vi /usr/local/etc/prometheus-web.yml # 新規作成 # 自身の証明書を指定 tls_server_config: cert_file: /usr/local/etc/server.crt key_file: /usr/local/etc/server.key # 生成したユーザーとパスワードを指定 basic_auth_users: admin: $2y$05$.Ne.2SccDPsUYWquhSu3OOebB85g3pde/7nnrWmrIOnVw8x2KJDyS
root@dlp:~ #
vi /usr/local/etc/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: /usr/local/etc/server.crt
key_file: /usr/local/etc/server.key
# 自己署名の証明書の場合は [true]
insecure_skip_verify: true
basic_auth:
username: 'admin'
password: 'password'
static_configs:
# 正規の証明書の場合は証明書に登録のホスト名と合わせる
- targets: ["localhost:9090"]
root@dlp:~ # sysrc prometheus_args="--web.config.file=/usr/local/etc/prometheus-web.yml" prometheus_args: -> --web.config.file=/usr/local/etc/prometheus-web.yml root@dlp:~ # service prometheus restart
|
| [3] | Prometheus のエンドポイントへ Web アクセス (HTTPS) して、設定通り、認証できれば OK です。 |
|
|
| Sponsored Link |
|
|