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.
Terraform
To use the Terraform samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- 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.
For more information, see Set up authentication for a local development environment.
Go
To use the Go samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- 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.
For more information, see Set up authentication for a local development environment.
Java
To use the Java samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- 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.
For more information, see Set up authentication for a local development environment.
Node.js
To use the Node.js samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- 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.
For more information, see Set up authentication for a local development environment.
PHP
To use the PHP samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- 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.
For more information, see Set up authentication for a local development environment.
Python
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- 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.
For more information, see Set up authentication for a local development environment.
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 所需的權限,請要求管理員為您授予專案的 Compute Instance Admin (v1) (roles/compute.instanceAdmin.v1
) IAM 角色。如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
這個預先定義的角色包含使用自訂機器類型建立 VM 所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要使用自訂機器類型建立 VM,必須具備下列權限:
-
如要為現有 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:
compute.instances.setMetadata
設定 VM 執行個體中繼資料 - 如何為 VM 設定標記:
compute.instances.setTags
- 如何為 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)資格。
自訂機器類型價格
Google 會根據 VM 使用的 vCPU 數量和記憶體時數,收取自訂 VM 費用。這與預先定義的機器類型計費不同。自訂機型的以量計價價格,會比預先定義機型的以量計價價格多出 5% 的附加費率。
使用自訂機器類型時,如果每個 vCPU 分配到等於或小於預設容量記憶體,系統會根據機器系列自訂機器類型定價來計費。E2 自訂機器類型與 E2 共用核心自訂機器類型採用相同的定價方案。
如果您使用承諾使用合約來執行自訂機型,Compute Engine 會在承諾使用合約的價格上加收 5% 的附加費率。在您執行這些自訂機器類型 VM 的承諾使用合約期間,Compute Engine 會針對您使用的部分收取此筆附加費率。
如要瞭解機器系列的定價資訊,請參閱「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 具備超過預設容量的記憶體,方可獲得最佳效果。這類工作負載以記憶體內高效能分析資料庫為基礎,包括 MS SQL Server、MongoDB 和 MemcacheD/Redis 等關聯式和 NoSQL 資料庫。作業系統和軟體堆疊的 vCPU 授權方式,也讓您在使用預先定義的機器類型時,更難選擇最佳的 VM 記憶體設定。您可使用擴充記憶體自由新增需要的記憶體數量,讓 VM 達到最佳的價格/效能比。
使用 GB 或 MB 做為記憶體表示單位
對於 Google Cloud 工具和說明文件,機器類型記憶體是以 GB 計算,1 GB 是 230 個位元。這種計算單位又稱為 GiB。將記憶體從 GB 轉換為 MB 時,換算方式為 1 GB = 1024 MB。
在 API 中,提供記憶體時請務必以 MB 為單位。如果您使用 Google Cloud CLI,可以以 GB 或 MB 為單位提供 VM 的記憶體總量。不過,gcloud CLI 要求記憶體值應為整數,因此無法提供浮點數值。例如,若要表示 5.75 GB,請將 5.75 GB 轉換為 MB。在此案例中,5.75 GB 應為 5888 MB。
使用自訂機器類型建立 VM
在您建立自訂 VM 執行個體前,請務必詳閱建立此機器類型的自訂規格。主控台
前往 Google Cloud 控制台的「Create an instance」(建立執行個體) 頁面。
在「機器設定」窗格中,執行下列操作:
- 選取要代管執行個體的「Region」(區域)和「Zone」(可用區)。
- 選取「一般用途」或「GPU」。
- 在「Series」清單中,選取機器系列。
- 如為一般用途,請選擇 N4、N2、N2D、E2 或 N1。
- 針對「GPU」,請選擇 G2。
- 在「Machine type」(機器類型) 部分中,選取「Custom」(自訂)。
- 如要指定執行個體的 vCPU 數量和記憶體容量,請拖曳滑桿,或在文字方塊中輸入值。當您變更 vCPU 和記憶體的數量時,主控台會顯示執行個體的估計費用。
- 在「Series」清單中,選取機器系列。
選用:指定其他設定選項。詳情請參閱「建立執行個體時的設定選項」。
如要建立並啟動執行個體,請按一下「建立」。
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
更改下列內容:
- 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 虛擬機器,記憶體必須是 1024 MB 的倍數,且必須位於支援的記憶體範圍內。如要進一步瞭解如何建立 G2 VM,請參閱「建立已連接 GPU 的 VM」。
以下是使用區域 us-central1-a
中具有 48 個 vCPU 和 310 GB 記憶體的 N2 機器類型的範例:
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
更改下列內容:
- INSTANCE_NAME:執行個體名稱
- NUMBER_OF_VCPUS:vCPU 數量
- NUMBER_OF_MB:記憶體量,以 MB 或 GB 為單位
- MACHINE_TYPE:機器類型,例如 N2
以下範例是使用 Google Cloud CLI 選項,建立具有 48 個 vCPU 和 310 GB 記憶體的 N2 自訂機器類型。
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
更改下列內容:
- INSTANCE_NAME:執行個體名稱
- MACHINE_TYPE:E2 small
- AMOUNT_OF_MEMORY_MB:記憶體量,以 MB 或 GB 為單位
以下範例為 E2 共用核心小型自訂機器類型,具有 0.5 個 vCPU 和 2.25 GB 記憶體。
gcloud compute instances create example-instance \
--machine-type=e2-custom-small-2304
Terraform
如要產生 Terraform 程式碼,您可以使用 Google Cloud 控制台中的「等效程式碼」元件。- 前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面。
- 點選「建立執行個體」。
- 指定所需參數。
- 在頁面頂端或底部,按一下「等效程式碼」,然後點選「Terraform」分頁標籤,即可查看 Terraform 程式碼。
Go
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Go。詳情請參閱 Compute Engine Go API 參考資料說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Java
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Java。詳情請參閱 Compute Engine Java API 參考資料說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Node.js
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Node.js。詳情請參閱 Compute Engine Node.js API 參考資料說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Python
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Python。詳情請參閱 Compute Engine Python API 參考資料說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
REST
使用 instances.insert
方法,建構執行個體建立要求,並指定自訂 machineType
值。請以「MB」為單位提供記憶體。
- 如果是 N1 機器系列,請先從自訂機器類型開始。
- 對於 E2 共用核心,NUMBER_OF_CPUs 為
micro
、small
或medium
。 - 如要啟用擴充記憶體,請在機器類型結尾加上
-ext
。
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 執行個體,請按照下列步驟操作:主控台
前往 Google Cloud 控制台的「Create an instance」(建立執行個體) 頁面。
在「機器設定」窗格中,執行下列操作:
- 在「Zone」(可用區) 清單中,選取要代管此 VM 的可用區。系統會篩選系列清單,只保留所選區域可用的機器類型系列。
- 選取「一般用途」。
- 在「系列」清單中,選取「N4」、「N2」、「N2D」和「N1」,建立自訂機器類型。
- 如要指定 vCPU 數量,請拖曳「Cores」滑桿,或在欄位中輸入值。
- 如要新增擴充記憶體,請選取「擴充記憶體」。如要指定機器類型的記憶體量,請拖曳「Memory」滑桿,或在欄位中輸入值。當您編輯 vCPU 和記憶體的數量時,主控台會顯示 VM 的預估費用。
選用:指定其他設定選項。詳情請參閱「建立執行個體時的設定選項」。
如要建立並啟動 VM,請按一下 [Create] (建立)。
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
更改下列內容:
- INSTANCE_NAME:執行個體名稱
- MACHINE_TYPE:機器類型,例如 N2
- NUMBER_OF_VCPUS:vCPU 數量
- AMOUNT_OF_MEMORY_MB:記憶體量,以 MB 或 GB 為單位
以下是使用區域 us-central1-a
中具有 48 個 vCPU 和 310 GB 記憶體的 N2 機器類型的範例:
gcloud compute instances create example-instance \
--zone=us-central1-a --machine-type=n2-custom-48-317440
Go
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Go。詳情請參閱 Compute Engine Go API 參考資料說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Java
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Java。詳情請參閱 Compute Engine Java API 參考資料說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Node.js
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Node.js。詳情請參閱 Compute Engine Node.js API 參考資料說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Python
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Python。詳情請參閱 Compute Engine Python API 參考資料說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
REST
使用 instances.insert
方法,建立執行個體建立要求,就像使用自訂記憶體建立執行個體一樣。指定 machineType
值時,請一併加入 -ext
,以表示擴充記憶體:
- 針對所有自訂機器類型,請附加
-ext
,將記憶體擴充至該特定機器系列所述的限制。
zones/ZONE/machineTypes//MACHINE_TYPE-NUMBER_OF_CPUS-AMOUNT_OF_MEMORY-ext
更改下列內容:
- ZONE:機器位置
- MACHINE_TYPE:機器類型,例如 N2 或 E2 小型
- NUMBER_OF_CPUS:vCPU 數量
- AMOUNT_OF_MEMORY_MB:記憶體量 (以 MB 為單位)
例如,下列指令所指定的是具有 2 個 vCPU 和 20 GB 記憶體的 N2 機器類型,請注意,您必須將記憶體轉換為 MB:
zones/ZONE/machineTypes/n2-custom-2-20480-ext
為現有 VM 執行個體新增擴充記憶體
如要為使用自訂機器類型的現有執行個體新增更多記憶體,您必須先停止執行個體。執行個體停止後,請完成下列步驟,為 VM 新增更多記憶體。主控台
前往 Google Cloud 控制台的「VM instances」(VM 執行個體) 頁面。
從 VM 清單中選擇要修改的已停止 VM。
按一下頁面頂端的「Edit」(編輯)。
在「機器設定」中,選取「一般用途」。
在「Machine type」(機器類型) 部分中,選取「Custom」(自訂)。
選取所需的 vCPU 數量。
如要新增擴充記憶體,請選取「Extend memory」,然後指定所需記憶體大小。
儲存變更。
gcloud
使用 gcloud compute instances stop
指令停止 VM。接著,請使用 gcloud compute instances set-machine-type
指令搭配 --custom-memory
和 --custom-extensions
選項來編輯機器的資源。
儲存變更並重新啟動 VM。
Go
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Go。詳情請參閱 Compute Engine Go API 參考資料說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Java
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Java。詳情請參閱 Compute Engine Java API 參考資料說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Node.js
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Node.js。詳情請參閱 Compute Engine Node.js API 參考資料說明文件。
如要向 Compute Engine 進行驗證,請設定應用程式預設憑證。詳情請參閱「為本機開發環境設定驗證機制」。
Python
在試用這個範例之前,請先按照 使用用戶端程式庫的 Compute Engine 快速入門中的操作說明設定 Python。詳情請參閱 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
後續步驟
- 進一步瞭解機器系列。
- 建立 VM 後,請依序完成教學課程,開始使用 VM 執行個體。
- 瞭解如何連線至 VM 執行個體。