使用本文档验证虚拟机管理器已正确设置。如需了解如何设置虚拟机管理器,请参阅设置虚拟机管理器。
要验证设置,您可以使用问题排查命令或对虚拟机实例执行手动检查。
准备工作
- 对于 Windows 虚拟机,请使用 PowerShell 3.0 或更高版本。
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 Trusted Cloud by S3NS 服务和 API 的过程。如需从本地开发环境运行代码或示例,您可以通过选择以下选项之一向 Compute Engine 进行身份验证:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, sign in to the gcloud CLI with your federated identity and then initialize it by running the following command:
gcloud init
- Set a default region and zone.
VM_NAME
:要进行问题排查的虚拟机实例的名称ZONE
:实例所在的可用区- 示例 1:显示虚拟机实例设置有问题时
os-config troubleshoot
命令的输出 示例 2:显示虚拟机实例设置正确时
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
的虚拟机实例进行问题排查,请运行以下命令: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
的虚拟机实例进行问题排查,请运行以下命令: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.
手动验证
如需手动验证虚拟机管理器已正确设置,请完成以下检查:
如果虚拟机管理器设置正确,但问题仍然存在,请参阅排查虚拟机管理器问题。
检查 OS Config API 是否已启用
在您的 Trusted Cloud 项目中,检查该 API 是否已启用。
控制台
在 Trusted Cloud 控制台中,前往 OS Config API 页面。
gcloud
gcloud services list --enabled
如果启用了 API,输出将如下所示:
osconfig.googleapis.com OS Config API
如果未启用 API,请启用 OS Config API。
检查元数据是否已启用
Linux
对于项目元数据,请在虚拟机上完成以下步骤:
如果元数据未启用,请启用 OS Config 元数据。
Windows
对于项目元数据,请在虚拟机上以管理员身份打开 PowerShell 终端并运行以下命令:
如果元数据未启用,请启用 OS Config 元数据。
检查 OS Config 代理是否已安装并运行
Linux
如需检查您的 Linux 虚拟机是否安装了该代理,请运行以下命令:
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 Config 代理,请安装该代理。
Windows
如需检查您的 Windows 虚拟机是否安装了代理,请运行以下命令:
PowerShell Get-Service google_osconfig_agent
如果代理已安装且正在运行,则会输出如下内容:
Status Name DisplayName ------ ---- ----------- Running google_osconfig... Google OSConfig Agent
如果尚未安装 OS Config 代理,请安装该代理。
检查服务账号是否已启用
如需了解服务账号要求,请参阅设置概览。
Linux
在虚拟机上,运行以下命令:
curl "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/" \ -H "Metadata-Flavor: Google"
输出应至少包含默认服务账号。
default/
Windows
在虚拟机上,以管理员身份打开 PowerShell 终端并运行以下命令:
$value = (Invoke-RestMethod ` -Headers @{'Metadata-Flavor' = 'Google'} ` -Uri "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/") $value
输出应至少包含默认服务账号。
default/
检查虚拟机是否可以与 OS Config API 通信
如需检查虚拟机是否可以与 OS Config API 通信,请在 Linux 或 Windows 虚拟机上运行以下命令:
ping osconfig.googleapis.com
如需停止 ping OS Config API,请按 Control + C。
如果您的虚拟机在专用 VPC 网络中运行,并且没有公共互联网访问权限,请检查是否已启用专用 Google 访问通道。
启用专用 Google 访问通道后,检查虚拟机是否可以与 OS Config API 通信。
Linux
在虚拟机上,运行以下命令:
curl --ssl 'https://osconfig.googleapis.com/$discovery/rest' | head
如果虚拟机可以与 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
在虚拟机上,以管理员身份打开 PowerShell 终端并运行以下命令:
Invoke-RestMethod -Headers @{'Metadata-Flavor' = 'Google'} -Uri 'https://osconfig.googleapis.com/$discovery/rest'
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-08。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-07-08。"],[[["This document provides methods to verify that VM Manager is properly set up, including using the `os-config troubleshoot` command or performing manual checks on the VM instance."],["Before using the verification methods, you may need to set up authentication, and for Windows VMs, PowerShell 3.0 or later is required."],["The `os-config troubleshoot` command is used with a specific VM name and zone to check for setup issues, and if any problems are detected, feedback is provided on how to resolve them."],["Manual verification involves checking if the OS Config API is enabled, OS Config metadata is enabled, the OS Config agent is installed and running, the service account is enabled, and the VM can communicate with the OS Config API."],["If VM Manager is correctly set up but issues still arise, further troubleshooting steps are available in the linked \"Troubleshooting VM Manager\" document."]]],[]] -