OCP監視へのアクセスにHTTPS方式を使用する場合は、この記事を参照してOCPとPrometheusにTLSおよび関連する証明書を追加してください。
PrometheusにTLSを追加する
詳細については、Prometheus公式Webサイトの説明を参照してください:https://prometheus.ac.cn/docs/guides/tls-encryption/
PrometheusにTLS暗号化を設定する際には、以下の点に注意してください:
生成された
prometheus.crt、prometheus.key、prometheus-ca.pemをPrometheusに登録する必要があります。web.ymlファイルに以下の設定を追加します(/etc/はDockerコンテナ内部のパスです):tls_server_config: cert_file: /etc/prometheus/prometheus.crt key_file: /etc/prometheus/prometheus.keyDocker起動コマンドに以下のパラメータを追加します:
-v /home/admin/docker/prometheus/prometheus.crt:/etc/prometheus/prometheus.crt -v /home/admin/docker/prometheus/prometheus.key:/etc/prometheus/prometheus.key
OCPにTLSを追加する
OCPにログインし、システムパラメータでocp.site.urlをhttps://ip:portに変更します。
OCPにPrometheusの証明書を追加する方法
接続可能な任意のPrometheusサーバーで以下のコマンドを実行し、サーバー証明書をエクスポートします。ここで、
IP:9090はPrometheusのアドレスです:openssl s_client -connect IP:9090 -servername IP </dev/null 2>/dev/null | openssl x509 -out /tmp/prometheus-server.pemサーバー証明書を、OCPの実行に使用するJDKの
cacertsにインポートします。パスとパスワードは実際の状況に応じて変更してください。デフォルトのパスワードは通常changeitです:keytool -importcert -noprompt -alias prometheus-61315353-9090 -file /tmp/prometheus-server.pem -cacerts -storepass changeit証明書が正常にインポートされたか確認します:
keytool -list -cacerts -storepass changeit | grep prometheusOCPコンテナを再起動すると、外部統合で
https://形式でPrometheusにアクセスできるようになります。
PrometheusにOCPの証明書を追加する方法
ステップ1:OCP HTTPS 8443ポートの証明書タイプを確認する
OCPにアクセス可能なサーバーで以下のコマンドを実行します:
openssl s_client -connect $OCP_IP:8443 -servername $OCP_IP </dev/null 2>/dev/null | openssl x509 -noout -issuer -subject -dates
Issuer を確認し、Prometheus の ca_file ファイルにその Issuer の公開鍵証明書(サードパーティ CA が発行した証明書および自己署名証明書を含む)が含まれていることを確認します。
サーバー証明書を保存して、比較のために使用します:
openssl s_client -connect $OCP_IP:8443 -servername $OCP_IP </dev/null 2>/dev/null | openssl x509 > /tmp/ocp-8443-cert.pem
ステップ2:自己署名証明書/単一ファイルをca_fileに配置する
OCPが自己署名証明書を使用している場合(IssuerとSubjectが同一のDNセットである場合)、ca_file にはこのサーバー証明書のPEM形式ファイルを含める必要があります(/tmp/ocp-8443-cert.pem の内容と一致させるだけで構いません)。例:
cp /tmp/ocp-8443-cert.pem /path/on/prometheus/ocp-for-prometheus-ca.pem
prometheus.yml に以下の設定を追加する必要があります:
tls_config:
ca_file: /path/on/prometheus/ocp-for-prometheus-ca.pem
注意
他のマシンのCA証明書やPrometheus自身の証明書を prometheus.yml に追加しないでください。そうしないと、unknown authority エラーが発生します。
ステップ3:OCP証明書をDockerに同期する
Docker内で以下のコマンドを実行します:
-v /home/admin/docker/prometheus/ocp-for-prometheus-ca.pem:/etc/prometheus/ocp-for-prometheus-ca.pem
Dockerを起動した後、Prometheusのログを注意深く観察してください。OCPへのアクセス失敗が発生した場合、OCP証明書にまだ問題があることを意味します。
ステップ4:OCP TLS認証を一時的に無視する
prometheus.yml に insecure_skip_verify: true を追加し、Prometheusサービスを再起動します:
scrape_configs:
- job_name: 'ocp_sd'
scheme: 'http'
fallback_scrape_protocol: "PrometheusText1.0.0"
tls_config:
insecure_skip_verify: true
# ca_file: /etc/prometheus/ocp-for-prometheus-ca.pem
http_sd_configs:
- url: 'https://xx.xx.xx.xx:8080/api/v2/monitor/prometheus_sd'
tls_config:
insecure_skip_verify: true
basic_auth: # OCPにアクセスしてprometheus_sd内のすべてのtargetを取得する
username: "******"
password: "******"
basic_auth: # すべてのTargetへのアクセスを制御する
username: "******"
password: "******"
よくある質問
起動後もOCPのPrometheusポートにアクセスできない場合、どう解決しますか?
この問題は、OCPとOCP-Agentがサポートする転送プロトコルが異なるために発生します。OCPはHTTPS認証方式をサポートしていますが、OCP-AgentはHTTP認証方式のみをサポートしています。以下の一時的な解決策を参考に、prometheus.ymlに別途jobを追加して解決できます。
- job_name: 'ocp_self'
scheme: 'https'
fallback_scrape_protocol: "PrometheusText1.0.0" # このパラメータはprometheus 3.xでのみ存在します。2.xではこのパラメータを削除してください。
metrics_path: '/api/v2/actuator/prometheus'
tls_config:
insecure_skip_verify: true
static_configs:
- targets: ['xx.xx.xx.xx:8443'] # ここはOCPのTLSアドレスです。
basic_auth:
username: "******"
password: "******"