使用 Cloud Shell 运行 gcloud 命令
了解如何在 Cloud Shell 中运行 gcloud CLI 命令。
如需遵循有关此任务的分步指导,请直接在 Cloud Shell Editor 中点击操作演示:
准备工作
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Roles required to select or create a project
- Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
-
Create a project: To create a project, you need the Project Creator
(
roles/resourcemanager.projectCreator), which contains theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
设置 gcloud 属性
- 启动 Cloud Shell Editor。
通过设置核心属性,防止在向终端输出消息时使用颜色:
gcloud config set disable_color true取消设置
disable_color属性:gcloud config unset disable_color如果您已启用 Compute Engine API,请设置首选 Compute Engine 区域。 将
REGION替换为区域名称,例如us-east1:gcloud config set compute/region REGION或者,您也可以设置首选区域。 将
ZONE替换为可用区名称,例如us-east1-b:gcloud config set compute/zone ZONE如需了解 Compute Engine 区域和可用区,请参阅区域和可用区。
显示可用属性的列表:
gcloud topic configurations
运行核心命令
列出其凭据存储在本地系统上的账号:
gcloud auth listgcloud CLI 会显示存储了凭据的账号的列表,其中
ACCOUNT_EMAIL表示一个或多个有效账号的列表:Credentialed Accounts ACTIVE ACCOUNT \*
ACCOUNT_EMAIL列出活跃 gcloud CLI 配置中的属性:
gcloud config listgcloud CLI 会显示类似于以下内容的属性列表,其中
ACCOUNT_EMAIL和PROJECT_ID会显示您的电子邮件地址和项目 ID:[core] account = ACCOUNT_EMAIL disable_usage_reporting = False project = PROJECT_ID
查看有关您的 gcloud CLI 安装和活跃配置的信息:
gcloud info
查看有关 gcloud 命令的帮助
查看有关
gcloud compute instances create命令的帮助:gcloud help compute instances create查看
gcloud topic下的可用命令:gcloud help topic查看有关过滤的信息:
gcloud topic filters详细了解
gcloud命令结构:gcloud topic command-conventions