本文档介绍如何查看现有虚拟机 (VM) 实例的详细信息。
查看虚拟机的详细信息有助于查看其配置和状态,例如挂接的磁盘、创建时间戳、机器类型和虚拟机 ID(可用于使用不可变值引用虚拟机)。
准备工作
-
设置身份验证(如果尚未设置)。身份验证是通过其进行身份验证以访问 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
-
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
- Set a default region and zone.
VM_NAME
:虚拟机名称。ZONE
:该虚拟机所在的可用区。PROJECT_ID
:虚拟机所在项目的 ID。ZONE
:该虚拟机所在的可用区。VM_NAME
:虚拟机名称。c3-standard-22
:C3 是机器系列名称,standard
是实例的内存分配类型,22
是分配给实例的 vCPU 数量。通常,standard
机器类型使用每个 vCPU 4 GB 内存的比率。因此,此机器类型会配备 88 GB 的 RAM。standard
、highmem
、highcpu
、ultamem
和megamem
机器类型的内存与 CPU 比率因机器系列而略有不同,因此请参阅机器系列页面,以确定为每种机器类型分配的确切内存量。n2-custom-8-16384
:对于自定义机器类型,机器类型的第一部分是机器系列,但 N1 机器类型除外,该机器类型根本不包含机器系列。custom
后面的第一个数字是 vCPU 数量,最后一个数字是分配给实例的内存量(以 MB 为单位)。
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
所需的角色
如需获得查看虚拟机详细信息所需的权限,请让管理员向您授予虚拟机或项目的 Compute Instance Admin (v1) (
roles/compute.instanceAdmin.v1
) IAM 角色。如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。此预定义角色可提供查看虚拟机的详细信息所需的
compute.instances.get
权限。查看虚拟机的详细信息
如需查看虚拟机的详细信息,请选择以下选项之一:
控制台
gcloud
如需查看虚拟机的详细信息,请使用
gcloud compute instances describe
命令。gcloud compute instances describe VM_NAME \ --zone=ZONE
请替换以下内容:
输出类似于以下内容:
canIpForward: false confidentialInstanceConfig: enableConfidentialCompute: false cpuPlatform: Intel Broadwell creationTimestamp: '2023-08-18T10:00:21.801-07:00' deletionProtection: false description: '' disks: - architecture: X86_64 autoDelete: true boot: true deviceName: example-vm diskSizeGb: '10' guestOsFeatures: - type: UEFI_COMPATIBLE - type: VIRTIO_SCSI_MULTIQUEUE - type: GVNIC - type: SEV_CAPABLE index: 0 interface: SCSI kind: compute#attachedDisk licenses: - https://www.googleapis.com/compute/v1/projects/debian-cloud/global/licenses/debian-11-bullseye mode: READ_WRITE source: https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/disks/example-vm type: PERSISTENT displayDevice: enableDisplay: false fingerprint: CQp-QBEACqw= id: '6404261768674286922' keyRevocationActionType: NONE kind: compute#instance labelFingerprint: 42WmSpB8rSM= lastStartTimestamp: '2023-08-18T10:00:28.182-07:00' machineType: https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/machineTypes/e2-medium metadata: fingerprint: lQ-dD2sMrMY= items: - key: enable-oslogin value: 'true' kind: compute#metadata name: example-vm networkInterfaces: - accessConfigs: - kind: compute#accessConfig name: External NAT natIP: 34.27.53.198 networkTier: PREMIUM type: ONE_TO_ONE_NAT fingerprint: QR3z6TgVFjg= kind: compute#networkInterface name: nic0 network: https://www.googleapis.com/compute/v1/projects/example-project/global/networks/default networkIP: 10.128.0.28 stackType: IPV4_ONLY subnetwork: https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/subnetworks/default reservationAffinity: consumeReservationType: ANY_RESERVATION scheduling: automaticRestart: true onHostMaintenance: MIGRATE preemptible: false provisioningModel: STANDARD selfLink: https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instances/example-vm serviceAccounts: - email: 790569220780-compute@developer.gserviceaccount.com scopes: - https://www.googleapis.com/auth/devstorage.read_only - https://www.googleapis.com/auth/logging.write - https://www.googleapis.com/auth/monitoring.write - https://www.googleapis.com/auth/servicecontrol - https://www.googleapis.com/auth/service.management.readonly - https://www.googleapis.com/auth/trace.append shieldedInstanceConfig: enableIntegrityMonitoring: true enableSecureBoot: false enableVtpm: true shieldedInstanceIntegrityPolicy: updateAutoLearnPolicy: true startRestricted: false status: RUNNING tags: fingerprint: 42WmSpB8rSM= zone: https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a
REST
如需查看虚拟机的详细信息,请向
instances.get
方法发出GET
请求。GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/VM_NAME
替换以下内容:
输出类似于以下内容:
{ "canIpForward": false, "confidentialInstanceConfig": { "enableConfidentialCompute": false }, "cpuPlatform": "Intel Broadwell", "creationTimestamp": "2023-08-18T10:00:21.801-07:00", "deletionProtection": false, "description": "", "disks": [ { "architecture": "X86_64", "autoDelete": true, "boot": true, "deviceName": "example-vm", "diskSizeGb": "10", "guestOsFeatures": [ { "type": "UEFI_COMPATIBLE" }, { "type": "VIRTIO_SCSI_MULTIQUEUE" }, { "type": "GVNIC" }, { "type": "SEV_CAPABLE" } ], "index": 0, "interface": "SCSI", "kind": "compute#attachedDisk", "licenses": [ "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/licenses/debian-11-bullseye" ], "mode": "READ_WRITE", "source": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/disks/example-vm", "type": "PERSISTENT" } ], "displayDevice": { "enableDisplay": false }, "fingerprint": "CQp-QBEACqw=", "id": "6404261768674286922", "keyRevocationActionType": "NONE", "kind": "compute#instance", "labelFingerprint": "42WmSpB8rSM=", "lastStartTimestamp": "2023-08-18T10:00:28.182-07:00", "machineType": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/machineTypes/e2-medium", "metadata": { "fingerprint": "lQ-dD2sMrMY=", "items": [ { "key": "enable-oslogin", "value": "true" } ], "kind": "compute#metadata" }, "name": "example-vm", "networkInterfaces": [ { "accessConfigs": [ { "kind": "compute#accessConfig", "name": "External NAT", "natIP": "34.27.53.198", "networkTier": "PREMIUM", "type": "ONE_TO_ONE_NAT" } ], "fingerprint": "QR3z6TgVFjg=", "kind": "compute#networkInterface", "name": "nic0", "network": "https://www.googleapis.com/compute/v1/projects/example-project/global/networks/default", "networkIP": "10.128.0.28", "stackType": "IPV4_ONLY", "subnetwork": "https://www.googleapis.com/compute/v1/projects/example-project/regions/us-central1/subnetworks/default" } ], "reservationAffinity": { "consumeReservationType": "ANY_RESERVATION" }, "scheduling": { "automaticRestart": true, "onHostMaintenance": "MIGRATE", "preemptible": false, "provisioningModel": "STANDARD" }, "selfLink": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a/instances/example-vm", "serviceAccounts": [ { "email": "790569220780-compute@developer.gserviceaccount.com", "scopes": [ "https://www.googleapis.com/auth/devstorage.read_only", "https://www.googleapis.com/auth/logging.write", "https://www.googleapis.com/auth/monitoring.write", "https://www.googleapis.com/auth/servicecontrol", "https://www.googleapis.com/auth/service.management.readonly", "https://www.googleapis.com/auth/trace.append" ] } ], "shieldedInstanceConfig": { "enableIntegrityMonitoring": true, "enableSecureBoot": false, "enableVtpm": true }, "shieldedInstanceIntegrityPolicy": { "updateAutoLearnPolicy": true }, "startRestricted": false, "status": "RUNNING", "tags": { "fingerprint": "42WmSpB8rSM=" }, "zone": "https://www.googleapis.com/compute/v1/projects/example-project/zones/us-central1-a" }
确定实例的 CPU 和内存分配
可以根据计算实例使用的机器类型确定分配给计算实例的 CPU 数量和内存量,例如:
如需详细了解机器类型,请参阅机器家族资源和比较指南。
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-12-24。
-