gcloud CLI を使用して Filestore インスタンスを作成する

このクイックスタートでは、Google Cloud CLI を使用して Identity and Access Management をすぐに利用開始する方法について説明します。このクイックスタートの内容:

  • IAM インスタンスを作成します。
  • そのインスタンスからのファイル共有を Compute Engine クライアント VM にマウントする。
  • マウントされたファイル共有にファイルを作成する。
  • IAM インスタンスを削除します。

始める前に

  1. Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
  2. Install the Google Cloud CLI.

  3. 外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。

  4. gcloud CLI を初期化するには、次のコマンドを実行します。

    gcloud init
  5. Create or select a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.
    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  6. このガイドで既存のプロジェクトを使用する場合は、このガイドを完了するために必要な権限があることを確認します。新しいプロジェクトを作成した場合は、必要な権限がすでに付与されています。

  7. Verify that billing is enabled for your Google Cloud project.

  8. Enable the Filestore API:

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    gcloud services enable file.googleapis.com
  9. Install the Google Cloud CLI.

  10. 外部 ID プロバイダ(IdP)を使用している場合は、まず連携 ID を使用して gcloud CLI にログインする必要があります。

  11. gcloud CLI を初期化するには、次のコマンドを実行します。

    gcloud init
  12. Create or select a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.
    • Create a Google Cloud project:

      gcloud projects create PROJECT_ID

      Replace PROJECT_ID with a name for the Google Cloud project you are creating.

    • Select the Google Cloud project that you created:

      gcloud config set project PROJECT_ID

      Replace PROJECT_ID with your Google Cloud project name.

  13. このガイドで既存のプロジェクトを使用する場合は、このガイドを完了するために必要な権限があることを確認します。新しいプロジェクトを作成した場合は、必要な権限がすでに付与されています。

  14. Verify that billing is enabled for your Google Cloud project.

  15. Enable the Filestore API:

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    gcloud services enable file.googleapis.com
  16. 必要なロール

    このクイックスタートを完了するために必要な権限を取得するには、プロジェクトに対する次の IAM ロールを付与するよう管理者に依頼してください。

    ロールの付与については、プロジェクト、フォルダ、組織へのアクセス権の管理をご覧ください。

    必要な権限は、カスタムロールや他の事前定義ロールから取得することもできます。

    このドキュメントに記載されているタスクの完了後、作成したリソースを削除すると、それ以上の請求は発生しません。詳細については、クリーンアップをご覧ください。

    Compute Engine VM を作成する

    Linux

    1. Create a Compute Engine instance. Configure the instance as follows:
      • Name the instance nfs-client.
      • --zone フラグを us-central1-c に設定します。
      • --image-project フラグを debian-cloud に設定します。
      • --image-family フラグを debian-11 に設定します。
      • --tags フラグを http-server, に設定します。
      • gcloud compute instances create nfs-client --zone=us-central1-c --image-project=debian-cloud --image-family=debian-11 --tags=http-server,

    Windows

    1. Create a Compute Engine instance. Configure the instance as follows:
      • Name the instance nfs-client.
      • --zone フラグを us-central1-c に設定します。
      • --image-project フラグを windows-cloud に設定します。
      • --image-family フラグを windows-2012-r2 に設定します。
      • --tags フラグを http-server,http-server, に設定します。
      • gcloud compute instances create nfs-client --zone=us-central1-c --image-project=windows-cloud --image-family=windows-2012-r2 --tags=http-server,http-server,

    IAM インスタンスを作成する

    このクイックスタートでは、カスタム パフォーマンスが有効になっているリージョン サービスティアでインスタンスを作成する方法について説明します。インスタンスの作成の詳細については、インスタンスを作成するをご覧ください。

    1. IAM インスタンスを作成します。インスタンスを次のように構成します。

      • インスタンスに nfs-server という名前を付けます。
      • --region フラグを us-central1 に設定します。
      • --tier フラグを REGIONAL に設定します。
      • --performance フラグを max-iops-per-tb=17000 に設定します。

      • --file-share フラグを name="vol1",capacity=1TB に設定します。

      • --network フラグを name="default" に設定します。

        gcloud filestore instances create nfs-server --region=us-central1 --tier=REGIONAL --performance=max-iops-per-tb=17000 --file-share=name="vol1",capacity=1TB --network=name="default"
    2. 作成した IAM インスタンスに関する情報を取得します。

        gcloud filestore instances describe nfs-server --region=us-central1 

      このコマンドは次のような出力を返します。

          createTime: '2025-02-12T09:15:08.163246004Z'
          customPerformanceSupported: true
          fileShares:
           -capacityGb: '1024'
              name: vol1
          name: projects/yourproject/locations/us-central1/instances/nfs-server
          networks:
          -connectMode: DIRECT_PEERING
            ipAddresses:
             - 10.0.0.2
            network: default
            reservedIpRange: 10.0.0.2/26
          performanceConfig:
            iopsPerTb:
              maxIopsPerTb: '17000'
          performanceLimits:
            maxIops: '17000'
            maxReadIops: '17000'
            maxReadThroughputBps: '417792000'
            maxWriteIops: '5100'
            maxWriteThroughputBps: '139264000'
          protocol: NFS_V3
          state: READY
          tier: REGIONAL

    ファイル共有をマウントするときに使用するために、インスタンスの IP アドレスをコピーします。このクイックスタートでは、IP アドレス 10.0.0.2 を使用します。

    IAM ファイル共有を nfs-client インスタンスにマウントする

    Linux

    1. Establish an SSH connection to the nfs-client インスタンス:
      gcloud compute ssh nfs-client

    1. nfs-client のターミナル ウィンドウで次のコマンドを実行して、NFS をインストールします。

      sudo apt-get -y update &&
      sudo apt-get -y install nfs-common
      
    2. IAM ファイル共有の nfs-client インスタンスにマウント ディレクトリを作成します。

      sudo mkdir /mnt/test
      
    3. IAM インスタンスの IP アドレス、ファイル共有名、マウント先のマウント ディレクトリを指定して mount コマンドを実行し、ファイル共有を nfs-client インスタンスにマウントします。

      sudo mount MOUNT-POINT-DIRECTORY /mnt/test
      

      ここで

      MOUNT-POINT-DIRECTORY は、Filestore ファイル共有がマウントされているディレクトリへのパスです。例: 10.0.0.2:/vol1

    4. 省略可: Filestore ファイル共有がマウントされていることを確認します。

      df -h --type=nfs

    5. 権限を変更し、ファイル共有にアクセスできるようにします。

      sudo chmod go+rw /mnt/test
      

    Windows

    管理者として nfs-client インスタンスにログインし、コマンド プロンプトを開く

    1. アカウントを作成し、nfs-client インスタンスの初期パスワードを設定します。

      gcloud compute reset-windows-password nfs-client
      
    2. インスタンスを構成してシリアルポート接続を有効にします。

      gcloud compute instances add-metadata nfs-client --metadata=serial-port-enable=1
      
    3. インタラクティブ セッションを開始します。

      gcloud compute connect-to-serial-port nfs-client --port=2
      
    4. SAC> プロンプトで、新しいチャネルを作成します。

      cmd
      

      Cmd0001 という名前のチャンネルが作成されます。

    5. チャンネルに接続します。

      ch -sn Cmd0001
      
    6. nfs-client インスタンスのユーザー名とパスワードを入力し、[Domain] フィールドは空白のままにします。nfs-client インスタンスの Command Prompt インターフェースに接続されます。

    NFS クライアントをインストールする

    1. nfs-clientCommand Prompt で、Windows PowerShell に切り替えます。

      powershell
      
    2. NFS クライアントをインストールします。

      Install-WindowsFeature -Name NFS-Client
      
    3. プロンプトが表示されたら、nfs-client インスタンスを再起動します。

      restart-computer
      
    4. SAC> プロンプトで、次の通知が表示されるまで待ちます。

      EVENT: The CMD command is now available.

      次に、前述のように cmd コマンドと ch -sn コマンドを使用してログインし、nfs-client インスタンスに再接続します。

    NFS クライアントが使用するユーザー ID を構成する

    1. コマンドプロンプトで powershell を実行して、Windows PowerShell に切り替えます。
    2. PowerShell で次のコマンドを実行して、2 つの新しいレジストリ エントリ AnonymousUidAnonymousGid を作成します。

      New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default" `
          -Name "AnonymousUid" -Value "0" -PropertyType DWORD
      
      New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default" `
          -Name "AnonymousGid" -Value "0" -PropertyType DWORD
      
    3. NFS クライアント サービスを再起動します。

      nfsadmin client stop
      
      nfsadmin client start
      

    vol1 ファイル共有を nfs-client インスタンスにマッピングする

    1. PowerShell を終了します。

      exit
      
    2. Command Prompt から、IAM インスタンスの IP アドレス、ファイル共有名、マウント先のドライブ レターを指定して mount コマンドを実行し、ファイル共有を nfs-client インスタンスにマウントします。

      mount -o mtype=hard 10.0.0.2:/vol1 z:
      

    マウントされたファイル共有にファイルを作成する

    Linux

    1. nfs-client ターミナル ウィンドウで、次のコマンドを実行して testfile という名前のファイルを作成します。

      echo 'This is a test' > /mnt/test/testfile
      
    2. 次のコマンドを実行して、ファイルが作成されたことを確認します。また、返されたディレクトリ内に testfile があることを確認します。

      ls /mnt/test
      

    Windows

    1. nfs-client インスタンスのコマンド プロンプト ウィンドウで、testfile という名前のファイルを作成します。

      echo 'This is a test' > Z:\testfile
      
    2. 次のコマンドを実行して、ファイルが作成されたことを確認します。

      dir Z:
      

      また、返されたディレクトリ内に testfile があることを確認します。

    クリーンアップ

    このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、リソースを含む Google Cloud プロジェクトを削除します。

    Google Cloud プロジェクトを削除する

      Delete a Google Cloud project:

      gcloud projects delete PROJECT_ID

    IAM インスタンスを削除する

    nfs-server インスタンスを削除します。

    gcloud filestore instances delete nfs-server --zone=us-central1-c
    

    Compute Engine インスタンスを削除する

    インスタンスを削除します。
    gcloud compute instances delete nfs-client

    次のステップ