您可以完成下列工作,在 Compute Engine 執行個體中使用 Hyperdisk Balanced、Hyperdisk Extreme 或 Hyperdisk Throughput 磁碟分割區:
- 建立空白、非開機和可用區 Hyperdisk 磁碟區,並在建立執行個體時或之後將其附加至執行個體。
- 格式化及掛接磁碟區,以便存取資料或檔案系統。
對於 Hyperdisk Balanced 磁碟區,您也可以建立啟動磁碟和資料磁碟。
如需 Hyperdisk 的一般資訊,請參閱「關於 Hyperdisk」。
如要為執行個體新增 Hyperdisk 平衡高可用性磁碟,請按照下列程序操作:
事前準備
- 在將 Hyperdisk 磁碟區新增至運算執行個體前,請先詳閱 Hyperdisk 限制。
-
如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 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.
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.
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.
-
必要角色和權限
如要取得在執行個體中新增 Hyperdisk 磁碟區所需的權限,請要求管理員為您授予專案的下列 IAM 角色:
-
Compute 執行個體管理員 (v1) (
roles/compute.instanceAdmin.v1
) -
如要連線至可以以服務帳戶身分執行的執行個體,請按照下列步驟操作:
服務帳戶使用者 (v1) (
roles/iam.serviceAccountUser
)
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
這些預先定義的角色包含在執行個體中新增 Hyperdisk 磁碟區所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要將 Hyperdisk 磁碟區新增至執行個體,您必須具備下列權限:
-
如要建立及附加 Hyperdisk 磁碟區,請按照下列步驟操作:
-
compute.disks.create
專案 -
執行個體的
compute.instances.attachDisk
權限 -
compute.disks.use
在要連結至執行個體的磁碟上
-
-
如要格式化及掛接已連結的磁碟區,請按照下列步驟操作:
compute.instances.setMetadata
在執行個體上
Hyperdisk 磁碟區支援的值
建立或修改 Hyperdisk 磁碟區時使用的值,必須落在 Hyperdisk 磁碟區限制中所述的最大值和最小值範圍內。
如果您要修改已連結至 VM 的 Hyperdisk 磁碟區大小,新值不得超過 每個 VM 的 Hyperdisk 限制。
Hyperdisk 磁碟區的已佈建 IOPS 和處理量必須遵循「 關於 Hyperdisk 的 IOPS 和處理量佈建」一文中所述的規則。
在執行個體中新增 Hyperdisk 磁碟區
您可以使用 Google Cloud 控制台、Google Cloud CLI 或 REST 建立及連結 Hyperdisk 磁碟區。
建立 Hyperdisk 磁碟區時,您指定的大小、傳輸量和 IOPS 必須在支援的值範圍內。
建立 Hyperdisk 平衡式磁碟區時,您可以選擇在多重寫入模式下建立磁碟,讓多個執行個體同時存取磁碟。
主控台
前往「VM instances」(VM 執行個體) 頁面。
按一下您要為其新增磁碟的執行個體名稱。
在「VM instance details」(VM 執行個體詳細資料) 頁面上,按一下 [Edit] (編輯)。
在「Additional disks」(其他磁碟) 標題下方,點選「Add new disk」(增加新磁碟)。
指定磁碟名稱,並視需要加入說明。選取「磁碟來源類型」的「空白磁碟」。
在「磁碟設定」下方,從下列清單中選擇磁碟類型。您指定的值必須在支援的值範圍內。
- Hyperdisk Balanced。您也可以變更預設磁碟的大小、已配置 IOPS 和已配置的傳輸量設定。
- Hyperdisk Extreme。您也可以變更預設磁碟的大小和已配置 IOPS 設定。
- Hyperdisk ML。您也可以變更預設磁碟大小和已配置的傳輸量設定。
- Hyperdisk 處理量。您也可以變更預設磁碟的大小和已佈建的處理量設定。
選用:針對 Hyperdisk 平衡磁區,您可以透過在多重寫入模式下建立磁碟,啟用將磁碟連接至多個執行個體的功能。在「存取模式」下方,選取「以讀寫模式連接多個 VM」。
按一下 [儲存]。
如要將變更套用至執行個體,請按一下「儲存」。
gcloud
使用
gcloud compute disks create
指令建立 Hyperdisk 磁碟區。gcloud compute disks create DISK_NAME \ --zone=ZONE \ --size=DISK_SIZE \ --type=DISK_TYPE \ --provisioned-iops=IOPS_LIMIT --provisioned-throughput=THROUGHPUT_LIMIT --access-mode=DISK_ACCESS_MODE
更改下列內容:
DISK_NAME
:新磁碟的名稱。ZONE
:新磁碟建立所在的可用區名稱。DISK_SIZE
:(選用) 新磁碟的大小。這個值必須是整數,後面接著大小單位,例如 GB (代表千兆位元組) 或 TB (代表兆位元組)。如果未指定大小單位,系統會使用 100 GB 做為預設值。磁碟大小的接受值如下:- Hyperdisk Balanced:從 4 GiB 到 64 TiB (含頭尾),以 1 GiB 為單位調整。
- Hyperdisk Extreme:從 64 GiB 到 64 TiB (含),以 1 GiB 為單位調整。
- Hyperdisk ML:從 4 GiB 到 64 TiB (含),以 1 GiB 為單位調整。
- Hyperdisk 處理量:從 2 TiB 到 32 TiB (含),以 1 GiB 為單位遞增。
DISK_TYPE
:磁碟類型。請使用下列其中一個值:hyperdisk-balanced
、hyperdisk-extreme
、hyperdisk-ml
或hyperdisk-throughput
IOPS_LIMIT
:選用:對於 Hyperdisk Balanced 或 Hyperdisk Extreme 磁碟,這是磁碟可處理的每秒輸入/輸出作業數 (IOPS)。THROUGHPUT_LIMIT
:選用:對於 Hyperdisk Balanced、Hyperdisk ML 或 Hyperdisk Throughput 磁碟區,此為整數,代表磁碟可提供的最大處理量 (以每秒 MiB 為單位)。DISK_ACCESS_MODE
:選用:計算機例如何存取磁碟上的資料。支援的值如下:READ_WRITE_SINGLE
,用於從單一執行個體讀取/寫入資料。這是目前的預設做法。READ_WRITE_MANY
(僅限 Hyperdisk Balanced 和 Hyperdisk Balanced High Availability),用於從多個執行個體同時讀寫存取。READ_ONLY_MANY
(僅限 Hyperdisk ML),適用於從多個執行個體同時存取唯讀資料。
如要設定 Hyperdisk 平衡高可用性磁碟的存取模式,請參閱「建立區域磁碟」。
選用:使用
gcloud compute disks describe DISK_NAME
指令查看磁碟說明。建立磁碟後,您可以將磁碟連結至執行個體。
REST
使用
disks.insert
方法建構POST
要求,以建立區域 Hyperdisk。請加入name
、sizeGb
、type
、provisionedIops
和provisionedThroughput
屬性。如要將這個磁碟建立為空白且未格式化的非開機磁碟,請勿指定來源映像檔或來源快照。POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/disks { "name": "DISK_NAME", "sizeGb": "DISK_SIZE", "type": "https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/diskTypes/DISK_TYPE", "provisionedIops": "IOPS_LIMIT", "provisionedThroughput": "THROUGHPUT_LIMIT", "accessMode": "DISK_ACCESS_MODE" }
更改下列內容:
PROJECT_ID
:您的專案 IDZONE
:執行個體和新磁碟所在的區域DISK_NAME
:新磁碟的名稱DISK_SIZE
:(選用) 新磁碟的大小。值必須是整數,後面加上大小單位,例如 GB (吉位元組) 或 TB (太位元組)。DISK_TYPE
:磁碟類型。如要建立 Hyperdisk 磁碟區,請使用下列任一值:hyperdisk-balanced
、hyperdisk-extreme
、hyperdisk-ml
或hyperdisk-throughput
。IOPS_LIMIT
:選用:對於 Hyperdisk Balanced 和 Hyperdisk Extreme,這是磁碟每秒可處理的 I/O 作業數量。THROUGHPUT_LIMIT
:選用:對於 Hyperdisk Balanced、Hyperdisk ML 或 Hyperdisk Throughput 磁碟區,此為整數,代表磁碟可提供的最大處理量 (以每秒 MiB 為單位)。DISK_ACCESS_MODE
:選用:計算機例如何存取磁碟上的資料。支援的值如下:READ_WRITE_SINGLE
,用於從單一執行個體存取讀寫權限。這是目前的預設做法。READ_WRITE_MANY
(僅限 Hyperdisk Balanced 和 Hyperdisk Balanced High Availability),用於從多個執行個體同時讀寫存取。READ_ONLY_MANY
(僅限 Hyperdisk ML),適用於從多個執行個體同時存取唯讀資料。
如要設定 Hyperdisk 平衡高可用性磁碟的存取模式,請參閱「建立區域磁碟」。
選用:使用
compute.disks.get
方法查看磁碟說明。建立磁碟後,您可以將磁碟連接至任何執行中或已停止的執行個體。
Go
Java
Node.js
建立磁碟後,您可以將磁碟連接至任何執行中或已停止的執行個體。
格式化及掛接磁碟
建立並將新磁碟連接至執行個體後,必須格式化和掛接磁碟,好讓作業系統能使用可用的儲存空間。
- Linux:請參閱「在 Linux 運算執行個體上格式化及掛接非啟動磁碟」一文
- Windows:請參閱「在 Windows 運算執行個體上格式化及掛接非啟動磁碟」
後續步驟
- 瞭解如何自訂 Hyperdisk 磁碟區的 IOPS 和傳輸量。
- 瞭解如何定期使用快照備份磁碟,以免不慎遺失資料。