使用 gcloud CLI 建立 Filestore 執行個體
本快速入門導覽課程說明如何使用 Google Cloud CLI,快速開始及執行 Filestore。在本快速入門課程中,您將瞭解如何:
- 建立 Filestore 執行個體。
- 在 Compute Engine 用戶端 VM 上掛接該執行個體的檔案共用區。
- 在已掛載的檔案共用區中建立檔案。
- 刪除 Filestore 執行個體。
事前準備
建立或選取專案:
建立專案
gcloud projects create PROJECT_ID
選取專案
gcloud config set project PROJECT_ID
其中 PROJECT_ID 是 Google Cloud 專案的 ID。
請確認您已為專案啟用計費功能。瞭解如何啟用結算功能。
-
如果您已安裝 gcloud CLI,可以使用
gcloud components update
指令進行更新:gcloud components update
完成本文件所述工作後,您可以刪除已建立的資源,避免繼續計費。詳情請參閱「清除所用資源」。
建立 Compute Engine VM 做為用戶端
Linux
-
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,
-
Name the instance
Windows
-
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,
-
Name the instance
建立 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
-
Establish an SSH connection to the
nfs-client
instance: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
指定 Filestore 執行個體的 IP 位址、檔案共用區名稱,以及要掛接的掛接目錄,即可使用
mount
指令將檔案共用區掛接到nfs-client
執行個體:sudo mount 10.0.0.2:/vol1 /mnt/test
變更設定,開放檔案共用區的存取權限:
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
執行個體的「Command Prompt」視窗中,建立名為testfile
的檔案:echo 'This is a test' > Z:\testfile
執行下列指令,確認檔案已建立:
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
後續步驟
- 請參閱 Filestore 總覽,進一步瞭解 Filestore 的基本概念。
- 按照「建立執行個體」一文中的操作說明,自行設定 Filestore 執行個體。
- 參閱「存取權控管」一文,瞭解如何控管對 Filestore 作業和執行個體資源的存取權。
- 瞭解如何將資料複製到 Filestore 執行個體,或是複製 Filestore 執行個體中的資料。
- 瞭解如何將大型資料集從 Cloud Storage 移轉至 Filestore。