Cloud Storage FUSE を使用して Cloud Storage バケットをローカル ファイル システムとしてマウントする方法を確認し、標準のファイル システムのセマンティクスを使用してオブジェクトを操作できるようにします。
このクイックスタートでは、次のタスクを行います。
Debian または Ubuntu に Cloud Storage FUSE をインストールする
バケットをマシン上のフォルダとしてマウントする
バケットにオブジェクトをアップロードする
Google Cloud CLI を使用して、ストレージ バケット内のオブジェクトの作成と管理を行います。また、gcsfuse CLI を使用してマシンにバケットをマウントします。
始める前に
プロジェクトを設定するには、次の操作を行います。
- 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.
-
In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.
-
Make sure 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.
IAM に移動 - プロジェクトを選択します。
- [ アクセスを許可] をクリックします。
-
[新しいプリンシパル] フィールドに、ユーザー ID を入力します。 これは通常、Google アカウントのメールアドレスです。
- [ロールを選択] リストでロールを選択します。
- 追加のロールを付与するには、 [別のロールを追加] をクリックして各ロールを追加します。
- [保存] をクリックします。
Install the Google Cloud CLI.
外部 ID プロバイダ(IdP)を使用している場合は、まずフェデレーション ID を使用して gcloud CLI にログインする必要があります。
gcloud CLI を初期化するには、次のコマンドを実行します。
gcloud init
-
-
In the Google Cloud console, on the project selector page, click Create project to begin creating a new Google Cloud project.
-
Make sure 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.
IAM に移動 - プロジェクトを選択します。
- [ アクセスを許可] をクリックします。
-
[新しいプリンシパル] フィールドに、ユーザー ID を入力します。 これは通常、Google アカウントのメールアドレスです。
- [ロールを選択] リストでロールを選択します。
- 追加のロールを付与するには、 [別のロールを追加] をクリックして各ロールを追加します。
- [保存] をクリックします。
Install the Google Cloud CLI.
外部 ID プロバイダ(IdP)を使用している場合は、まずフェデレーション ID を使用して gcloud CLI にログインする必要があります。
gcloud CLI を初期化するには、次のコマンドを実行します。
gcloud init
-
- マウントする Cloud Storage バケットを用意します。まだバケットを保有していない場合は、新しいバケットを作成します。
gcloud auth application-default login
コマンドを使用してアプリケーションのデフォルト認証情報を生成します。gcloud auth application-default login
Cloud Storage FUSE が認証情報を自動的に読み込みます。
ストレージ バケットをマウントするディレクトリを作成します。
mkdir "$HOME/mount-folder"
gcsfuse
コマンドを使用してストレージ バケットをマウントします。gcsfuse BUCKET_NAME "$HOME/mount-folder"
BUCKET_NAME は、マウントするバケットの名前に置き換えます。
成功した場合、コマンドは次のようなテキストを含む出力を返します。
File system has been successfully mounted.
画像を右クリックして、パソコンに保存します(デスクトップなど)。
cURL コマンド
curl -O https://cloud.google.com/storage/images/kitten.png
を使用してイメージをダウンロードすることもできます。cp
コマンドを使用して、保存した場所からバケットがマウントされているフォルダに画像をコピーします。cp kitten.png "$HOME/mount-folder/kitten.png"
次の手順に沿って、画像がローカル ファイル システムにコピーされ、バケットに正常にアップロードされたことを確認します。
kitten.png
がローカル ファイル システムにコピーされたことを確認するには、バケットがマウントされているフォルダでls
を実行します。ls "$HOME/mount-folder"
コピー オペレーションが成功した場合は、出力で
kitten.png
が返されます。バケットの内容を一覧表示するには、
gcloud storage ls
コマンドを使用します。gcloud storage ls gs://BUCKET_NAME
BUCKET_NAME は、実際のバケット名を置き換えます。
画像がバケットに正常にアップロードされると、出力で
kitten.png
が返されます。
fusermount
ツールを使用して、Linux マシンからストレージ バケットをマウント解除します。fusermount -u "$HOME/mount-folder"
バケットとその中のすべてのものを削除するには、
--recursive
フラグを指定してgcloud storage rm
コマンドを使用します。gcloud storage rm gs://BUCKET_NAME --recursive
BUCKET_NAME は、実際のバケット名を置き換えます。
成功した場合、コマンドは次のような出力を返します。
Removing gs://my-bucket/kitten.png#1676488739323620... Removing gs://my-bucket/...
Cloud Storage FUSE の詳細を確認する。
さまざまなユースケースでバケットをマウントする方法を確認する。
- Vertex AI で Cloud Storage FUSE を使用して、カスタム トレーニング ジョブ用に Cloud Storage バケットをマウントする方法を確認する。
Cloud Storage FUSE をインストールする
Cloud Storage FUSE をインストールするには、Cloud Storage FUSE をインストールするの手順に沿って操作します。
バケットをマウントする
バケットをローカル ファイル システムにマウントするには、次の手順を行います。
バケットにオブジェクトをアップロードする
サンプル オブジェクトをダウンロードして、マウントされたバケットにアップロードするには、次の操作を行います。
クリーンアップ
このページで使用したリソースについて、 Google Cloud アカウントに課金されないようにするには、次の手順でリソースを削除します。