Montare un bucket Cloud Storage utilizzando Cloud Storage FUSE

Cloud Storage FUSE ti consente di montare un bucket Cloud Storage come file system locale, in modo da poter interagire con i tuoi oggetti utilizzando la semantica del file system standard. In questa guida rapida, installerai Cloud Storage FUSE su Debian o Ubuntu, monterai un bucket come cartella sulla tua macchina e caricherai un oggetto nel bucket.

Utilizzerai Google Cloud CLI per creare e gestire l'oggetto nel bucket di archiviazione e l'interfaccia a riga di comando di Cloud Storage FUSE per montare il bucket sulla tua macchina.

Prima di iniziare

Per configurare un progetto, completa i seguenti passaggi:

  1. In the Cloud de Confiance console, on the project selector page, click Create project to begin creating a new Cloud de Confiance project.

    Roles required to create a project

    To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  2. Verify that billing is enabled for your Cloud de Confiance project.

  3. 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

    1. In the Cloud de Confiance console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. 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.

    4. 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

    1. In the Cloud de Confiance console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the identifier for a user in a workforce identity pool. For details, see Represent workforce pool users in IAM policies, or contact your administrator.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.
  4. Install the Google Cloud CLI.

  5. Configure the gcloud CLI to use your federated identity.

    For more information, see Sign in to the gcloud CLI with your federated identity.

  6. To initialize the gcloud CLI, run the following command:

    gcloud init
  7. Avere un bucket Cloud Storage da montare. Se non ne hai già uno, crea un nuovo bucket.

Installa Cloud Storage FUSE

Per installare Cloud Storage FUSE, segui le istruzioni riportate in Installa Cloud Storage FUSE.

Monta il bucket

Per montare il bucket sul file system locale, completa i seguenti passaggi:

  1. 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.

  2. Crea una directory in cui montare il bucket di archiviazione:

    mkdir "$HOME/mount-folder"
  3. 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 che contiene un testo simile al seguente:

    File system has been successfully mounted.

Carica un oggetto nel bucket

Per scaricare un oggetto di esempio e caricarlo nel bucket montato, completa i seguenti passaggi:

Immagine di un gattino da caricare nel bucket.

  1. Fai clic con il tasto destro del mouse sull'immagine e salvala in un punto qualsiasi 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.

  2. Copia l'immagine dalla posizione in cui è salvata alla cartella in cui è montato il bucket, utilizzando il comando cp:

    cp kitten.png "$HOME/mount-folder/kitten.png"
  3. Per verificare che l'immagine sia stata copiata nel file system locale e caricata correttamente nel bucket, segui questi passaggi:

    1. Per verificare che kitten.png sia stato copiato nel file system locale, esegui ls sulla cartella in cui è montato il bucket:

      ls "$HOME/mount-folder"

      Se l'operazione di copia è andata a buon fine, nell'output viene restituito kitten.png.

    2. 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, l'output restituisce kitten.png.

Esegui la pulizia

Per evitare che al tuo account Cloud de Confiance by S3NS vengano addebitati costi relativi alle risorse utilizzate in questa pagina, elimina le risorse completando i seguenti passaggi:

  1. Smonta il bucket di archiviazione dalla macchina Linux utilizzando lo strumento fusermount:

    fusermount -u "$HOME/mount-folder"
  2. 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/...

Passaggi successivi