建立新的 Hyperdisk 磁碟區


如要將 Hyperdisk Balanced、Hyperdisk Extreme 或 Hyperdisk Throughput 磁碟區與 Compute Engine 執行個體搭配使用,請完成下列工作:

  • 建立空白的非開機可用區 Hyperdisk 磁碟區,並在建立執行個體時或之後將其附加至執行個體。
  • 格式化並掛接磁碟區,以存取資料或檔案系統。

對於 Hyperdisk Balanced 磁碟區,您也可以建立開機磁碟和資料磁碟。

如要瞭解 Hyperdisk 的一般資訊,請參閱「關於 Hyperdisk」。

如要將 Hyperdisk Balanced High Availability 磁碟新增至執行個體,請按照下列程序操作:

事前準備

  • 將 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

    1. 安裝 Google Cloud CLI。 安裝完成後,執行下列指令初始化 Google Cloud CLI:

      gcloud init

      如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

    2. Set a default region and zone.

    Go

    如要在本機開發環境中使用本頁的 Go 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。

      安裝 Google Cloud CLI。

      如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

      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.

    詳情請參閱 Set up authentication for a local development environment

    Java

    如要在本機開發環境中使用本頁的 Java 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。

      安裝 Google Cloud CLI。

      如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

      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.

    詳情請參閱 Set up authentication for a local development environment

    Node.js

    如要在本機開發環境中使用本頁的 Node.js 範例,請安裝並初始化 gcloud CLI,然後使用使用者憑證設定應用程式預設憑證。

      安裝 Google Cloud CLI。

      如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

      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.

    詳情請參閱 Set up authentication for a local development environment

    REST

    如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。

      安裝 Google Cloud CLI。

      如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI

    詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。

必要角色和權限

如要取得將 Hyperdisk 磁碟區新增至執行個體所需的權限,請要求管理員授予您專案的下列 IAM 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。

這些預先定義的角色具備將 Hyperdisk 磁碟區新增至執行個體所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:

所需權限

如要將 Hyperdisk 磁碟區新增至執行個體,您必須具備下列權限:

  • 如要建立及附加 Hyperdisk 磁碟區:
    • 專案的 compute.disks.create
    • compute.instances.attachDisk 執行個體
    • compute.disks.use 要連結至執行個體的磁碟區
  • 如要格式化及掛接附加的磁碟區,請在執行個體上執行以下指令: compute.instances.setMetadata

您或許還可透過自訂角色或其他預先定義的角色取得這些權限。

Hyperdisk 磁碟區支援的值

大小限制

為 Hyperdisk 磁碟區指定的大小必須在下表列出的範圍內。

Hyperdisk 類型 大小下限 大小上限 預設大小
Hyperdisk Balanced 4 GiB 64 TiB 100 GiB
Hyperdisk Balanced High Availability 4 GiB 64 TiB 100 GiB
Hyperdisk Extreme 64 GiB 64 TiB 1 TiB
Hyperdisk ML 4 GiB 64 TiB 100 GiB
Hyperdisk Throughput 2 TiB 32 TiB 2 TiB

不過,附加至 VM 的 Hyperdisk 磁碟區大小不得超過 VM 的 Hyperdisk 限制

效能限制

下表列出各 Hyperdisk 類型可指定的效能限制。不過,您可以指定的 IOPS 和處理量等級也取決於磁碟區大小。如需各項限制的詳細摘要,請參閱 Hyperdisk BalancedHyperdisk Balanced High AvailabilityHyperdisk ExtremeHyperdisk MLHyperdisk Throughput 的「大小和效能限制」一節。

Hyperdisk 類型 IOPS 限制 處理量上限 (MiB/秒)
Hyperdisk Balanced 160,000 2,400
Hyperdisk Balanced High Availability 100,000 1,200
Hyperdisk Extreme 350,000 您無法為 Hyperdisk Extreme 磁碟區佈建輸送量等級。每 1,000 IOPS 的磁碟區可獲得 250 MiB/s 的總處理量,最高可達 5,000 MiB/s。
Hyperdisk ML 您無法佈建 IOPS 級別,但每佈建 1 MiB/s 的輸送量,就會有 16 個 IOPS,最多可達 19,200,000 個 IOPS。 1,200,000
Hyperdisk Throughput 您無法佈建 IOPS 級別,但每佈建 1 MiB/s 的處理量,就會有 4 個 IOPS,最多可達 9,600 個 IOPS。 2,400

Hyperdisk 類型變數

下表列出各 Hyperdisk 類型的參考值。使用 Google Cloud CLI、REST 或 Compute Engine 適用的 Cloud 用戶端程式庫建立 Hyperdisk 磁碟區時,請從下表提供對應值,指明要建立的 Hyperdisk 類型。

磁碟類型 參照名稱
Hyperdisk Balanced hyperdisk-balanced
Hyperdisk Balanced High Availability hyperdisk-balanced-high-availability
Hyperdisk Extreme hyperdisk-extreme
Hyperdisk Throughput hyperdisk-throughput
Hyperdisk ML hyperdisk-ml

將 Hyperdisk 磁碟區新增至執行個體

您可以使用Google Cloud 控制台、Google Cloud CLI 或 REST,建立及連結 Hyperdisk 磁碟區。

建立 Hyperdisk 磁碟區時,指定的大小、輸送量和 IOPS 必須在支援的值範圍內。

建立 Hyperdisk Balanced 磁碟區時,您可以選擇以多重寫入模式建立磁碟,允許多個執行個體同時存取磁碟。

主控台

  1. 前往「VM instances」(VM 執行個體) 頁面。

    前往 VM 執行個體

  2. 按一下您要為其新增磁碟的執行個體名稱。

  3. 在「VM instance details」(VM 執行個體詳細資料) 頁面上,按一下 [Edit] (編輯)

  4. 在「Additional disks」(其他磁碟) 標題下方,點選「Add new disk」(增加新磁碟)

  5. 指定磁碟名稱,並視需要新增說明。選取「空白磁碟」做為「磁碟來源類型」

  6. 在「磁碟設定」下方,從下列清單中選擇磁碟類型。指定的值必須在支援的值範圍內。

    1. Hyperdisk Balanced。您也可以變更預設的磁碟「大小」、「佈建 IOPS」和「佈建處理量」設定。
    2. Hyperdisk Extreme。您也可以變更預設的磁碟大小佈建 IOPS 設定。
    3. Hyperdisk ML。您也可以變更預設磁碟大小佈建的輸送量設定。
    4. Hyperdisk 處理量。您也可以變更預設磁碟大小佈建處理量設定。
  7. 選用:如果是 Hyperdisk Balanced 磁碟區,您可以建立處於多重寫入模式的磁碟,啟用將磁碟連接至多個執行個體的功能。在「存取模式」下方,選取「以讀寫模式連接多個 VM」

  8. 按一下 [儲存]

  9. 如要將變更套用至執行個體,請按一下「儲存」

gcloud

  1. 使用 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-balancedhyperdisk-extremehyperdisk-mlhyperdisk-throughput
    • IOPS_LIMIT:選用:如果是 Hyperdisk Balanced 或 Hyperdisk Extreme 磁碟,這是指磁碟每秒可處理的 I/O 作業數 (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),可供多個執行個體同時讀寫存取。
      • (僅限 Hyperdisk ML) 可供多個執行個體同時進行唯讀存取。READ_ONLY_MANY

      如要設定 Hyperdisk Balanced High Availability 磁碟的存取模式,請參閱建立區域磁碟

  2. 選用:使用 gcloud compute disks describe DISK_NAME 指令查看磁碟說明。

  3. 建立磁碟後,您可以將磁碟連接至執行個體

REST

  1. 使用 disks.insert 方法建構 POST 要求,以建立區域 Hyperdisk。請包含 namesizeGbtypeprovisionedIopsprovisionedThroughput 屬性。如要將這個磁碟建立為空白且未格式化的非開機磁碟,請勿指定來源映像檔或來源快照。

    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:您的專案 ID
    • ZONE:執行個體和新磁碟所在的可用區
    • DISK_NAME:新磁碟的名稱
    • DISK_SIZE:選用:新磁碟的大小。值必須為整數,後接大小單位,例如 GB 代表吉位元組,TB 代表太位元組。
    • DISK_TYPE:磁碟類型。如要建立 Hyperdisk 磁碟區,請使用下列其中一個值:hyperdisk-balancedhyperdisk-extremehyperdisk-mlhyperdisk-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 Balanced High Availability 磁碟的存取模式,請參閱建立區域磁碟

  2. 選用:使用 compute.disks.get 方法查看磁碟說明。

  3. 建立磁碟後,您可以將磁碟連接至任何執行中或已停止的執行個體。

Go

// createHyperdisk creates a new Hyperdisk in the specified project and zone.
func createHyperdisk(w io.Writer, projectId, zone, diskName string) error {
	//   projectID := "your_project_id"
	//   zone := "europe-central2-b"
	//   diskName := "your_disk_name"

	ctx := context.Background()
	client, err := compute.NewDisksRESTClient(ctx)
	if err != nil {
		return fmt.Errorf("NewDisksRESTClient: %v", err)
	}
	defer client.Close()

	// use format "zones/{zone}/diskTypes/(hyperdisk-balanced|hyperdisk-throughput)".
	diskType := fmt.Sprintf("zones/%s/diskTypes/hyperdisk-balanced", zone)

	// Create the disk
	disk := &computepb.Disk{
		Name:   proto.String(diskName),
		Type:   proto.String(diskType),
		SizeGb: proto.Int64(10),
		Zone:   proto.String(zone),
	}

	req := &computepb.InsertDiskRequest{
		Project:      projectId,
		Zone:         zone,
		DiskResource: disk,
	}

	op, err := client.Insert(ctx, req)
	if err != nil {
		return fmt.Errorf("Insert disk request failed: %v", err)
	}

	// Wait for the insert disk operation to complete
	if err = op.Wait(ctx); err != nil {
		return fmt.Errorf("unable to wait for the operation: %w", err)
	}

	fmt.Fprintf(w, "Hyperdisk created: %v\n", diskName)
	return nil
}

Java


import com.google.cloud.compute.v1.Disk;
import com.google.cloud.compute.v1.DisksClient;
import com.google.cloud.compute.v1.InsertDiskRequest;
import com.google.cloud.compute.v1.Operation;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class CreateHyperdisk {
  public static void main(String[] args)
          throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // TODO(developer): Replace these variables before running the sample.
    // Project ID or project number of the Google Cloud project you want to use.
    String projectId = "YOUR_PROJECT_ID";
    // Name of the zone in which you want to create the disk.
    String zone = "europe-central2-b";
    // Name of the disk you want to create.
    String diskName = "YOUR_DISK_NAME";
    // The type of disk you want to create. This value uses the following format:
    // "zones/{zone}/diskTypes/(hyperdisk-balanced|hyperdisk-extreme|hyperdisk-throughput)".
    // For example: "zones/us-west3-b/diskTypes/hyperdisk-balanced"
    String diskType = String.format("zones/%s/diskTypes/hyperdisk-balanced", zone);
    // Size of the new disk in gigabytes.
    long diskSizeGb = 10;
    // Optional: For Hyperdisk Balanced or Hyperdisk Extreme disks,
    // this is the number of I/O operations per second (IOPS) that the disk can handle
    long provisionedIops = 3000;
    // Optional: For Hyperdisk Balanced or Hyperdisk Throughput volumes,
    // this is an integer that represents the throughput,
    // measured in MiB per second, that the disk can handle.
    long provisionedThroughput = 140;

    createHyperdisk(projectId, zone, diskName, diskType, diskSizeGb,
            provisionedIops, provisionedThroughput);
  }

  // Creates a hyperdisk in a project
  public static Disk createHyperdisk(String projectId, String zone, String diskName,
                                     String diskType, long diskSizeGb, long provisionedIops,
                                     long provisionedThroughput)
          throws IOException, ExecutionException, InterruptedException, TimeoutException {
    // Initialize client that will be used to send requests. This client only needs to be created
    // once, and can be reused for multiple requests.
    try (DisksClient client = DisksClient.create()) {
      // Create a disk.
      Disk disk = Disk.newBuilder()
              .setZone(zone)
              .setName(diskName)
              .setType(diskType)
              .setSizeGb(diskSizeGb)
              .setProvisionedIops(provisionedIops)
              .setProvisionedThroughput(provisionedThroughput)
              .build();

      InsertDiskRequest request = InsertDiskRequest.newBuilder()
              .setProject(projectId)
              .setZone(zone)
              .setDiskResource(disk)
              .build();

      // Wait for the insert disk operation to complete.
      Operation operation = client.insertAsync(request).get(1, TimeUnit.MINUTES);

      if (operation.hasError()) {
        System.out.println("Disk creation failed!");
        throw new Error(operation.getError().toString());
      }

      // Wait for server update
      TimeUnit.SECONDS.sleep(10);

      Disk hyperdisk = client.get(projectId, zone, diskName);

      System.out.printf("Hyperdisk '%s' has been created successfully", hyperdisk.getName());

      return hyperdisk;
    }
  }
}

Node.js

// Import the Compute library
const computeLib = require('@google-cloud/compute');
const compute = computeLib.protos.google.cloud.compute.v1;

// Instantiate a diskClient
const disksClient = new computeLib.DisksClient();
// Instantiate a zoneOperationsClient
const zoneOperationsClient = new computeLib.ZoneOperationsClient();

/**
 * TODO(developer): Update/uncomment these variables before running the sample.
 */
// Project ID or project number of the Google Cloud project you want to use.
const projectId = await disksClient.getProjectId();

// The zone where your VM and new disk are located.
// zone = 'europe-central2-b';

// The name of the new disk
// diskName = 'disk-name';

// The type of disk. This value uses the following format:
// "zones/{zone}/diskTypes/(hyperdisk-balanced|hyperdisk-extreme|hyperdisk-ml|hyperdisk-throughput)".
// For example: "zones/us-west3-b/diskTypes/hyperdisk-balanced"
const diskType = `zones/${zone}/diskTypes/hyperdisk-balanced`;
// Size of the new disk in gigabytes.
const diskSizeGb = 10;
// Optional: For Hyperdisk Balanced or Hyperdisk Extreme disks,
// this is the number of I/O operations per second (IOPS) that the disk can handle.
const provisionedIops = 3000;
// Optional: For Hyperdisk Balanced or Hyperdisk Throughput volumes,
// this is an integer that represents the throughput,
// measured in MiB per second, that the disk can handle.
const provisionedThroughput = 140;

async function callCreateComputeHyperdisk() {
  // Create a disk
  const disk = new compute.Disk({
    sizeGb: diskSizeGb,
    name: diskName,
    zone,
    type: diskType,
    provisionedIops,
    provisionedThroughput,
  });

  const [response] = await disksClient.insert({
    project: projectId,
    zone,
    diskResource: disk,
  });

  let operation = response.latestResponse;

  // Wait for the create disk operation to complete.
  while (operation.status !== 'DONE') {
    [operation] = await zoneOperationsClient.wait({
      operation: operation.name,
      project: projectId,
      zone: operation.zone.split('/').pop(),
    });
  }

  console.log(`Disk: ${diskName} created.`);
}

await callCreateComputeHyperdisk();

建立磁碟後,您可以將磁碟連接至任何執行中或已停止的執行個體。

格式化並掛接磁碟

建立新磁碟並將該磁碟連接至執行個體之後,必須格式化和掛接磁碟,好讓作業系統能使用可用的儲存空間。

後續步驟