使用 gcloud CLI 建立 Filestore 執行個體
本快速入門導覽課程說明如何使用 Google Cloud CLI,快速開始及執行 Identity and Access Management。在本快速入門導覽課程中,您將瞭解如何執行下列操作:
- 建立 IAM 執行個體。
- 在 Compute Engine 用戶端 VM 上,掛接該執行個體的檔案共用區。
- 在已掛接的檔案共用區中建立檔案。
- 刪除 IAM 執行個體。
事前準備
- 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.
-
Install the Google Cloud CLI.
-
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
-
執行下列指令,初始化 gcloud CLI:
gcloud init -
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_IDwith 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_IDwith your Google Cloud project name.
-
如要使用現有專案進行本指南中的操作,請確認您具有完成本指南所需的權限。如果您建立新專案,則已具備必要權限。
-
Verify that billing is enabled for your Google Cloud project.
-
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 theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable file.googleapis.com
-
Install the Google Cloud CLI.
-
若您採用的是外部識別資訊提供者 (IdP),請先使用聯合身分登入 gcloud CLI。
-
執行下列指令,初始化 gcloud CLI:
gcloud init -
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Create a Google Cloud project:
gcloud projects create PROJECT_ID
Replace
PROJECT_IDwith 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_IDwith your Google Cloud project name.
-
如要使用現有專案進行本指南中的操作,請確認您具有完成本指南所需的權限。如果您建立新專案,則已具備必要權限。
-
Verify that billing is enabled for your Google Cloud project.
-
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 theserviceusage.services.enablepermission. Learn how to grant roles.gcloud services enable file.googleapis.com
-
建立及管理 Filestore 執行個體:
Cloud Filestore 編輯者 (
roles/file.editor) -
建立及管理 Compute Engine 執行個體:
Compute 執行個體管理員 (v1) (
roles/compute.instanceAdmin.v1) -
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
-
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
建立 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"
- 為執行個體
取得您建立的 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
-
Establish an SSH connection to the
nfs-client執行個體:gcloud compute ssh nfs-client
在
nfs-client的終端機視窗中執行下列指令,安裝 NFS:sudo apt-get -y update && sudo apt-get -y install nfs-common在
nfs-client執行個體上,為 IAM 檔案共用區建立掛接目錄:sudo mkdir /mnt/test指定 IAM 執行個體的 IP 位址、檔案共用區名稱,以及要掛接的掛接目錄,即可使用
mount指令將檔案共用區掛接到nfs-client執行個體: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為
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-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執行個體。- 在命令提示字元中執行
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離開
PowerShell:exit從
Command Prompt,使用mount指令將檔案共用區掛接到nfs-client執行個體,並指定 IAM 執行個體的 IP 位址、檔案共用區名稱,以及要掛接的磁碟機代號:mount -o mtype=hard 10.0.0.2:/vol1 z:在
nfs-client終端機視窗中執行下列指令,建立名為testfile的檔案:echo 'This is a test' > /mnt/test/testfile執行下列指令並確認
testfile位於傳回的目錄內容中,確認檔案已建立:ls /mnt/test在
nfs-client執行個體的命令提示字元視窗中,建立名為testfile的檔案:echo 'This is a test' > Z:\testfile執行下列指令,確認檔案已建立:
dir Z:並確認
testfile位於傳回的目錄內容中。- 如要進一步瞭解 IAM 的基本概念,請參閱「身分與存取權管理總覽」。
- 按照「建立執行個體」一文中的操作說明,自行設定 IAM 執行個體。
- 請參閱「存取權控管」,瞭解如何控管對 IAM 作業及執行個體資源的存取權。
- 瞭解如何將資料複製到 Filestore 執行個體,或是複製 Filestore 執行個體中的資料。
- 瞭解如何將大型資料集從 Cloud Storage 移轉至 Filestore。
必要的角色
如要取得完成本快速入門導覽課程所需的權限,請要求管理員在專案中授予您下列 IAM 角色:
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
完成本文所述工作後,您可以刪除建立的資源,避免繼續計費,詳情請參閱「清除所用資源」一節。
建立 Compute Engine VM
Linux
Windows
建立 IAM 執行個體
本快速入門導覽課程說明如何在啟用自訂效能的區域服務層級中建立執行個體。如要瞭解如何建立執行個體,請參閱建立執行個體。
複製執行個體的 IP 位址,供掛接檔案共用區時使用。在本快速入門導覽課程中,我們使用 IP 位址 10.0.0.2。
在 nfs-client 執行個體中掛接 IAM 檔案共用區
Linux
Windows
登入 nfs-client 執行個體,然後以系統管理員身分開啟命令提示字元
安裝 NFS 用戶端
設定 NFS 用戶端所用的使用者 ID
將 vol1 檔案共用區對應至 nfs-client 執行個體
在已掛接的檔案共用區中建立檔案
Linux
Windows
清除所用資源
為了避免系統向您的 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