Db2 のログ・ストリーミングの構成
Db2監査ロギングを有効にした後、監査ログをIBM® Software Hub監査サービスに転送するためのログ・ストリーミング・ポッドを作成できます。
始める前に
手順
- ご使用の環境の環境変数を作成します。
- 以下のコマンドを実行して、アクティブな Db2uCluster または Db2uInstance の名前を判別します。
oc get db2ucluster,db2uinstance -n ${PROJECT_CPD_INST_OPERANDS} - DB2_CR_ID を、Db2uCluster または Db2uInstanceのリソース名に設定します。
export DB2_CR_ID=<db2ucluster resource name/<db2uinstance resource name> - 以下のコマンドを実行して、データベース・インスタンスの TLS シークレット を判別します。
$ oc get secret -n ${PROJECT_CPD_INST_OPERANDS} | grep tls - INSTANCE_TLS 環境変数を、ログ・ストリーミングを構成するデータベース・インスタンスの TLS シークレット に設定します。
export INSTANCE_TLS=<instance-tls>DB2OLTPインスタンスの場合、これをデフォルトの シークレット に設定できます。export INSTANCE_TLS=db2oltp-internal-tls
- 以下のコマンドを実行して、アクティブな Db2uCluster または Db2uInstance の名前を判別します。
- Db2uCluster または Db2uInstance に対して以下のコマンドを実行して、監査ロギングが有効になっていること、およびデプロイ済みデータベース用に
auditlogs PVCが作成されていることを確認します。Db2uCluster の場合:
Db2uInstance の場合:oc get db2u <DB2_CR_ID> -oyamloc get db2 <DB2_CR_ID> -oyamlenableAuditがtrueに設定され、auditlogs PVCがstorage configsに追加されていることを確認します。 - Db2uCluster または Db2uInstance のログ・ストリーム・ポッドを作成します。
cat << EOF | oc apply -f - apiVersion: db2ulog.databases.ibm.com/v1alpha1 kind: Db2uLogStream metadata: name: $DB2_CR_ID spec: configurations: - type: audit format: cadf connection: cp4d connections: cp4d: endpoint: https://zen-audit-svc.${PROJECT_CPD_INST_OPERANDS}:9880/records credentials: $INSTANCE_TLS authType: tls resources: # this field is optional and used to control the resources of the logstreaming pod limits: cpu: "100m" memory: "300Mi" requests: cpu: "100m" memory: "300Mi" EOF注:resourcesフィールドにデータを設定することにより、ログ・ストリーミング・ポッドのリソース制限を設定できます。 フィールドを空のままにすると、デフォルト値が使用されます。yamlファイルを適用した後、ログ・ストリーム・ポッドが作成されます。 以下のコマンドを実行して、ポッドがアクティブになったことを確認できます。
このコマンドは、以下の例のような出力を生成します。$ oc get pod | grep logstreamc-db2oltp-audit-test-logstream-6fb596cd5f-5r4xd 1/1 Running 0 43h - オプション: ログ・ストリーミングのデバッグ・モードを有効にします。デバッグ・モジュールは、ログ・ストリーミング・ポッドからの出力に詳細を返します。
- 以下のコマンドを実行して、ログ・ストリーミング・ポッドを編集します。
oc edit cm c-<instance-name>-logstream -oyaml - インスタンスの
dataフィールドに以下の内容を追加します。fluent.conf: "\n <system>\n log_level trace\n </system>\n \ <source>\n @type tail\n path /var/log/auditlogs/*.del\n \ pos_file /tmp/auditlog.pos\n tag audit.*\n <parse>\n \ @type none\n </parse>\n </source>\n\n <filter audit.**>\n @type audit\n </filter>\n <filter audit.**>\n \ @type cadf\n </filter>\n <match audit.**>\n @type http\n\t\t\t\t\t endpoint https://zen-audit-svc.zen:9880/records\n\t\t\t\t\t \ <format>\n\t\t\t\t\t\t @type json\n\t\t\t\t\t </format>\n\t\t\t\t\t json_array true\n\t\t\t\t\t \n\t\ttls_ca_cert_path /etc/credentials/cp4d/ca.crt\n tls_client_cert_path /etc/credentials/cp4d/tls.crt\n tls_private_key_path /etc/credentials/cp4d/tls.key\n\t\t\n \ </match>\n " - 以下のコマンドを実行して、ログ・ストリーミング・ポッドを削除します。
ログ・ストリーミング・ポッドが再始動し、新しい構成が適用されます。oc delete pod c-<instance-name>-logstream-0
- 以下のコマンドを実行して、ログ・ストリーミング・ポッドを編集します。