請參閱本文,確認 VM 管理工具設定正確無誤。 如要瞭解如何設定 VM 管理員,請參閱「設定 VM 管理員」。
如要驗證設定,您可以使用疑難排解指令,或對虛擬機器 (VM) 執行個體執行手動檢查。
事前準備
- 如為 Windows VM,請使用 PowerShell 3.0 以上版本。
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 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.
VM_NAME
:要排解疑難的 VM 執行個體名稱ZONE
:執行個體所在的區域- 範例 1:顯示 VM 執行個體設定有問題時,
os-config troubleshoot
指令的輸出內容 範例 2:顯示 VM 執行個體設定正確時,
os-config troubleshoot
指令的輸出內容查詢專案屬性端點:
curl "http://metadata.google.internal/computeMetadata/v1/project/attributes/" \ -H "Metadata-Flavor: Google"
如果已設定代理程式中繼資料值,輸出內容會類似於下列內容:
enable-osconfig
如果顯示
enable-osconfig
值,請查詢端點:curl "http://metadata.google.internal/computeMetadata/v1/project/attributes/enable-osconfig" \ -H "Metadata-Flavor: Google"
如果啟用,端點會傳回
TRUE
。查詢專案屬性端點:
$value = (Invoke-RestMethod ` -Headers @{'Metadata-Flavor' = 'Google'} ` -Uri "http://metadata.google.internal/computeMetadata/v1/project/attributes/") $value
如果已設定代理程式中繼資料值,輸出內容會類似於下列內容:
enable-osconfig
如果顯示
enable-osconfig
值,請查詢端點:$value = (Invoke-RestMethod ` -Headers @{'Metadata-Flavor' = 'Google'} ` -Uri "http://metadata.google.internal/computeMetadata/v1/project/attributes/enable-osconfig") $value
如果啟用,端點會傳回
TRUE
。
使用疑難排解指令
使用
os-config troubleshoot
指令驗證設定。如檢查未通過,系統會提供意見回饋,說明如何修正問題。gcloud compute os-config troubleshoot VM_NAME \ --zone=ZONE
更改下列內容:
範例
範例 1
如要排解可用區
asia-east2-b
中名為my-instance-1
的 VM 執行個體問題,請執行下列指令:gcloud compute os-config troubleshoot my-instance-1 \ --zone=asia-east2-b
輸出結果會與下列內容相似:
OS Config troubleshooter tool is checking if there are issues with the VM Manager setup for this VM instance. > Is the OS Config API enabled? Yes > Is the OS Config agent enabled? Yes > Is the OS Config agent up to date? No The version of OS Config agent running on this VM instance is not the latest version. See https://cloud.google.com/compute/docs/manage-os/upgrade-vm-manager#update-agent on how to update the agent.
範例 2
如要排解可用區
us-west1-b
中名為my-instance-2
的 VM 執行個體問題,請執行下列指令:gcloud compute os-config troubleshoot my-instance-2 \ --zone=us-west1-b
輸出結果會與下列內容相似:
OS Config troubleshooter tool is checking if there are issues with the VM Manager setup for this VM instance. > Is the OS Config API enabled? Yes > Is the OS Config agent enabled? Yes > Is the OS Config agent up to date? Yes > Is a service account present on the instance? Yes > Is the OS Config Service account present for this instance? Yes > Does this instance have a public IP or Private Google Access? Yes This instance has a public IP.
手動驗證
如要手動驗證 VM 管理員設定是否正確,請完成下列檢查:
如果 VM 管理員設定正確,但仍有問題,請參閱「排解 VM 管理員問題」。
檢查 OS Config API 是否已啟用
在 Google Cloud 專案中,檢查 API 是否已啟用。
主控台
前往 Google Cloud 控制台的「OS Config API」頁面。
gcloud
gcloud services list --enabled
如果已啟用 API,輸出內容會類似以下內容:
osconfig.googleapis.com OS Config API
如果 API 未啟用,請啟用 OS Config API。
檢查中繼資料是否已啟用
Linux
如要取得專案中繼資料,請在 VM 上完成下列步驟:
如果中繼資料未啟用,請啟用 OS 設定中繼資料。
Windows
如要取得專案中繼資料,請在 VM 中以管理員身分開啟 PowerShell 終端機,然後執行下列指令:
如果中繼資料未啟用,請啟用 OS 設定中繼資料。
檢查 OS 設定代理程式是否已安裝並正在執行
Linux
如要檢查 Linux VM 是否已安裝代理程式,請執行下列指令:
sudo systemctl status google-osconfig-agent
如果代理程式已安裝並正在執行,輸出結果會類似以下內容:
google-osconfig-agent.service - Google OSConfig Agent Loaded: loaded (/lib/systemd/system/google-osconfig-agent.service; enabled; vendor preset: Active: active (running) since Wed 2020-01-15 00:14:22 UTC; 6min ago Main PID: 369 (google_osconfig) Tasks: 8 (limit: 4374) Memory: 102.7M CGroup: /system.slice/google-osconfig-agent.service └─369 /usr/bin/google_osconfig_agent
如果尚未安裝代理程式,請安裝 OS 設定代理程式。
Windows
如要檢查 Windows VM 是否已安裝代理程式,請執行下列指令:
PowerShell Get-Service google_osconfig_agent
如果代理程式已安裝並正在執行,輸出結果會類似以下內容:
Status Name DisplayName ------ ---- ----------- Running google_osconfig... Google OSConfig Agent
如果尚未安裝代理程式,請安裝 OS 設定代理程式。
檢查服務帳戶是否已啟用
如要瞭解服務帳戶需求,請參閱設定總覽。
Linux
在 VM 上執行下列指令:
curl "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/" \ -H "Metadata-Flavor: Google"
輸出內容至少應包含預設服務帳戶。
default/
Windows
在 VM 中,以系統管理員身分開啟 PowerShell 終端機,然後執行下列指令:
$value = (Invoke-RestMethod ` -Headers @{'Metadata-Flavor' = 'Google'} ` -Uri "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/") $value
輸出內容至少應包含預設服務帳戶。
default/
檢查 VM 是否可與 OS Config API 通訊
如要檢查 VM 是否可與 OS Config API 通訊,請在 Linux 或 Windows VM 上執行下列指令:
ping osconfig.googleapis.com
如要停止對 OS Config API 執行 Ping 作業,請按下 Control + C。
如果 VM 是在私人虛擬私有雲網路中運作,且沒有公開網際網路存取權,請確認您已啟用 Private Google Access。
啟用私人 Google 存取權後,請檢查 VM 是否可與 OS Config API 通訊。
Linux
在 VM 上執行下列指令:
curl --ssl 'https://osconfig.googleapis.com/$discovery/rest' | head
如果 VM 可以與 OS Config API 通訊,指令輸出內容會類似於下列內容:
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0{ "discoveryVersion": "v1", "baseUrl": "https://osconfig.googleapis.com/", "ownerName": "Google", "version": "v1beta", "schemas": { "GooSettings": { "description": "Googet patching is performed by running `googet update`.", "properties": {}, "id": "GooSettings", 100 9569 0 9569 0 0 198k 0 --:--:-- --:--:-- --:--:-- 198k
Windows
在 VM 中,以管理員身分開啟 PowerShell 終端機,然後執行下列指令:
Invoke-RestMethod -Headers @{'Metadata-Flavor' = 'Google'} -Uri 'https://osconfig.googleapis.com/$discovery/rest'
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-21 (世界標準時間)。
-