Compute Engine 提供預先定義的機器類型,可供您在建立 VM 執行個體時使用。在預先定義的機器類型中,vCPU 數量和記憶體容量均已預先設定完成,並依據固定價格收費。如果預先定義的 VM 不符合需求,您可以使用自訂的虛擬化硬體設定來建立 VM 執行個體。具體而言就是,您實際上可以使用自訂機器類型建立 VM 執行個體,並自訂該執行個體的 vCPU 數量和記憶體大小。自訂機器類型適用於下列項目:
- 僅適用於 N 和 E 機器系列的一般用途機器家族。C 和 Tau 系列機型不支援自訂機型。您可以在 N4、N2、N2D、E2 或 N1 系列機型上建立自訂 VM。
- 加速器最佳化機器系列,僅適用於 G2 機器系列。
自訂 VM 最適合下列情境:
- 不適合預先定義 VM 類型的工作負載。
- 工作負載需要更多處理效能或記憶體,但不需要新一代機器類型提供的所有升級功能。
- 工作負載的軟體授權費用是依 CPU 計算。自訂 vCPU 數量,避免為未使用的處理能力支付授權費用,或配合可用的軟體授權數量。
事前準備
- 參閱機器系列說明文件。
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 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.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
-
如要為現有 VM 新增擴充記憶體,請按照下列步驟操作:
compute.instances.setMachineType
在 VM 上 -
如要建立採用自訂機型的 VM,請按照下列步驟操作:
- 專案的
compute.instances.create
權限 - 如要使用自訂映像檔建立 VM,請按一下映像檔上的
compute.images.useReadOnly
: - 如要使用快照建立 VM,請按一下快照上的
compute.snapshots.useReadOnly
- 如要使用執行個體範本建立 VM,請按一下執行個體範本上的
compute.instanceTemplates.useReadOnly
- 如要將舊版網路指派給 VM:專案的
compute.networks.use
- 如要為 VM 指定靜態 IP 位址,請在專案中擁有
compute.addresses.use
權限 - 使用舊版網路時,如要將外部 IP 位址指派給 VM,請在專案中設定
compute.networks.useExternalIp
- 為 VM 指定子網路:專案或所選子網路的
compute.subnetworks.use
- 使用虛擬私有雲網路時,如要將外部 IP 位址指派給 VM,請在專案或所選子網路上擁有
compute.subnetworks.useExternalIp
權限 - 如要為專案中的 VM 設定 VM 執行個體中繼資料,請執行下列指令:
compute.instances.setMetadata
- 如要為 VM 設定標記,請在 VM 上按一下
compute.instances.setTags
- 如要為 VM 設定標籤,請在 VM 上執行下列步驟:
compute.instances.setLabels
- 如要設定 VM 使用的服務帳戶,請在 VM 上執行
compute.instances.setServiceAccount
- 如要為 VM 建立新磁碟,請取得專案的
compute.disks.create
權限 - 如要以唯讀或讀寫模式連接現有磁碟,請對磁碟擁有
compute.disks.use
權限 - 如要以唯讀模式連接現有磁碟,請對磁碟擁有
compute.disks.useReadOnly
權限
- 專案的
- 如果 VM 具有本機 SSD 磁碟,您就無法變更 vCPU 和記憶體設定。
- 擴充記憶體適用於 N4、N2、N2D 和 N1 自訂機器類型。預先定義的機器類型,以及 G2 和 E2 自訂機器類型,都不支援擴充記憶體。
- 每個機器類型可新增的記憶體大小有其上限。
- 必須以 256 MB 增量來指定記憶體。
- 擴充記憶體未享有依資源計算的承諾使用折扣 (CUD)。
使用自訂機器類型時,如果每個 vCPU 分配到等於或小於預設容量記憶體,系統會根據機器系列自訂機器類型定價計費。E2 自訂機器和 E2 共用核心自訂機器類型適用相同價格方案。
如果您使用承諾使用合約來執行自訂機型,Compute Engine 會在承諾使用合約的價格上加收 5% 的附加費率。在您執行這些自訂機型 VM 的承諾使用合約期間,Compute Engine 會針對您使用的部分收取此筆附加費率。
前往 Google Cloud 控制台的「Create an instance」(建立執行個體) 頁面。
在「機器設定」窗格中,執行下列操作:
- 選取要代管執行個體的「Region」(區域) 和「Zone」(可用區)。
- 選取「一般用途」或「GPU」。
- 在「系列」清單中,選取機器系列。
- 如為一般用途,請選擇 N4、N2、N2D、E2 或 N1。
- 在「GPU」部分,選擇 G2。
- 在「Machine type」(機器類型) 部分中,選取「Custom」(自訂)。
- 如要指定執行個體的 vCPU 數量和記憶體大小,請拖曳滑桿或在文字方塊中輸入值。當您變更 vCPU 和記憶體的數量時,主控台會顯示執行個體的估計費用。
- 在「系列」清單中,選取機器系列。
視需要指定其他設定選項。詳情請參閱「建立執行個體時的設定選項」。
如要建立並啟動執行個體,請按一下「建立」。
- INSTANCE_NAME:執行個體名稱
- MACHINE_TYPE:機器類型,例如 N2
- NUMBER_OF_VCPUS:vCPU 數量
AMOUNT_OF_MEMORY_MB:記憶體量 (以 MB 或 GB 為單位)
如要在
us-central1-a
區域中建立具有 4 個 vCPU 和 19 GB 記憶體的 G2 VM,請執行下列指令:gcloud compute instances create example-instance \ --zone=us-central1-a --machine-type=g2-custom-4-19456
如果是 G2 VM,記憶體必須是 1024 MB 的倍數,且在支援的記憶體範圍內。 如要進一步瞭解如何建立 G2 VM,請參閱「建立連接 GPU 的 VM」一文。
- INSTANCE_NAME:執行個體名稱
- NUMBER_OF_VCPUS:vCPU 數量
- NUMBER_OF_MB:記憶體量 (以 MB 或 GB 為單位)
- MACHINE_TYPE:機器類型,例如 N2
- INSTANCE_NAME:執行個體名稱
- MACHINE_TYPE:E2 small
- AMOUNT_OF_MEMORY_MB:記憶體量 (以 MB 或 GB 為單位)
- 前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面。
- 點選「建立執行個體」。
- 指定所需參數。
- 按一下頁面頂端或底部的「對等程式碼」,然後點選「Terraform」分頁標籤,即可查看 Terraform 程式碼。
- 如果是 N1 系列機器,請從自訂機器開始。
- 如果是 E2 共用核心,NUMBER_OF_CPUs 為
micro
、small
或medium
。 - 如要啟用擴充記憶體,請在機器類型結尾加上
-ext
。 前往 Google Cloud 控制台的「Create an instance」(建立執行個體) 頁面。
在「機器設定」窗格中,執行下列操作:
- 在「Zone」(可用區) 清單中,選取要代管這個 VM 的可用區。系統會篩選「系列」清單,只顯示所選區域可用的機器類型系列。
- 選取「一般用途」。
- 在「系列」清單中,選取「N4」、「N2」、「N2D」、「N1」,即可建立自訂機器類型。
- 如要指定 vCPU 數量,請拖曳「核心」滑桿,或在欄位中輸入值。
- 如要新增擴充記憶體,請選取「擴充記憶體」。如要指定機器類型的記憶體容量,請拖曳「記憶體」滑桿,或在欄位中輸入值。當您編輯 vCPU 和記憶體的數量時,主控台會顯示 VM 的預估費用。
視需要指定其他設定選項。詳情請參閱「建立執行個體時的設定選項」。
如要建立並啟動 VM,請按一下 [Create] (建立)。
- INSTANCE_NAME:執行個體名稱
- MACHINE_TYPE:機器類型,例如 N2
- NUMBER_OF_VCPUS:vCPU 數量
- AMOUNT_OF_MEMORY_MB:記憶體量 (以 MB 或 GB 為單位)
- 如要將所有自訂機器類型的記憶體擴充至上限,請附加
-ext
,如該特定機器系列所述。 - ZONE:機器位置
- MACHINE_TYPE:機器類型,例如 N2 或 E2 小型
- NUMBER_OF_CPUS:vCPU 數量
- AMOUNT_OF_MEMORY_MB:記憶體量 (以 MB 為單位)
前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面。
從 VM 清單中選擇要修改的已停止 VM。
按一下頁面頂端的「Edit」(編輯)。
在「機器設定」中,選取「一般用途」。
在「Machine type」(機器類型) 部分中,選取「Custom」(自訂)。
選取所需的 vCPU 數量。
如要新增擴充記憶體,請選取「擴充記憶體」,然後指定所需記憶體大小。
儲存變更。
- 進一步瞭解機器系列。
- 建立 VM 後,請逐步完成教學課程,開始使用 VM 執行個體。
- 瞭解如何連線至 VM 執行個體。
Terraform
如要在本機開發環境中使用本頁的 Terraform 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
Go
如要在本機開發環境中使用本頁的 Go 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
Java
如要在本機開發環境中使用本頁的 Java 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
Node.js
如要在本機開發環境中使用本頁的 Node.js 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
PHP
如要在本機開發環境中使用本頁的 PHP 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
Python
如要在本機開發環境中使用本頁的 Python 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。
詳情請參閱 Set up authentication for a local development environment。
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 驗證說明文件中的「Authenticate for using REST」。
必要的角色
如要取得建立自訂機器類型 VM 所需的權限,請要求管理員授予您專案的 Compute 執行個體管理員 (v1) (
roles/compute.instanceAdmin.v1
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。這個預先定義的角色具備使用自訂機器類型建立 VM 所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要建立採用自訂機型的 VM,您必須具備下列權限:
限制
自訂機器類型價格
Google 會根據 VM 使用的 vCPU 數量與記憶體時數,收取自訂 VM 費用。這與預先定義的機器類型計費不同。自訂機型的以量計價價格,會比預先定義機型的以量計價價格多出 5% 的附加費率。
如要查看各機器系列的資訊,請參閱 VM 執行個體定價。
自訂 VM 與其他執行個體同樣皆遵循 1 分鐘最低收費的規範,但自訂機器類型的續用折扣會採不同方式計算。詳情請參閱自訂 VM 的續用折扣。
擴充記憶體定價
對於超出每個 vCPU 預設值的記憶體,Compute Engine 會依據機器系列擴充自訂記憶體定價,收取擴充記憶體費用。擴充記憶體價格與低於預設臨界值的記憶體價格不同。
擴充記憶體價格取決於區域。透過擴充記憶體執行的執行個體,與其他所有執行個體同樣皆遵循 1 分鐘最低收費的規範。擴充記憶體亦享有續用折扣資格。
為機器類型新增擴充記憶體
視機器系列而定,每個機器類型根據預設可擁有一定額度的記憶體。對於某些工作負載來說,這樣的記憶體容量可能不敷使用。您可以額外付費,讓單個 vCPU 取得超出預設限制的記憶體量。這種做法稱為擴充記憶體。
擴充記憶體可讓您為自訂機器類型指定記憶體量,而不受每個 vCPU 的限制。您可以指定擴充記憶體量,最多可達機器系列的限制,而不使用根據指定 vCPU 數量得出的預設記憶體大小。
機器系列 vCPU 限制 記憶體限制 N4 80 640 GB N2 80 864 GB N2D 96 768 GB N1 96 624 GB 如需更多記憶體,請使用記憶體最佳化機器類型。
判斷是否需要擴充記憶體
某些工作負載會需要每個 vCPU 具備超過預設容量的記憶體,方可獲得最佳效果。這類工作負載以記憶體內高效能分析資料庫為基礎,包括關聯式和 NoSQL 資料庫,例如 MS SQL Server、MongoDB 和 MemcacheD/Redis。作業系統和軟體堆疊的授權是以 vCPU 為依據,因此使用預先定義的機器類型時,選取最佳 VM 記憶體設定會更加困難。您可使用擴充記憶體自由新增 VM 需要的記憶體數量,讓 VM 達到最佳價格與效能比。
使用 GB 或 MB 做為記憶體表示單位
對於 Google Cloud 工具和說明文件,機器類型記憶體是以 GB 計算,1 GB 是 230 個位元。這種計算單位又稱為 GiB。將記憶體從 GB 轉換為 MB 時,換算方式為 1 GB = 1024 MB。
在 API 中,提供記憶體時請務必以 MB 為單位。如果您使用 Google Cloud CLI,可以提供 VM 的記憶體總量 (以 GB 或 MB 為單位)。不過,gcloud CLI 要求記憶體值應為整數,因此無法提供浮點數值。例如,若要表示 5.75 GB,請將 5.75 GB 轉換為 MB。在此案例中,5.75 GB 應為 5888 MB。
建立採用自訂機型的 VM
建立自訂 VM 執行個體前,請務必詳閱建立這類機型的自訂規格。主控台
gcloud
使用
gcloud compute instances create
指令搭配--machine-type
選項,建立自訂機器類型。gcloud compute instances create INSTANCE_NAME \ --machine-type=MACHINE_TYPE-custom-NUMBER_OF_VCPUS-AMOUNT_OF_MEMORY_MB
更改下列內容:
以下範例使用 N2 機器類型,在
us-central1-a
區域中具有 48 個 vCPU 和 310 GB 記憶體:gcloud compute instances create example-instance \ --zone=us-central1-a --machine-type=n2-custom-48-317440
對於 N2 等支援的機器系列,您可以設定擴充記憶體,指定高於記憶體與 vCPU 最大比例的記憶體量。如要設定擴充記憶體,請增加
AMOUNT_OF_MEMORY_MB
的值,並在機器類型名稱後方附加-ext
,例如--machine-type=n2-custom-48-720000-ext
。您也可以使用自訂選項指定自訂機器類型:
--custom-cpu
、--custom-memory
、--custom-vm-type
和--custom-extensions
。gcloud compute instances create INSTANCE_NAME \ --custom-cpu=NUMBER_OF_VCPUS \ --custom-memory=NUMBER_OF_MB \ --custom-vm-type=MACHINE_TYPE \ --custom-extension
更改下列內容:
以下範例是使用 Google Cloud CLI 選項的 N2 自訂機器類型,具有 48 個 vCPU 和 310 GB 記憶體。
gcloud compute instances create example-instance \ --custom-cpu=48 --custom-memory=317440 --custom-extension --custom-vm-type=n2
使用
--custom-memory
選項時,請指定記憶體的總和大小 (單位為 GB 或 MB)。該屬性值必須為整數,因此若想指定記憶體增量 0.25 GB,請改用 250 MB。如要使用 E2 共用核心自訂機器類型,請使用相同的
gcloud compute instances create
指令,並加入共用核心機器大小:micro
、small
或medium
。 vCPU 和記憶體受到限制。gcloud compute instances create INSTANCE_NAME\ --machine-type=MACHINE_TYPE-AMOUNT_OF_MEMORY_MB
更改下列內容:
以下範例為 E2 共用核心小型自訂機器類型,具備 0.5 個 vCPU 和 2.25 GB 記憶體。
gcloud compute instances create example-instance \ --machine-type=e2-custom-small-2304
Terraform
如要產生 Terraform 程式碼,可以使用 Google Cloud 控制台中的「對等程式碼」元件。Go
在試用這個範例之前,請先按照Go「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Go API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
在試用這個範例之前,請先按照Java「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Java API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
在試用這個範例之前,請先按照Node.js「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Node.js API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
在試用這個範例之前,請先按照Python「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Python API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
REST
使用
instances.insert
方法,建構執行個體建立要求,並指定自訂machineType
值。請以「MB」為單位來提供記憶體:POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances
要求主體範例
{ "name": "exampleinstance", "machineType": "zones/us-central1-a/machineTypes/n2-custom-16-107520", "disks": [ { "boot": true, "diskSizeGb": 10, "initializeParams": { "sourceImage": "projects/debian-cloud/global/images/family/debian-11" } } ], "networkInterfaces": [ { "network": "global/networks/default" } ] } ```
在建立執行個體時新增擴充記憶體
如要透過擴充記憶體建立 VM 執行個體,請按照以下操作說明進行。主控台
gcloud
使用
gcloud compute instances create
指令搭配--machine-type
選項,建立自訂機器。gcloud compute instances create INSTANCE_NAME\ --machine-type=MACHINE_TYPE-custom-NUMBER_OF_VCPUS-AMOUNT_OF_MEMORY_MB
更改下列內容:
以下範例使用 N2 機器類型,在
us-central1-a
區域中具有 48 個 vCPU 和 310 GB 記憶體:gcloud compute instances create example-instance \ --zone=us-central1-a --machine-type=n2-custom-48-317440
Go
在試用這個範例之前,請先按照Go「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Go API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
在試用這個範例之前,請先按照Java「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Java API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
在試用這個範例之前,請先按照Node.js「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Node.js API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
在試用這個範例之前,請先按照Python「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Python API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
REST
使用
instances.insert
方法,建構執行個體建立要求,就像建立具有自訂記憶體的執行個體一樣。指定machineType
值時,請加入-ext
,表示擴充記憶體:zones/ZONE/machineTypes//MACHINE_TYPE-NUMBER_OF_CPUS-AMOUNT_OF_MEMORY-ext
更改下列內容:
例如,下列指令所指定的是具有 2 個 vCPU 和 20 GB 記憶體的 N2 機器類型,請注意,您必須將記憶體轉換為 MB:
zones/ZONE/machineTypes/n2-custom-2-20480-ext
為現有 VM 執行個體新增擴充記憶體
如要為使用自訂機型的現有執行個體新增更多記憶體,請先停止執行個體。 執行個體停止後,請完成下列步驟,為 VM 新增更多記憶體。主控台
gcloud
使用
gcloud compute instances stop
指令停止 VM。然後使用gcloud compute instances set-machine-type
指令搭配--custom-memory
和--custom-extensions
選項,編輯機器的資源。儲存變更並重新啟動 VM。
Go
在試用這個範例之前,請先按照Go「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Go API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Java
在試用這個範例之前,請先按照Java「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Java API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Node.js
在試用這個範例之前,請先按照Node.js「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Node.js API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
Python
在試用這個範例之前,請先按照Python「使用用戶端程式庫的 Compute Engine 快速入門」中的操作說明進行設定。詳情請參閱 Compute Engine Python API 參考說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。 詳情請參閱「為本機開發環境設定驗證」。
REST
使用
instances.stop
方法,然後使用instances.setMachineType
方法編輯機器類型資源。停止執行個體後,編輯
machineTypes
選項並進行變更。{
"name": "INSTANCE_NAME", "machineType": "zones/ZONE/machineTypes/MACHINE_TYPE",
... }
更改下列內容:
+ INSTANCE_NAME: The name of the VM + ZONE: The zone where your VMs reside + MACHINE_TYPE: The name of the VM
後續步驟
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-09 (世界標準時間)。
-