使用 gcloud CLI 建立 Filestore 執行個體

本快速入門導覽課程說明如何使用 Google Cloud CLI,快速開始及執行 Filestore。在本快速入門課程中,您將瞭解如何:

  • 建立 Filestore 執行個體。
  • 在 Compute Engine 用戶端 VM 上掛接該執行個體的檔案共用區。
  • 在已掛載的檔案共用區中建立檔案。
  • 刪除 Filestore 執行個體。

事前準備

  1. 建立或選取專案:

    建立專案

     gcloud projects create PROJECT_ID
    

    選取專案

     gcloud config set project PROJECT_ID
    

    其中 PROJECT_ID 是 Google Cloud 專案的 ID。

  2. 請確認您已為專案啟用計費功能。瞭解如何啟用結算功能

  3. 安裝並初始化 gcloud CLI

    如果您已安裝 gcloud CLI,可以使用 gcloud components update 指令進行更新:

    gcloud components update
    

完成本文件所述工作後,您可以刪除已建立的資源,避免繼續計費。詳情請參閱「清除所用資源」。

建立 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,

建立 Filestore 執行個體

本快速入門導覽課程說明如何在區域服務層級中建立啟用自訂效能功能的執行個體。如要進一步瞭解如何建立執行個體,請參閱「建立執行個體」。

  1. 建立 Filestore 執行個體。如下所示建立執行個體:

    • 為執行個體 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. 取得您建立的 Filestore 執行個體相關資訊:

      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

nfs-client 執行個體上掛接 Filestore 檔案共用區

Linux

  1. Establish an SSH connection to the nfs-client instance:
    gcloud compute ssh nfs-client

  1. nfs-client 的終端機視窗中執行下列指令,安裝 NFS:

    sudo apt-get -y update &&
    sudo apt-get -y install nfs-common
    
  2. nfs-client 執行個體上建立 Filestore 檔案共用區的掛接目錄:

    sudo mkdir /mnt/test
    
  3. 指定 Filestore 執行個體的 IP 位址、檔案共用區名稱,以及要掛接的掛接目錄,即可使用 mount 指令將檔案共用區掛接到 nfs-client 執行個體:

    sudo mount 10.0.0.2:/vol1 /mnt/test
    
  4. 變更設定,開放檔案共用區的存取權限:

    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.

    接著,請按照先前的操作說明執行 cmdch -sn 指令,登入並重新連線至 nfs-client 執行個體。

設定 NFS 用戶端所用的使用者 ID

  1. 在命令提示字元中執行 powershell,切換至 Windows PowerShell。
  2. PowerShell 中執行下列指令,建立兩個新的登錄項目 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 使用 mount 指令將檔案共用區掛接至 nfs-client 執行個體,方法是指定 Filestore 執行個體的 IP 位址、檔案共用區名稱,以及要掛接的磁碟機代號:

    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 執行個體的「Command Prompt」視窗中,建立名為 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

刪除 Filestore 執行個體

刪除 nfs-server 執行個體:

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

刪除 Compute Engine 執行個體

刪除執行個體:
gcloud compute instances delete nfs-client

後續步驟