按照本部分中的说明设置 Central 日志服务器。
设置存储桶
创建新的存储桶以存储设备日志:
gcloud storage buckets create gs://BUCKET_NAME
启用 IAM API(如果尚未启用):
gcloud services enable iam.googleapis.com
创建用于访问存储桶的服务账号:
gcloud iam service-accounts create GSA_NAME --description="DESCRIPTION" --display-name="DISPLAY_NAME"
将数据从 GDC 转移到存储桶
转移数据,将数据导出到存储分区。
将 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 的 GKE 工作负载身份联合配置对 Cloud Storage 存储分区的访问权限。在第 5 步中设置 IAM 政策绑定时,选择
roles/storage.objectAdmin
。按照 https://cloud.google.com/artifact-registry/docs/repositories/remote-repo 中的说明创建一个 Artifact Registry 远程代码库,该代码库将充当 Dockerhub 的代理,后者是包含 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 界面
通过在计算机与 Kubernetes 集群中的 Grafana 服务之间设置端口转发来访问 Grafana 界面:
kubectl port-forward service/GRAFANA_APP_NAME
-n NAMESPACE 3000:3000
运行上述命令后,您就可以访问 Grafana 界面了。如果您需要向组织中的多位用户公开 Grafana 界面,请考虑设置 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
对象分配的名称,因为该名称必须与后续步骤中指定的值一致。 - 在对象的 Output block 部分中添加自定义的 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
对象分配的名称,因为该名称必须与后续步骤中指定的值一致。 - 在对象的 Output block 部分中添加自定义的 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。