Ops Agent 会收集实例的遥测数据,供您之后用于问题排查和性能调整。
准备工作
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 Google Cloud 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以选择以下任一选项向 Compute Engine 进行身份验证:
Select the tab for how you plan to use the samples on this page:
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
-
所需的角色
如需获得为 Ops Agent 监控和日志记录创建实例所需的权限,请让管理员向您授予项目的以下 IAM 角色:
-
Compute Instance Admin (v1) (
roles/compute.instanceAdmin.v1
) -
如需在实例上安装 Ops Agent,请执行以下操作:
OSPolicyAssignment Editor (
roles/osconfig.osPolicyAssignmentEditor
)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
为 Ops Agent 监控和日志记录创建实例
您只能使用 Google Cloud 控制台创建仅配置为进行 Ops Agent 监控和日志记录的实例。本部分简要介绍了如何在创建实例时安装 Ops Agent。如需了解详情,另请参阅在创建实例期间安装 Ops Agent。
在 Google Cloud 控制台中,前往创建实例页面。
如果出现提示,请选择您的项目并点击继续。
系统随即会显示创建实例页面,并显示机器配置窗格。
在导航窗格中,点击可观测性。系统随即会显示可观测性窗格。
在 Ops Agent 部分,选中安装用于监控和日志记录的 Ops Agent 复选框。
选中此复选框会在功能受限模式下启用虚拟机管理器,并创建用于在实例上安装 Ops Agent 的操作系统政策分配任务。
可选:指定其他配置选项。如需了解详情,请参阅实例创建期间的配置选项。
要创建并启动该实例,请点击创建。
在现有实例上安装 Ops Agent
您可以使用 Google Cloud 控制台、gcloud CLI 或自动化工具在一组实例或单个实例上安装 Ops Agent。如需了解详细说明,请参阅安装 Ops Agent。