請按照本節的操作說明設定中央記錄伺服器。
設定儲存空間值區
建立新的儲存空間 bucket,用來儲存設備記錄:
gcloud storage buckets create gs://BUCKET_NAME
如果尚未啟用 IAM API,請啟用:
gcloud services enable iam.googleapis.com
建立服務帳戶,以便存取 bucket:
gcloud iam service-accounts create GSA_NAME --description="DESCRIPTION" --display-name="DISPLAY_NAME"
將資料從 GDC 轉移至儲存空間 bucket
轉移資料,將資料匯出至儲存空間值區。
將 Grafana 和 Loki Helm 圖表從 GDC 零氣隙裝置複製到本機
在 GDC 氣隙隔離裝置的啟動程式上,Grafana 和 Loki 的 Helm 圖表位於 RELEASE_DIR/appliance/observability
中。將這些檔案複製到執行這項設定的本機電腦:
scp
USERNAME@BOOTSTRAPPER:/RELEASE_DIR/appliance/observability/grafana.tgz WORKING_DIR/grafana.tgz
scp
USERNAME@BOOTSTRAPPER:/RELEASE_DIR/appliance/observability/loki.tgz WORKING_DIR/loki.tgz
在 GKE 叢集中設定 Grafana 和 Loki
建立新的 GKE 叢集: https://cloud.google.com/sdk/gcloud/reference/container/clusters/create。如果使用現有叢集進行這項設定,請繼續下一個步驟。
安裝及設定 kubectl,以便與叢集互動: https://cloud.google.com/kubernetes-engine/docs/how-to/cluster-access-for-kubectl
為叢集啟用 Workload Identity: https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity#enable-existing-cluster
請按照 https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/cloud-storage-fuse-csi-driver#enable 的說明,在 GKE 叢集中啟用 Cloud Storage FUSE CSI 驅動程式。
請按照 https://cloud.google.com/kubernetes-engine/docs/how-to/persistent-volumes/cloud-storage-fuse-csi-driver#authentication 的說明,使用 GKE 適用的工作負載身分聯盟設定 Cloud Storage 儲存空間的存取權。在步驟 5 中設定 IAM 政策繫結時,請選擇
roles/storage.objectAdmin
。請按照 https://cloud.google.com/artifact-registry/docs/repositories/remote-repo 建立 Artifact Registry 遠端存放區,做為 Dockerhub 的 Proxy,這個外部登錄檔包含 Grafana 和 Loki Helm 圖表使用的容器映像檔。
下載並解壓縮 Grafana 和 Loki Helm 圖表:
tar -xzf WORKING_DIR/grafana.tgz tar -xzf WORKING_DIR/loki.tgz
在 WORKING_DIR/loki/values.yaml.in 中設定 Loki Helm 資訊套件值,並在叢集中安裝 Helm 資訊套件:
helm install LOKI_RELEASE_NAME WORKING_DIR/loki --namespace NAMESPACE
在 WORKING_DIR/grafana/values.yaml.in 中設定 Grafana helm 資訊套件值,並在叢集中安裝 helm 資訊套件:
helm install GRAFANA_RELEASE_NAME WORKING_DIR/grafana --namespace NAMESPACE
例如:
app: # name is the name that will used for creating kubernetes resources # like deployment, service, etc. associated with this grafana app. name: grafana # artifactRegistryRepository is the full name of the artifact registry remote # repository that proxies dockerhub. artifactRegistryRepository: us-east1-docker.pkg.dev/my-gcp-project/dockerhub loki: # serviceName is the name of the kubernetes service that exposes # the loki server. serviceName: loki # serviceNamespace is the namespace in which the loki service is present serviceNamespace: my-loki-namespace # tenantID is the tenant ID of the logs. tenantID: infra-obs
存取 Grafana UI
在電腦與 Kubernetes 叢集的 Grafana 服務之間設定通訊埠轉送,即可存取 Grafana UI:
kubectl port-forward service/GRAFANA_APP_NAME
-n NAMESPACE 3000:3000
執行上述指令後,您就能存取 Grafana 使用者介面。如要向貴機構的多位使用者公開 Grafana UI,請考慮設定 GKE Ingress:https://cloud.google.com/kubernetes-engine/docs/tutorials/http-balancer
將記錄匯出至外部儲存空間
根據預設,叢集中執行的 Loki 執行個體會彙整並儲存所有記錄。不過,您可以設定額外的 Fluent Bit 輸出,將記錄檔匯出至根管理員叢集上 Loki 執行個體以外的其他目的地。
本節說明如何設定額外的接收器,將記錄檔轉送及匯出至外部儲存空間。並根據您的用途,提供下列記錄類型的操作說明:
如要查看支援的 Fluent Bit 目的地完整清單,請參閱 https://docs.fluentbit.io/manual/pipeline/outputs。
匯出作業記錄
請按照下列步驟將作業記錄匯出至外部儲存空間:
在
obs-system
命名空間中,使用logmon: system_logs
標籤建立ConfigMap
物件。在data
區段的output.conf
檔案中,新增額外的輸出設定。語法必須與 Fluent Bit 輸出外掛程式相同。建立
ConfigMap
物件時,請務必符合下列規定:- 請記下您指派給
ConfigMap
物件的名稱,因為這個名稱必須與後續步驟中指定的值相符。 - 在物件的「輸出區塊」部分,新增自訂的 Fluent Bit 輸出外掛程式設定。
下列 YAML 檔案顯示
ConfigMap
物件的範本,說明先前的需求。apiVersion: v1 kind: ConfigMap metadata: # The name should match the configmap name specified in step 3. name: <descriptive configmap name> namespace: obs-system labels: # This label is required and must be system_logs for system logs logmon: system_logs data: # The file name must be output.conf output.conf: # ===== Output block ===== ### Add customized fluent-bit output plugin configurations here
- 請記下您指派給
在指令列編輯器中開啟
ObservabilityPipeline
自訂資源:kubectl --kubeconfig=ROOT_ADMIN_CLUSTER_KUBECONFIG -n obs-system edit observabilitypipelines.observability.gdc.goog default
將 ORG_ADMIN_CLUSTER_KUBECONFIG 替換為管理員叢集的 kubeconfig 檔案路徑。
在
ObservabilityPipeline
自訂資源中,將fluentbitConfigMaps
陣列新增至additionalSinks
欄位,做為規格部分的記錄欄位。fluentbitConfigMaps
陣列中的項目必須與您先前在步驟 1 中指派給 ConfigMap 物件的名稱相符。apiVersion: observability.gdc.goog/v1alpha1 kind: ObservabilityPipeline metadata: # Don't change anything in this section ... spec: logging: # This section is for system logs and only needs to be edited if system logs have a custom output. additionalSink: fluentbitConfigMaps: # The name should match the configmap name created in step 1. - "<system logs output configmap name>" # Scheme: []v1.VolumeMount. Add volumeMounts if necessary volumeMounts: - ... - ... # Scheme: []v1.Volume. Add volumes if necessary volumes: - ... - ...
如要將變更套用至
ObservabilityPipeline
自訂資源,請儲存並結束指令列編輯器。
完成這些步驟後,系統就會開始推出變更,並重新啟動 anthos-log-forwarder
DaemonSet。
匯出稽核記錄
請按照下列步驟,將稽核記錄匯出至外部儲存空間:
在
obs-system
命名空間中,使用logmon: audit_logs
標籤建立ConfigMap
物件。在data
區段的output.conf
檔案中,新增額外的輸出設定。語法必須與 Fluent Bit 輸出外掛程式相同。建立
ConfigMap
物件時,請務必符合下列規定:- 請記下您指派給
ConfigMap
物件的名稱,因為這個名稱必須與後續步驟中指定的值相符。 - 在物件的「輸出區塊」部分,新增自訂的 Fluent Bit 輸出外掛程式設定。
下列 YAML 檔案顯示
ConfigMap
物件的範本,說明先前的需求。apiVersion: v1 kind: ConfigMap metadata: # The name should match the configmap name specified in step 3. name: <descriptive configmap name> namespace: obs-system labels: # This label is required and must be audit_logs for audit logs logmon: audit_logs data: # The file name must be output.conf output.conf: | # ===== Output block ===== ### Add a customized fluent-bit output plugin configuration here
- 請記下您指派給
在指令列編輯器中開啟
ObservabilityPipeline
自訂資源:kubectl --kubeconfig=ORG_ADMIN_CLUSTER_KUBECONFIG -n obs-system edit observabilitypipelines.observability.gdc.goog default
將 ORG_ADMIN_CLUSTER_KUBECONFIG 替換為管理員叢集的 kubeconfig 檔案路徑。
在
ObservabilityPipeline
自訂資源中,將fluentbitConfigMaps
陣列新增至additionalSinks
欄位,做為規格部分的記錄欄位。fluentbitConfigMaps
陣列中的項目必須與您先前在步驟 1 中指派給 ConfigMap 物件的名稱相符。apiVersion: observability.gdc.goog/v1alpha1 kind: ObservabilityPipeline metadata: # Don't change anything in this section ... spec: auditLogging: # This section is for audit logs and only needs to be edited if audit logs have a custom output. additionalSink: fluentbitConfigMaps: # The name should match the configmap name created in step 1. - "<audit logs output configmap name>" # Scheme: []v1.VolumeMount. Add volumeMounts if necessary volumeMounts: - ... - ... # Scheme: []v1.Volume. Add volumes if necessary volumes:
如要將變更套用至
ObservabilityPipeline
自訂資源,請儲存並結束指令列編輯器。
完成這些步驟後,系統就會開始推出變更,並重新啟動 anthos-log-forwarder
DaemonSet。