瞭解如何使用 Cloud Storage FUSE 將 Cloud Storage bucket 掛接為本機檔案系統,以便使用標準檔案系統語意與物件互動。
在本快速入門導覽課程中,您將完成下列工作:
在 Debian 或 Ubuntu 上安裝 Cloud Storage FUSE
將 bucket 掛接為機器上的資料夾
將物件上傳至 bucket
您將使用 Google Cloud CLI 建立及管理儲存空間 bucket 中的物件,並使用 Cloud Storage FUSE CLI 將 bucket 掛接至機器。
事前準備
如要設定專案,請完成下列步驟:
- 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自體驗產品的實際應用成效。新客戶還能獲得價值 $300 美元的免費抵免額,用於執行、測試及部署工作負載。
-
In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.
Roles required to 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. -
Verify that billing is enabled for your Google Cloud project.
-
Make sure that you have the following role or roles on the project: Storage Admin (
roles/storage.admin), Storage Bucket Viewer (roles/storage.bucketViewer)Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init -
In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.
Roles required to 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. -
Verify that billing is enabled for your Google Cloud project.
-
Make sure that you have the following role or roles on the project: Storage Admin (
roles/storage.admin), Storage Bucket Viewer (roles/storage.bucketViewer)Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
- Click Grant access.
-
In the New principals field, enter your user identifier. This is typically the email address for a Google Account.
- Click Select a role, then search for the role.
- To grant additional roles, click Add another role and add each additional role.
- Click Save.
-
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init - 擁有要掛接的 Cloud Storage bucket。如果還沒有值區,請建立新值區。
安裝 Cloud Storage FUSE
如要安裝 Cloud Storage FUSE,請按照「安裝 Cloud Storage FUSE」中的操作說明進行。
安裝水桶
如要將 bucket 掛接至本機檔案系統,請完成下列步驟:
使用
gcloud auth application-default login指令產生應用程式預設憑證:gcloud auth application-default login
Cloud Storage FUSE 會自動載入憑證。
建立要掛接儲存空間 bucket 的目錄:
mkdir "$HOME/mount-folder"
使用
gcsfuse指令掛接儲存空間 bucket:gcsfuse BUCKET_NAME "$HOME/mount-folder"
將 BUCKET_NAME 替換為要掛接的值區名稱。
如果成功,指令會傳回類似下列文字的輸出內容:
File system has been successfully mounted.
將物件上傳至 bucket
如要下載範例物件並上傳至已掛接的值區,請完成下列步驟:

在圖片上按一下滑鼠右鍵,然後儲存到電腦上的某個位置,例如桌面。
您也可以使用 cURL 指令
curl -O https://cloud.google.com/storage/images/kitten.png下載圖片。使用
cp指令,將圖片從儲存位置複製到 bucket 掛接的資料夾:cp kitten.png "$HOME/mount-folder/kitten.png"
請按照下列步驟,確認圖片已複製到本機檔案系統,並成功上傳至 bucket:
如要確認
kitten.png已複製到本機檔案系統,請在掛接 bucket 的資料夾中執行ls:ls "$HOME/mount-folder"
如果複製作業成功,輸出內容會傳回
kitten.png。如要列出 bucket 的內容,請使用
gcloud storage ls指令:gcloud storage ls gs://BUCKET_NAME
將 BUCKET_NAME 替換為 bucket 名稱。
如果圖片已成功上傳至 bucket,輸出內容會傳回
kitten.png。
清除所用資源
為避免系統向您的 Google Cloud 帳戶收取本頁面所用資源的費用,請按照下列步驟刪除資源:
使用
fusermount工具從 Linux 電腦卸載儲存空間 bucket:fusermount -u "$HOME/mount-folder"
如要刪除 bucket 和其中的所有內容,請使用
gcloud storage rm指令搭配--recursive旗標:gcloud storage rm gs://BUCKET_NAME --recursive
將 BUCKET_NAME 替換為 bucket 名稱。
如果成功,指令會傳回類似以下的輸出內容:
Removing gs://my-bucket/kitten.png#1676488739323620... Removing gs://my-bucket/...
後續步驟
瞭解如何針對不同用途掛接 bucket。
瞭解如何使用 Cloud Storage 代理程式技能,透過 AI 程式開發輔助工具自動掛接及設定快取。
- 瞭解 Vertex AI 如何使用 Cloud Storage FUSE,為自訂訓練工作掛接 Cloud Storage bucket。