本文說明如何查看現有虛擬機器 (VM) 執行個體的詳細資料。
查看 VM 詳細資料可讓您瞭解其設定和狀態,例如已連結的磁碟、建立時間戳記、機器類型和 VM ID。您可以使用這個 ID 透過不可變的值參照 VM。
事前準備
-
如果尚未設定,請先設定驗證機制。「驗證」是指驗證身分,以便存取 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.
前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面。
在「VM 執行個體」頁面中,您可以查看運算執行個體的下列資訊:
上方清單包含「VM instances」頁面上顯示的預設欄。您可以按一下
「資料欄顯示選項」,變更每個 VM 顯示的資料欄。在「Name」欄中,按一下 VM 名稱,查看 VM 執行個體的其他詳細資料。
VM_NAME
:VM 名稱。ZONE
:VM 所在區域。PROJECT_ID
:VM 所在專案的 ID。ZONE
:VM 所在區域。VM_NAME
:VM 名稱。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 為單位)。瞭解如何重新命名 VM。
瞭解如何停止或啟動 VM。
瞭解如何暫停或繼續執行 VM。
進一步瞭解虛擬機器生命週期。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
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.
詳情請參閱 Google Cloud 驗證說明文件中的「驗證以使用 REST」。
必要的角色
如要取得查看 VM 詳細資料所需的權限,請要求管理員為您授予 VM 或專案的 Compute Instance 管理員 (v1) (
roles/compute.instanceAdmin.v1
) 身分與存取權管理角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。這個預先定義的角色包含
compute.instances.get
權限,這是查看 VM 詳細資料所需的權限。查看 VM 詳細資料
如要查看 VM 的詳細資料,請選取下列任一選項:
主控台
gcloud
如要查看 VM 的詳細資料,請使用
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
如要查看 VM 的詳細資料,請對
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 和記憶體,例如:
如要進一步瞭解機器類型,請參閱機器家族資源與比較指南。
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-06-16 (世界標準時間)。
-