使用 gcloud CLI 建立 Filestore 執行個體
本快速入門導覽課程說明如何使用 Google Cloud CLI 快速設定及執行 Filestore。在本快速入門導覽課程中,您將瞭解如何:
- 建立 Filestore 執行個體。
- 在 Compute Engine 用戶端 VM 上,掛接該執行個體的檔案共用區。
- 在掛接的檔案共用區中建立檔案。
- 刪除 Filestore 執行個體。
事前準備
-
安裝 Google Cloud CLI。
-
設定 gcloud CLI,使用您的聯合身分。
詳情請參閱「使用聯合身分登入 gcloud CLI」。
-
執行下列指令,初始化 gcloud CLI:
gcloud init -
選取或建立專案所需的角色
- 選取專案:選取專案時,不需具備特定 IAM 角色,只要您已獲派角色,即可選取任何專案。
-
建立專案:如要建立專案,您必須具備專案建立者角色 (
roles/resourcemanager.projectCreator),其中包含resourcemanager.projects.create權限。瞭解如何授予角色。
-
建立 Cloud de Confiance 專案:
gcloud projects create PROJECT_ID
將
PROJECT_ID替換為您要建立的 Cloud de Confiance 專案名稱。 -
選取您建立的 Cloud de Confiance 專案:
gcloud config set project PROJECT_ID
將
PROJECT_ID替換為 Cloud de Confiance 專案名稱。
-
如要使用現有專案進行本指南中的操作,請確認您具有完成本指南所需的權限。如果您建立新專案,則已具備必要權限。
-
確認 Cloud de Confiance 專案已啟用計費功能。
啟用 Filestore API (如果尚未啟用):
啟用 API 所需的角色
如要啟用 API,您必須具備
serviceusage.services.enable權限。如果您建立了專案,可能已透過擁有者角色 (roles/owner) 取得這項權限。否則,您可以透過 Service Usage 管理員角色 (roles/serviceusage.serviceUsageAdmin) 取得這項權限。瞭解如何授予角色。gcloud services enable file.googleapis.com
必要的角色
如要取得完成本快速入門導覽課程所需的權限,請要求管理員在專案中授予您下列 IAM 角色:
-
建立及管理 Filestore 執行個體:Cloud Filestore 編輯者 (
roles/file.editor) -
建立及管理 Compute Engine 執行個體:Compute 執行個體管理員 (v1) (
roles/compute.instanceAdmin.v1)
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
完成本文所述工作後,您可以刪除建立的資源,避免繼續計費,詳情請參閱「清除所用資源」一節。
建立 Compute Engine VM
Linux
-
建立 Compute Engine 執行個體。按照下列指示設定執行個體:
-
將執行個體命名為
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
-
建立 Compute Engine 執行個體。按照下列指示設定執行個體:
-
將執行個體命名為
nfs-client。 -
將
--zone旗標設為us-central1-c。 -
將
--image-project旗標設為windows-cloud。 -
將
--image-family旗標設為windows-2012-r2。 -
將
--tags旗標設為http-server。
gcloud compute instances create nfs-client --zone=us-central1-c --image-project=windows-cloud --image-family=windows-2012-r2 --tags=http-server
-
將執行個體命名為
建立 Filestore 執行個體
本快速入門導覽課程說明如何建立區域服務級別的執行個體,並啟用自訂效能。如要進一步瞭解如何建立執行個體,請參閱「建立執行個體」。
建立 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"
- 為執行個體
取得您建立的 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
-
建立與
nfs-client執行個體的 SSH 連線:gcloud compute ssh nfs-client
在
nfs-client的終端機視窗中執行下列指令,安裝 NFS:sudo apt-get -y update && sudo apt-get -y install nfs-common在
nfs-client執行個體上,為 Filestore 檔案共用區建立掛接目錄:sudo mkdir /mnt/test使用
mount指令,將檔案共用區掛接至nfs-client執行個體,並指定 Filestore 執行個體的 IP 位址、檔案共用區名稱,以及要掛接的掛接目錄:sudo mount MOUNT-POINT-DIRECTORY /mnt/test其中:
MOUNT-POINT-DIRECTORY 是 Filestore 檔案共用區掛接位置的目錄路徑。例如:
10.0.0.2:/vol1選用:確認 Filestore 檔案共用區已掛接:
df -h --type=nfs
變更設定,開放檔案共用區的存取權限:
sudo chmod go+rw /mnt/test
Windows
登入 nfs-client 執行個體,並以管理員身分開啟命令提示字元
建立帳戶並為
nfs-client執行個體設定初始密碼:gcloud compute reset-windows-password nfs-client設定執行個體,啟用序列埠連線功能:
gcloud compute instances add-metadata nfs-client --metadata=serial-port-enable=1進入互動式工作階段:
gcloud compute connect-to-serial-port nfs-client --port=2在
SAC>提示中建立新管道:cmd系統會建立名為
Cmd0001的管道。連線至管道:
ch -sn Cmd0001輸入
nfs-client執行個體的使用者名稱和密碼,並將Domain欄位留空。您已連線至nfs-client執行個體的Command Prompt介面。
安裝 NFS 用戶端
在
nfs-client的Command Prompt中,切換至Windows PowerShell:powershell安裝
NFS用戶端:Install-WindowsFeature -Name NFS-Client在系統提示時重新啟動
nfs-client執行個體:restart-computer在
SAC>提示中,等待下列通知出現:EVENT: The CMD command is now available.
接著,按照先前的指示執行
cmd和ch -sn指令,登入並重新連線至nfs-client執行個體。
設定 NFS 用戶端所用的使用者 ID
- 在命令提示字元中執行
powershell,切換至 Windows PowerShell。 在
PowerShell中執行下列指令,建立兩個新的登錄項目AnonymousUid和AnonymousGid: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重新啟動 NFS 用戶端服務:
nfsadmin client stop nfsadmin client start
將 vol1 檔案共用區對應至 nfs-client 執行個體
結束
PowerShell:exit在
Command Prompt中,使用mount指令將檔案共用區掛接至nfs-client執行個體,並指定 Filestore 執行個體的 IP 位址、檔案共用區名稱,以及要掛接的磁碟機代號:mount -o mtype=hard 10.0.0.2:/vol1 z:
在掛接的檔案共用區中建立檔案
Linux
在
nfs-client終端機視窗中,執行下列指令來建立名為testfile的檔案:echo 'This is a test' > /mnt/test/testfile執行下列指令,確認檔案已建立,並確認傳回的目錄內容中包含
testfile:ls /mnt/test
Windows
在
nfs-client執行個體的命令提示字元視窗中,建立名為testfile的檔案:echo 'This is a test' > Z:\testfile執行下列指令,確認檔案已建立:
dir Z:並確認傳回的目錄內容中包含
testfile。
清除所用資源
為了避免系統向您的 Cloud de Confiance 帳戶收取本頁面所用資源的費用,請刪除含有這些資源的 Cloud de Confiance 專案。
刪除 Cloud de Confiance 專案
刪除 Cloud de Confiance 專案:
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
後續步驟
- 請參閱「Filestore 總覽」,進一步瞭解 Filestore 的基本概念。
- 按照「建立執行個體」的操作說明,自行設定 Filestore 執行個體。
- 請參閱「存取控管」一文,瞭解如何控管 Filestore 作業和執行個體資源的存取權。
- 瞭解如何將資料複製到 Filestore 執行個體,或是複製 Filestore 執行個體中的資料。
- 瞭解如何將大型資料集從 Cloud Storage 移轉至 Filestore。