本文說明如何查看現有虛擬機器 (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.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the 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.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
必要的角色
如要取得查看 VM 詳細資料所需的權限,請要求管理員為您授予 VM 或專案的 Compute Instance 管理員 (v1) (roles/compute.instanceAdmin.v1
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
這個預先定義的角色包含 compute.instances.get
權限,這是查看 VM 詳細資料所需的權限。
查看 VM 詳細資料
如要查看 VM 的詳細資料,請選取下列任一選項:
主控台
gcloud
如要查看 VM 的詳細資料,請使用 gcloud compute instances describe
指令。
gcloud compute instances describe VM_NAME \
--zone=ZONE
更改下列內容:
VM_NAME
:VM 名稱。ZONE
:VM 所在區域。
輸出結果會與下列內容相似:
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
更改下列內容:
PROJECT_ID
:VM 所在專案的 ID。ZONE
:VM 所在區域。VM_NAME
:VM 名稱。
輸出結果會與下列內容相似:
{
"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 和記憶體,例如:
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。
進一步瞭解虛擬機器生命週期。