使用 Google Cloud 控制台建立 Filestore 執行個體

本快速入門導覽課程說明如何使用 Google Cloud 控制台,在 Filestore 中執行基本作業。在快速入門導覽課程中,您將可以:

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

事前準備

  1. 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
  2. In the Google Cloud console, on the project selector page, select or create 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.

    Go to project selector

  3. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

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

  5. 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.

    Enable the API

  6. In the Google Cloud console, on the project selector page, select or create 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.

    Go to project selector

  7. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

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

  9. 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.

    Enable the API

必要的角色

如要取得完成本快速入門導覽課程所需的權限,請要求管理員在專案中授予您下列 IAM 角色:

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

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

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

建立 Compute Engine VM 執行個體做為用戶端

  1. 前往 Google Cloud 控制台的「VM Instances」(VM 執行個體) 頁面。

    前往 Compute Engine 執行個體頁面

  2. 按一下「建立執行個體」,然後按照下列方式設定執行個體。

    • 將「Name」(名稱) 設定為 nfs-client
    • 將「Zone」(區域) 設為 [us-central1-c]
    • 保留預設開機磁碟。
    • 在「Networking」(網路) >「Firewall」(防火牆) 區段中,選取「Allow HTTP traffic」(允許 HTTP 流量) 核取方塊。
    • 將網路保留為 default
  3. 按一下「建立」,建立執行個體。

建立 Filestore 執行個體

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

  1. 前往 Google Cloud 控制台的 Filestore「Instances」(執行個體) 頁面。

    前往「Filestore Instances」(Filestore 執行個體) 頁面

  2. 按一下「建立執行個體」,然後按照下列方式設定執行個體:

    • 將「Instance ID」(執行個體 ID) 設為 nfs-server
    • 將「執行個體類型」設為「區域」
    • 在「容量」中輸入 1 TiB
    • 在「效能」中,按一下「自訂效能」切換按鈕,即可啟用自訂效能。根據預設,您會在「效能」欄位中看到 12,000 IOPS。「隨著容量調整效能」核取方塊已勾選,因此如果變更「容量」欄位中的值,效能也會隨之調整。如要瞭解設定選項的詳細資訊,請參閱「設定效能」。

    • 將「Region」(地區) 設為 us-central1

    • 將「VPC network」(虛擬私人雲端網路) 設為 default

    • 將「File share name」(檔案共用區名稱) 設為 vol1

    • 將「已分配的 IP 範圍」設為「使用系統自動分配的 IP 範圍」

    • 將「Access controls」設為「Grant access to all clients」

  3. 點選「建立」

在用戶端上掛接 Filestore 檔案共用區

  1. 前往 Google Cloud 控制台的「VM Instances」(VM 執行個體) 頁面。

    前往 VM 執行個體頁面

  2. 在 VM 執行個體清單中,按一下nfs-client 的 [SSH] 按鈕,開啟連線至該執行個體的終端機視窗。

  3. 執行下列指令,安裝 NFS:

    sudo apt-get -y update &&
    sudo apt-get -y install nfs-common
    
  4. 執行下列指令,為 Filestore 檔案共用區建立掛接目錄:

    sudo mkdir -p /mnt/test
    
  5. 執行 mount 指令並指定 Filestore 執行個體 IP 位址與檔案共用區名稱,掛接檔案共用區:

    sudo mount MOUNT-POINT-DIRECTORY /mnt/test
    

    其中:

    MOUNT-POINT-DIRECTORY 是掛接 Filestore 檔案共用區的所在目錄路徑。例如:10.0.0.2:/vol1

  6. 選用:確認已掛接 Filestore 檔案共用區:

    df -h --type=nfs
    
  7. 變更設定,開放檔案共用區的存取權限:

    sudo chmod go+rw /mnt/test
    

在檔案共用區中建立檔案

  1. 在連線至 nfs-client 執行個體的終端機視窗中,執行下列指令以建立名為 testfile 的檔案:

    echo 'This is a test' > /mnt/test/testfile
    
  2. 執行下列指令,確認檔案已建立:

    ls /mnt/test
    

    並確認 testfile 是否已列出。

清除所用資源

為了避免系統向您的 Google Cloud 帳戶收取本頁面所用資源的費用,請按照下列步驟操作。

刪除 Google Cloud 專案

  1. 前往 Google Cloud 控制台的「Manage resources」(管理資源) 頁面。

    前往「Manage resources」(管理資源)

  2. 在專案清單中選取要刪除的專案,然後點選「Delete」(刪除)
  3. 在對話方塊中輸入專案 ID,然後按一下 [Shut down] (關閉) 以刪除專案。

刪除 Filestore 執行個體

  1. 前往 Google Cloud 控制台的 Filestore 執行個體頁面。

    前往 Filestore 執行個體頁面

  2. 按一下 nfs-server 執行個體 ID,開啟執行個體詳細資料頁面。

  3. 按一下「刪除」圖示

  4. 收到系統提示時,輸入執行個體 ID。

  5. 點選「刪除」。

刪除 Compute Engine 執行個體

  1. 前往 Google Cloud 控制台的 Filestore 執行個體頁面。

    前往 VM 執行個體頁面

  2. 選取 nfs-client 執行個體名稱旁的核取方塊。

  3. 按一下「刪除」圖示

  4. 系統顯示提示時,再按一下「刪除」

後續步驟