Scopri come montare un bucket Cloud Storage come file system locale utilizzando Cloud Storage FUSE, in modo da poter interagire con gli oggetti utilizzando la semantica standard del file system.
In questa guida rapida completerai le seguenti attività:
Installare Cloud Storage FUSE su Debian o Ubuntu
Monta il bucket come cartella sul computer
Carica un oggetto nel bucket
Utilizzerai Google Cloud CLI per creare e gestire l'oggetto nel bucket di archiviazione e gcsfuse CLI per montare il bucket sulla macchina.
Prima di iniziare
Per configurare un progetto, completa i seguenti passaggi:
- 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.
Vai a IAM - Seleziona il progetto.
- Fai clic su Concedi l'accesso.
-
Nel campo Nuove entità, inserisci il tuo identificatore utente. In genere si tratta dell'indirizzo email di un Account Google.
- Nell'elenco Seleziona un ruolo, seleziona un ruolo.
- Per concedere altri ruoli, fai clic su Aggiungi un altro ruolo e aggiungi ogni ruolo aggiuntivo.
- Fai clic su Salva.
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.
-
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.
Vai a IAM - Seleziona il progetto.
- Fai clic su Concedi l'accesso.
-
Nel campo Nuove entità, inserisci il tuo identificatore utente. In genere si tratta dell'indirizzo email di un Account Google.
- Nell'elenco Seleziona un ruolo, seleziona un ruolo.
- Per concedere altri ruoli, fai clic su Aggiungi un altro ruolo e aggiungi ogni ruolo aggiuntivo.
- Fai clic su Salva.
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
- Avere un bucket Cloud Storage da montare. Se non ne hai già uno, crea un nuovo bucket.
Aggiungi l'URL di distribuzione di Cloud Storage FUSE come origine pacchetto:
export GCSFUSE_REPO=gcsfuse-`lsb_release -c -s`
echo "deb https://packages.cloud.google.com/apt $GCSFUSE_REPO main" | sudo tee /etc/apt/sources.list.d/gcsfuse.list
Importa la chiave pubblica del repository APT: Google Cloud
curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
Aggiorna l'elenco dei pacchetti disponibili:
sudo apt-get update
Installa Cloud Storage FUSE e la relativa dipendenza FUSE:
sudo apt-get install fuse gcsfuse
Quando richiesto, premi Invio per confermare.
Verifica che Cloud Storage FUSE sia stato installato:
gcsfuse -v
In caso di esito positivo, il comando restituisce un output simile al seguente:
gcsfuse version 0.41.12 (Go version go1.18.4)
Genera le credenziali predefinite dell'applicazione utilizzando il comando
gcloud auth application-default login
:gcloud auth application-default login
Cloud Storage FUSE carica automaticamente le credenziali.
Crea una directory in cui montare il bucket di archiviazione:
mkdir "$HOME/mount-folder"
Monta il bucket di archiviazione utilizzando il comando
gcsfuse
:gcsfuse BUCKET_NAME "$HOME/mount-folder"
Sostituisci BUCKET_NAME con il nome del bucket che vuoi montare.
In caso di esito positivo, il comando restituisce un output contenente un testo simile al seguente:
File system has been successfully mounted.
Fai clic con il tasto destro del mouse sull'immagine e salvala in una posizione del computer, ad esempio sul desktop.
Puoi anche scaricare l'immagine utilizzando il comando cURL
curl -O https://cloud.google.com/storage/images/kitten.png
.Copia l'immagine dalla posizione in cui è salvata nella cartella in cui è montato il bucket utilizzando il comando
cp
:cp kitten.png "$HOME/mount-folder/kitten.png"
Verifica che l'immagine sia stata copiata nel file system locale e caricata nel bucket seguendo i passaggi:
Per verificare che
kitten.png
sia stato copiato nel file system locale, eseguils
nella cartella in cui è montato il bucket:ls "$HOME/mount-folder"
Se l'operazione di copia è riuscita,
kitten.png
viene restituito nell'output.Per elencare i contenuti del bucket, utilizza il comando
gcloud storage ls
:gcloud storage ls gs://BUCKET_NAME
Sostituisci BUCKET_NAME con il nome del tuo bucket.
Se l'immagine è stata caricata correttamente nel bucket, nell'output viene restituito
kitten.png
.
Smonta il bucket di archiviazione dalla macchina Linux utilizzando lo strumento
fusermount
:fusermount -u "$HOME/mount-folder"
Per eliminare il bucket e tutto ciò che contiene al suo interno, utilizza il comando
gcloud storage rm
con il flag--recursive
:gcloud storage rm gs://BUCKET_NAME --recursive
Sostituisci BUCKET_NAME con il nome del tuo bucket.
In caso di esito positivo, il comando restituisce un output simile al seguente:
Removing gs://my-bucket/kitten.png#1676488739323620... Removing gs://my-bucket/...
Visualizza una panoramica dettagliata di Cloud Storage FUSE.
Scopri di più su come montare bucket per diversi casi d'uso.
Installa Cloud Storage FUSE
Per installare Cloud Storage FUSE, completa le seguenti istruzioni utilizzando la shell locale su Debian o Ubuntu:
Monta il secchio
Per montare il bucket sul file system locale, completa i seguenti passaggi:
Carica un oggetto nel bucket
Per scaricare un oggetto di esempio e caricarlo nel bucket montato, completa i seguenti passaggi:
Esegui la pulizia
Per evitare che al tuo account Google Cloud vengano addebitati costi relativi alle risorse utilizzate in questa pagina, elimina le risorse completando i seguenti passaggi: