本页面介绍了如何为您的 Trusted Cloud 控制台项目设置默认区域或可用区。
向 Compute Engine 发出请求时,您可能需要根据请求的特定要求提供区域或地区。任何涉及区域资源的请求均需要提供区域名称;任何涉及可用区资源的请求均需要提供可用区名称。例如,创建静态外部 IP 地址时必须指定区域,而创建虚拟机实例时必须指定可用区。
创建项目时,Compute Engine 会根据您创建项目的位置自动选择默认区域和地区。Compute Engine 会尝试选择靠近项目创建位置的区域和地区,这样,您创建的资源到达客户或客户端的延迟时间就会缩短。如果您要在其他区域或地区创建资源,则可以替换默认选项。
如需详细了解区域和地区,请参阅区域和地区。
如需详细了解 Compute Engine 的全球、区域和地区性资源,请参阅全球、区域和地区性资源。
准备工作
-
如果您尚未设置身份验证,请进行设置。身份验证是通过其进行身份验证以访问 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.
google-compute-default-region
google-compute-default-zone
在 Trusted Cloud 控制台中,前往设置页面。
从区域下拉菜单中选择默认区域。
从地区下拉菜单中选择默认地区。
点击保存。
- 详细了解区域和地区。
- 详细了解全球、区域和可用区资源
默认区域和地区对您的项目的影响
默认区域和可用区设置仅会影响 Google Cloud CLI 和 Trusted Cloud 控制台等客户端工具。当您使用这些工具构建请求时,这些工具会自动选择默认区域和地区以帮助您管理资源。
当您使用 Trusted Cloud 控制台创建区域级或可用区级资源(例如地址或实例)时,Compute Engine 会为您设置区域和可用区字段。您可以接受预先填充的值,也可以明确更改其中一个或这两个值。
当您使用 gcloud CLI 时,可以忽略设置
--region
和--zone
标志以使用新项目的默认区域和可用区属性。您可以随时更改元数据服务器中的默认区域和可用区设置、在本地替换 gcloud CLI 的默认区域和可用区,或者使用 gcloud CLI 或 Trusted Cloud 控制台手动替换每个请求的设置。
查找默认区域或地区
元数据服务器包含项目的相关元数据信息,例如项目 ID 和项目名称。您可以查询元数据服务器来获取和使用项目相关信息。
如果为项目指定默认区域和地区,则 Compute Engine 会在元数据服务器中为项目设置这些值。
使用以下值设置默认地区和区域:
如需查看您的默认区域和地区设置,请运行以下
gcloud
命令,并将PROJECT_ID
替换为您的项目 ID:gcloud compute project-info describe --project PROJECT_ID
在响应中查找默认区域和地区的元数据值。如果响应中缺少
google-compute-default-region
和google-compute-default-zone
键及其值,则表示未设置默认区域或地区。更改默认区域或地区
系统不限制为默认属性设置哪些区域或可用区。例如,您可以在您的默认区域之外设置默认地区。创建和管理资源时,请检查默认区域和可用区设置。
控制台
如需更改默认区域或可用区,请按照以下步骤操作:
gcloud
您可以向元数据服务器发出请求来更改默认区域和可用区。例如:
gcloud compute project-info add-metadata \ --metadata google-compute-default-region=europe-west1,google-compute-default-zone=europe-west1-b
使用任何方法更新默认元数据后,运行
gcloud init
命令来重新初始化default
配置。只有运行gcloud init
命令后,gcloud CLI 才会刷新默认区域和可用区设置。如需详细了解如何使用 gcloud CLI 选项设置默认区域和可用区,请参阅设置默认属性。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-24。
[[["易于理解","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-24。"],[[["\u003cp\u003eThis page explains how to set and manage default regions and zones for your Google Cloud project, which are necessary for creating regional and zonal resources like static IP addresses and virtual machine instances.\u003c/p\u003e\n"],["\u003cp\u003eCompute Engine automatically selects a default region and zone based on the project's origin, but users can override these defaults to create resources in different locations, to reduce latency.\u003c/p\u003e\n"],["\u003cp\u003eDefault region and zone settings affect client tools like the Google Cloud CLI and Google Cloud console by automatically pre-populating these values when creating resources, but can be manually changed or overridden.\u003c/p\u003e\n"],["\u003cp\u003eYou can check your current default region and zone settings by querying the metadata server using the \u003ccode\u003egcloud compute project-info describe\u003c/code\u003e command, which will list \u003ccode\u003egoogle-compute-default-region\u003c/code\u003e and \u003ccode\u003egoogle-compute-default-zone\u003c/code\u003e if they are set.\u003c/p\u003e\n"],["\u003cp\u003eThe default region and zone can be modified either through the Google Cloud console settings page, or by using the \u003ccode\u003egcloud compute project-info add-metadata\u003c/code\u003e command to update the metadata server, followed by the \u003ccode\u003egcloud init\u003c/code\u003e command to refresh the local configuration.\u003c/p\u003e\n"]]],[],null,[]] -