VM 간에 Persistent Disk 볼륨 공유


멀티 작성자 모드의 SSD 영구 디스크 볼륨을 최대 2개의 N2 가상 머신(VM) 인스턴스에 동시에 연결하면 두 VM에서 모두 디스크를 읽고 쓸 수 있습니다. 새 Persistent Disk 볼륨에 멀티 작성자 모드를 사용 설정하려면 새 Persistent Disk 볼륨을 만들고 gcloud CLI에서 --multi-writer 플래그를 지정하거나 Compute Engine API에서 multiWriter 속성을 지정합니다.

멀티 작성자 모드의 Persistent Disk 볼륨은 공유 블록 스토리지 기능을 제공하며 분산형 스토리지 시스템 및 이와 유사한 가용성이 높은 서비스를 빌드하기 위한 인프라 기반을 제공합니다. 멀티 작성자 모드에서 Persistent Disk 볼륨을 사용하는 경우 여러 VM에서 영구 디스크 기기에 대한 액세스를 조정할 수 있는 수평 확장 스토리지 소프트웨어 시스템을 사용합니다. 이러한 스토리지 시스템의 예로는 Lustre와 IBM Spectrum Scale이 있습니다. EXT4, XFS, NTFS와 같은 대부분의 단일 VM 파일 시스템은 공유 블록 스토리지와 함께 사용하도록 설계되지 않았습니다. 자세한 내용은 이 문서의 권장사항을 참조하세요. 완전 관리형 파일 스토리지가 필요하면 Compute Engine VM에 Filestore 파일 공유를 마운트할 수 있습니다.

멀티 작성자 모드의 Persistent Disk 볼륨은 SCSI-3 영구 예약 (SCSI PR) 명령어의 하위 집합을 지원합니다. 고가용성 애플리케이션은 I/O 펜싱 및 장애 조치 구성에 이 명령어를 사용할 수 있습니다.

다음과 같은 SCSI PR 명령어가 지원됩니다.

  • IN {REPORT CAPABILITIES, READ FULL STATUS, READ RESERVATION, READ KEYS}
  • OUT {REGISTER, REGISTER AND IGNORE EXISTING KEY, RESERVE, PREEMPT, CLEAR, RELEASE}

시작하기 전에

  • 아직 인증을 설정하지 않았다면 설정합니다. 인증은 Google Cloud 서비스 및 API에 액세스하기 위해 ID를 확인하는 프로세스입니다. 로컬 개발 환경에서 코드 또는 샘플을 실행하려면 다음과 같이 Compute Engine에 인증하면 됩니다.

    이 페이지의 샘플 사용 방법에 대한 탭을 선택하세요.

    콘솔

    Google Cloud 콘솔을 사용하여 Google Cloud 서비스 및 API에 액세스할 때는 인증을 설정할 필요가 없습니다.

    gcloud

    1. Google Cloud CLI를 설치한 후 다음 명령어를 실행하여 초기화합니다.

      gcloud init
    2. 기본 리전 및 영역을 설정합니다.

    Java

    로컬 개발 환경에서 이 페이지의 Java 샘플을 사용하려면 gcloud CLI를 설치 및 초기화한 다음 사용자 인증 정보로 애플리케이션 기본 사용자 인증 정보를 설정하세요.

    1. Google Cloud CLI를 설치합니다.
    2. gcloud CLI를 초기화하려면 다음 명령어를 실행합니다.

      gcloud init
    3. Google 계정의 로컬 인증 사용자 인증 정보를 만듭니다.

      gcloud auth application-default login

    자세한 내용은 로컬 개발 환경의 인증 설정를 참조하세요.

    Python

    로컬 개발 환경에서 이 페이지의 Python 샘플을 사용하려면 gcloud CLI를 설치 및 초기화한 다음 사용자 인증 정보로 애플리케이션 기본 사용자 인증 정보를 설정하세요.

    1. Google Cloud CLI를 설치합니다.
    2. gcloud CLI를 초기화하려면 다음 명령어를 실행합니다.

      gcloud init
    3. Google 계정의 로컬 인증 사용자 인증 정보를 만듭니다.

      gcloud auth application-default login

    자세한 내용은 로컬 개발 환경의 인증 설정를 참조하세요.

    REST

    로컬 개발 환경에서 이 페이지의 REST API 샘플을 사용하려면 gcloud CLI에 제공한 사용자 인증 정보를 사용합니다.

      Google Cloud CLI를 설치한 후 다음 명령어를 실행하여 초기화합니다.

      gcloud init

제한사항

  • SSD 유형 영구 디스크 볼륨에만 사용할 수 있습니다.
  • 모든 영역에 멀티 작성자 모드의 Persistent Disk 볼륨을 만들 수 있지만, 다음 위치의 VM에만 디스크를 연결할 수 있습니다.
    • australia-southeast1
    • europe-west1
    • us-central1(us-central1-aus-central1-c 영역만 해당)
    • us-east1(us-east1-d 영역만 해당)
    • us-west1(us-west1-bus-west1-c 영역만 해당)
  • 연결된 VM에는 N2 머신 유형이 있어야 합니다.
  • 최소 크기: 10GB
  • 최대 연결 VM 수: 2
  • 멀티 작성자 모드의 Persistent Disk 볼륨은 Persistent Disk 측정항목을 지원하지 않습니다.
  • 멀티 작성자 모드의 디스크는 읽기 전용 모드로 변경할 수 없습니다.
  • 디스크 이미지나 스냅샷을 사용하여 멀티 작성자 모드의 Persistent Disk 볼륨을 만들 수 없습니다.
  • 멀티 작성자 모드의 Persistent Disk 볼륨에서 스냅샷이나 이미지를 만들 수 없습니다.
  • IOPS 한도를 낮춥니다. 자세한 내용은 디스크 성능을 참조하세요.
  • 멀티 작성자 Persistent Disk 볼륨의 크기를 조절할 수 없습니다.
  • Google Cloud CLI를 사용해서 VM을 만들 때는 --create-disk 플래그를 사용해서 멀티 작성자 Persistent Disk 볼륨을 만들 수 없습니다.

권장사항

  • SCSI PR 명령어를 사용하는 I/O 펜싱으로 인해 Persistent Disk 데이터가 일관되게 비정상 종료됩니다. 일부 파일 시스템은 일관되게 비정상 종료되지 않으므로 SCSI PR 명령어를 사용할 경우 손상될 수 있습니다.
  • EXT4, XFS, NTFS와 같은 많은 파일 시스템은 공유 블록 스토리지와 함께 사용하도록 설계되지 않았으며 여러 VM 인스턴스에서 발생하는 작업을 동기화하거나 수행하는 메커니즘이 없습니다.
  • Persistent Disk 볼륨을 멀티 작성자 모드로 사용하기 전에 파일 시스템을 이해하고 공유 블록 스토리지와 여러 VM의 동시 액세스에서 안전하게 사용할 수 있는 방법을 확인해야 합니다.

성능

멀티 작성자 모드에서 만들어진 Persistent Disk 볼륨에는 특정 IOPS 및 처리량 한도가 적용됩니다.

영역 SSD 영구 디스크 멀티 작성자 모드
최대 지속 IOPS
GB당 읽기 IOPS 30
GB당 쓰기 IOPS 30
인스턴스당 읽기 IOPS 15,000~100,000*
인스턴스당 쓰기 IOPS 15,000~100,000*
최대 지속 처리량(MB/s)
GB당 읽기 처리량 0.48
GB당 쓰기 처리량 0.48
인스턴스당 읽기 처리량 240~1,200*
인스턴스당 쓰기 처리량 240~1,200*
* 영구 디스크의 IOPS 및 처리량 성능은 여러 요인 중에서도 디스크 크기, 인스턴스 vCPU 수, I/O 블록 크기에 따라 달라집니다.
멀티 작성자 디스크를 다수의 가상 머신 인스턴스에 연결해도 집계 성능이나 비용에 영향을 미치지 않습니다. 각 머신은 디스크당 성능 한도 중 일정 비율을 차지합니다.

여러 VM 간에 영구 디스크를 공유하는 방법은 VM 간 영구 디스크 공유를 참조하세요.

VM 인스턴스 간에 영역 Persistent Disk 볼륨 공유

이 섹션에서는 여러 VM 간에 영역 영구 디스크 볼륨을 공유하는 다양한 방법을 설명합니다.

여러 VM 간에 읽기 전용 모드로 디스크 공유

읽기 전용 모드로 2개 이상 VM에 비부팅 Persistent Disk 볼륨을 연결하여 여러 VM 간에 정적 데이터를 공유할 수 있습니다. 하나의 Persistent Disk 볼륨에서 여러 VM 간에 정적 데이터를 공유하면 개별 VM의 고유 디스크에 데이터를 복제하는 것보다 비용이 적게 듭니다.

여러 VM 간에 동적 저장공간을 공유하려면 다음 옵션 중 하나를 사용할 수 있습니다.

콘솔

  1. Google Cloud 콘솔에서 VM 인스턴스 페이지로 이동합니다.

    VM 인스턴스로 이동

  2. 프로젝트의 VM 목록에서 디스크에 연결하려는 VM 이름을 클릭합니다. VM 인스턴스 세부정보 페이지가 열립니다.

  3. 인스턴스 세부정보 페이지에서 수정을 클릭합니다.

  4. 추가 디스크 섹션에서 다음 중 하나를 클릭합니다.

    1. VM에 디스크를 읽기 전용 모드로 추가하려면 디스크를 추가합니다.
    2. 기존 디스크를 선택하고 읽기 전용 모드로 VM에 연결하려면 기존 디스크를 연결합니다.
  5. 디스크의 다른 옵션을 지정합니다.

  6. 완료를 클릭하여 변경사항을 적용합니다.

  7. 저장을 클릭하여 VM에 변경사항을 적용합니다.

  8. VM에 연결하고 디스크를 마운트합니다.

  9. 다른 VM에 디스크를 읽기 전용 모드로 추가하려면 이 프로세스를 반복합니다.

gcloud

gcloud CLI에서 compute instances attach-disk 명령어를 사용하고 ro 옵션으로 --mode 플래그를 지정합니다.

gcloud compute instances attach-disk INSTANCE_NAME \
  --disk DISK_NAME \
  --mode ro

다음을 바꿉니다.

  • INSTANCE_NAME: 영역 Persistent Disk 볼륨을 연결할 VM의 이름
  • DISK_NAME: 연결할 디스크의 이름

디스크를 연결한 후에 VM에 연결하고 마운트합니다.

이 디스크를 읽기 전용 모드로 추가하려는 각 VM에 이 명령어를 반복합니다.

Java

Java

이 샘플을 사용해 보기 전에 Compute Engine 빠른 시작: 클라이언트 라이브러리 사용Java 설정 안내를 따르세요. 자세한 내용은 Compute Engine Java API 참조 문서를 확인하세요.

Compute Engine에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.


import com.google.cloud.compute.v1.AttachDiskInstanceRequest;
import com.google.cloud.compute.v1.AttachedDisk;
import com.google.cloud.compute.v1.InstancesClient;
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 AttachDisk {

  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 Cloud project you want to use.
    String projectId = "your-project-id";

    // Name of the zone in which the instance you want to use resides.
    String zone = "zone-name";

    // Name of the compute instance you want to attach a disk to.
    String instanceName = "instance-name";

    // Full or partial URL of a persistent disk that you want to attach. This can be either
    // be a regional or zonal disk.
    // Valid formats:
    //     * https://www.googleapis.com/compute/v1/projects/{project}/zones/{zone}/disks/{disk_name}
    //     * /projects/{project}/zones/{zone}/disks/{disk_name}
    //     * /projects/{project}/regions/{region}/disks/{disk_name}
    String diskLink = String.format("/projects/%s/zones/%s/disks/%s",
        "project", "zone", "disk_name");

    // Specifies in what mode the disk will be attached to the instance. Available options are
    // `READ_ONLY` and `READ_WRITE`. Disk in `READ_ONLY` mode can be attached to
    // multiple instances at once.
    String mode = "READ_ONLY";

    attachDisk(projectId, zone, instanceName, diskLink, mode);
  }

  // Attaches a non-boot persistent disk to a specified compute instance.
  // The disk might be zonal or regional.
  // You need following permissions to execute this action:
  // https://cloud.google.com/compute/docs/disks/regional-persistent-disk#expandable-1
  public static void attachDisk(String projectId, String zone, String instanceName, String diskLink,
      String mode)
      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. After completing all of your requests, call
    // the `instancesClient.close()` method on the client to safely
    // clean up any remaining background resources.
    try (InstancesClient instancesClient = InstancesClient.create()) {

      AttachDiskInstanceRequest attachDiskInstanceRequest = AttachDiskInstanceRequest.newBuilder()
          .setProject(projectId)
          .setZone(zone)
          .setInstance(instanceName)
          .setAttachedDiskResource(AttachedDisk.newBuilder()
              .setSource(diskLink)
              .setMode(mode)
              .build())
          .build();

      Operation response = instancesClient.attachDiskAsync(attachDiskInstanceRequest)
          .get(3, TimeUnit.MINUTES);

      if (response.hasError()) {
        System.out.println("Attach disk failed! " + response);
        return;
      }
      System.out.println("Attach disk - operation status: " + response.getStatus());
    }
  }
}

Python

Python

이 샘플을 사용해 보기 전에 Compute Engine 빠른 시작: 클라이언트 라이브러리 사용Python 설정 안내를 따르세요. 자세한 내용은 Compute Engine Python API 참조 문서를 확인하세요.

Compute Engine에 인증하려면 애플리케이션 기본 사용자 인증 정보를 설정합니다. 자세한 내용은 로컬 개발 환경의 인증 설정을 참조하세요.

from __future__ import annotations

import sys
from typing import Any

from google.api_core.extended_operation import ExtendedOperation
from google.cloud import compute_v1

def wait_for_extended_operation(
    operation: ExtendedOperation, verbose_name: str = "operation", timeout: int = 300
) -> Any:
    """
    Waits for the extended (long-running) operation to complete.

    If the operation is successful, it will return its result.
    If the operation ends with an error, an exception will be raised.
    If there were any warnings during the execution of the operation
    they will be printed to sys.stderr.

    Args:
        operation: a long-running operation you want to wait on.
        verbose_name: (optional) a more verbose name of the operation,
            used only during error and warning reporting.
        timeout: how long (in seconds) to wait for operation to finish.
            If None, wait indefinitely.

    Returns:
        Whatever the operation.result() returns.

    Raises:
        This method will raise the exception received from `operation.exception()`
        or RuntimeError if there is no exception set, but there is an `error_code`
        set for the `operation`.

        In case of an operation taking longer than `timeout` seconds to complete,
        a `concurrent.futures.TimeoutError` will be raised.
    """
    result = operation.result(timeout=timeout)

    if operation.error_code:
        print(
            f"Error during {verbose_name}: [Code: {operation.error_code}]: {operation.error_message}",
            file=sys.stderr,
            flush=True,
        )
        print(f"Operation ID: {operation.name}", file=sys.stderr, flush=True)
        raise operation.exception() or RuntimeError(operation.error_message)

    if operation.warnings:
        print(f"Warnings during {verbose_name}:\n", file=sys.stderr, flush=True)
        for warning in operation.warnings:
            print(f" - {warning.code}: {warning.message}", file=sys.stderr, flush=True)

    return result

def attach_disk(
    project_id: str, zone: str, instance_name: str, disk_link: str, mode: str
) -> None:
    """
    Attaches a non-boot persistent disk to a specified compute instance. The disk might be zonal or regional.

    You need following permissions to execute this action:
    https://cloud.google.com/compute/docs/disks/regional-persistent-disk#expandable-1

    Args:
        project_id: project ID or project number of the Cloud project you want to use.
        zone:name of the zone in which the instance you want to use resides.
        instance_name: name of the compute instance you want to attach a disk to.
        disk_link: full or partial URL to a persistent disk that you want to attach. This can be either
            regional or zonal disk.
            Expected formats:
                * https://www.googleapis.com/compute/v1/projects/[project]/zones/[zone]/disks/[disk_name]
                * /projects/[project]/zones/[zone]/disks/[disk_name]
                * /projects/[project]/regions/[region]/disks/[disk_name]
        mode: Specifies in what mode the disk will be attached to the instance. Available options are `READ_ONLY`
            and `READ_WRITE`. Disk in `READ_ONLY` mode can be attached to multiple instances at once.
    """
    instances_client = compute_v1.InstancesClient()

    request = compute_v1.AttachDiskInstanceRequest()
    request.project = project_id
    request.zone = zone
    request.instance = instance_name
    request.attached_disk_resource = compute_v1.AttachedDisk()
    request.attached_disk_resource.source = disk_link
    request.attached_disk_resource.mode = mode

    operation = instances_client.attach_disk(request)

    wait_for_extended_operation(operation, "disk attachement")

REST

API에서 compute.instances.attachDisk 메서드에 대해 POST 요청을 작성합니다. 요청 본문에서 mode 매개변수를 READ_ONLY로 지정합니다.

POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/attachDisk

{
 "source": "zones/ZONE/disks/DISK_NAME",
 "mode": "READ_ONLY"
}

다음을 바꿉니다.

  • INSTANCE_NAME: 영역 Persistent Disk 볼륨을 연결할 VM의 이름
  • PROJECT_ID: 프로젝트 ID입니다.
  • ZONE: 디스크가 있는 영역
  • DISK_NAME: 연결하는 디스크의 이름

디스크를 연결한 후에 VM에 연결하고 마운트합니다.

이 디스크를 읽기 전용 모드로 추가하려는 각 VM에 이 요청을 반복합니다.

여러 VM 간에 멀티 작성자 모드로 SSD 영구 디스크 볼륨 공유

같은 영역의 N2 VM 간에 멀티 작성자 모드로 SSD 영구 디스크 볼륨을 공유할 수 있습니다. 이 모드의 작동 방식에 대한 자세한 내용은 Persistent Disk 멀티 작성자 모드를 참조하세요. 다음 프로세스에 따라 멀티 작성자 Persistent Disk 볼륨을 만들고 연결할 수 있습니다.

gcloud

gcloud CLI를 사용하여 영역 Persistent Disk 볼륨을 만들고 연결합니다.

  1. gcloud beta compute disks create 명령어를 사용하여 영역 Persistent Disk 볼륨을 만듭니다. 멀티 작성자 모드의 VM 간에 디스크를 공유할 수 있어야 함을 나타내려면 --multi-writer 플래그를 포함합니다.

    gcloud beta compute disks create DISK_NAME \
       --size DISK_SIZE \
       --type pd-ssd \
       --multi-writer
    

    다음을 바꿉니다.

    • DISK_NAME: 새 디스크의 이름입니다.
    • DISK_SIZE: 허용되는 새 디스크 크기의 범위(SSD 영구 디스크 볼륨의 경우 1GB~65,536GB, 멀티 작성자 모드의 표준 영구 디스크의 경우 200 GB~65,536 GB)
  2. 디스크를 만든 후 N2 머신 유형으로 실행 중이거나 중지된 VM에 연결합니다. gcloud compute instances attach-disk 명령어를 사용합니다.

    gcloud compute instances attach-disk INSTANCE_NAME \
       --disk DISK_NAME
    

    다음을 바꿉니다.

    • INSTANCE_NAME: 새 영역 Persistent Disk 볼륨을 추가할 N2 VM의 이름
    • DISK_NAME: VM에 연결하려는 새 디스크의 이름
  3. gcloud compute instances attach-disk 명령어를 반복하되 INSTANCE_NAME을 두 번째 VM의 이름으로 바꿉니다.

새 디스크를 만들고 VM에 연결한 후에는 공유 디스크 파일 시스템을 사용하여 디스크를 포맷하고 마운트합니다. 대부분의 파일 시스템은 공유 스토리지를 사용할 수 없습니다. 멀티 작성자 Persistent Disk에서 사용하기 전에 파일 시스템이 이러한 기능을 지원하는지 확인합니다. 일반적으로 단일 VM에 디스크를 마운트할 때와 동일한 프로세스를 사용해서는 여러 VM에 디스크를 마운트할 수 없습니다.

REST

Compute Engine API를 사용하여 멀티 작성자 모드로 SSD 영구 디스크 볼륨을 만들고 N2 VM에 연결합니다.

  1. API에서 disks.insert 메서드를 사용하여 영역 Persistent Disk 볼륨을 만들기 위한 POST 요청을 작성합니다. name, sizeGb, type 속성을 포함합니다. 이 새 디스크를 비어 있고 포맷되지 않은 비부팅 디스크로 만들려면 이 디스크에 대해 소스 이미지 또는 소스 스냅샷을 지정하지 마세요. 멀티 작성자 모드로 여러 VM 간에 디스크를 공유할 수 있음을 나타내기 위해 multiWriter 속성을 True 값으로 포함합니다.

    POST https://compute.googleapis.com/compute/beta/projects/PROJECT_ID/zones/ZONE/disks
    
    {
    "name": "DISK_NAME",
    "sizeGb": "DISK_SIZE",
    "type": "zones/ZONE/diskTypes/pd-ssd",
    "multiWriter": "True"
    }
    

    다음을 바꿉니다.

    • PROJECT_ID: 프로젝트 ID입니다.
    • ZONE: VM과 새 디스크가 있는 영역입니다.
    • DISK_NAME: 새 디스크의 이름입니다.
    • DISK_SIZE: 허용되는 새 디스크 크기의 범위(SSD 영구 디스크 볼륨의 경우 1GB~65,536GB, 멀티 작성자 모드의 표준 영구 디스크의 경우 200 GB~65,536 GB)
  2. compute.instances.attachDisk 메서드에 대해 POST 요청을 작성하고 방금 만든 영역 Persistent Disk 볼륨의 URL을 포함합니다.

    POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/instances/INSTANCE_NAME/attachDisk
    
    {
    "source": "/compute/v1/projects/PROJECT_ID/zones/ZONE/disks/DISK_NAME"
    }
    

    다음을 바꿉니다.

    • PROJECT_ID: 프로젝트 ID입니다.
    • ZONE: VM과 새 디스크가 있는 영역입니다.
    • INSTANCE_NAME: 새 Persistent Disk 볼륨을 추가할 VM의 이름입니다.
    • DISK_NAME: 새 디스크의 이름입니다.
  3. disks.insert 명령어를 반복하되 두 번째 VM을 대신 지정합니다.

새 디스크를 만들고 VM에 연결한 후에는 공유 디스크 파일 시스템을 사용하여 디스크를 포맷하고 마운트합니다. 대부분의 파일 시스템은 공유 스토리지를 사용할 수 없습니다. 멀티 작성자 Persistent Disk에서 사용하기 전에 파일 시스템이 이러한 기능을 지원하는지 확인합니다.

다음 단계