作業套件代理程式會收集執行個體的遙測資料,供您進行疑難排解和效能調整。
事前準備
-
如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 Google Cloud 服務和 API 的程序。如要在本機開發環境中執行程式碼或範例,您可以選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
必要的角色
如要取得建立 Ops Agent 監控和記錄作業所需的權限,請要求管理員授予您專案的下列 IAM 角色:
-
Compute 執行個體管理員 (v1) (
roles/compute.instanceAdmin.v1
) -
如要在執行個體上安裝作業套件代理程式,請按照下列步驟操作:
OSPolicyAssignment 編輯器 (
roles/osconfig.osPolicyAssignmentEditor
)
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
建立作業套件代理程式監控和記錄的執行個體
您只能使用 Google Cloud 控制台,建立為 Ops Agent 監控和記錄而設定的執行個體。本節將簡要說明如何在建立執行個體時安裝 Ops Agent。如需更多資訊,請參閱「在建立執行個體時安裝 Ops Agent」。
前往 Google Cloud 控制台的「Create an instance」(建立執行個體) 頁面。
前往「Create an instance」(建立執行個體)
如果出現系統提示,請選取您的專案,然後按一下 [Continue] (繼續)。
系統隨即會顯示「Create an instance」(建立執行個體) 頁面,並顯示「Machine configuration」(機器設定) 窗格。
在導覽窗格中,按一下「可觀察性」。系統會顯示「可觀察性」窗格。
在「Ops Agent」專區中,勾選「Install Ops Agent for Monitoring and Logging」核取方塊。
選取這個核取方塊可在受限功能模式中啟用 VM 管理員,並建立 OS 政策指派,以便在執行個體上安裝 Ops Agent。
選用:指定其他設定選項。詳情請參閱「建立執行個體時的設定選項」。
如要建立並啟動執行個體,請按一下「建立」。
在現有執行個體上安裝作業套件代理程式
您可以使用 Google Cloud 控制台、gcloud CLI 或自動化工具,在整個執行個體群組或個別執行個體上安裝作業套件代理程式。如需詳細操作說明,請參閱「安裝 Ops Agent」。