טעינת קטגוריה של Cloud Storage באמצעות Cloud Storage FUSE

‫Cloud Storage FUSE מאפשר לטעון קטגוריה של Cloud Storage כמערכת קבצים מקומית, כדי שתוכלו לנהל אינטראקציה עם האובייקטים שלכם באמצעות סמנטיקה של מערכת קבצים רגילה. במדריך למתחילים הזה תתקינו את Cloud Storage FUSE ב-Debian או ב-Ubuntu, תטענו קטגוריה כתיקייה במכונה ותעלו אובייקט לקטגוריה.

תשתמשו ב-Google Cloud CLI כדי ליצור ולנהל את האובייקט בקטגוריית האחסון שלכם, וב-Cloud Storage FUSE CLI כדי לטעון את הקטגוריה למכונה שלכם.

לפני שמתחילים

כדי להגדיר פרויקט, מבצעים את השלבים הבאים:

  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. קטגוריה של Cloud Storage שרוצים לטעון. אם עדיין אין לכם קטגוריה, צרו קטגוריה חדשה.

התקנת Cloud Storage FUSE

כדי להתקין את Cloud Storage FUSE, פועלים לפי ההוראות במאמר התקנת Cloud Storage FUSE.

טעינת הקטגוריה

כדי לטעון את הקטגוריה למערכת הקבצים המקומית שלכם, מבצעים את הפעולות הבאות:

  1. יוצרים Application Default Credentials באמצעות הפקודה gcloud auth application-default login:

    gcloud auth application-default login

    ‫Cloud Storage FUSE טוען באופן אוטומטי את פרטי הכניסה.

  2. יוצרים ספרייה שאליה צריך לטעון את קטגוריית האחסון:

    mkdir "$HOME/mount-folder"
  3. טוענים את קטגוריית האחסון באמצעות הפקודה gcsfuse:

    gcsfuse BUCKET_NAME "$HOME/mount-folder"

    מחליפים את BUCKET_NAME בשם הקטגוריה שרוצים לטעון.

    אם הפקודה מסתיימת בלי שגיאות, היא תחזיר פלט שמכיל טקסט דומה לזה:

    File system has been successfully mounted.

העלאת אובייקט לקטגוריה

כדי להוריד אובייקט לדוגמה ולהעלות אותו לקטגוריה שנטענה, מבצעים את הפעולות הבאות:

תמונה של חתלתול להעלות לקטגוריה.

  1. לוחצים לחיצה ימנית על התמונה ושומרים אותה במקום כלשהו במחשב, למשל בשולחן העבודה.

    אפשר גם להוריד את התמונה באמצעות פקודת ה-cURL curl -O https://cloud.google.com/storage/images/kitten.png.

  2. מעתיקים את התמונה מהמיקום שבו נשמרה לתיקייה שבה הקטגוריה נטענה, באמצעות הפקודה cp:

    cp kitten.png "$HOME/mount-folder/kitten.png"
  3. כך מוודאים שהתמונה הועתקה למערכת הקבצים המקומית והועלתה לקטגוריה ללא שגיאות:

    1. כדי לבדוק שהקובץ kitten.png הועתק למערכת הקבצים המקומית, מריצים את הפקודה ls בתיקייה שבה הקטגוריה שלכם נטענה:

      ls "$HOME/mount-folder"

      אם פעולת ההעתקה בוצעה ללא שגיאות, הפלט יחזיר kitten.png.

    2. כדי להציג את תוכן הקטגוריה, משתמשים בפקודה gcloud storage ls:

      gcloud storage ls gs://BUCKET_NAME

      מחליפים את BUCKET_NAME בשם הקטגוריה שלכם.

      אם התמונה הועלתה לקטגוריה ללא שגיאות, הפלט יחזיר kitten.png.

הסרת המשאבים

כדי להימנע מצבירת חיובים בחשבון Cloud de Confiance by S3NS על המשאבים שבהם השתמשתם בדף הזה, מוחקים את המשאבים באמצעות הפעולות הבאות:

  1. מנתקים את קטגוריית האחסון ממכונת Linux שלכם באמצעות הכלי fusermount:

    fusermount -u "$HOME/mount-folder"
  2. כדי למחוק את הקטגוריה ואת כל התוכן שבה, משתמשים בפקודה gcloud storage rm עם הדגל --recursive:

    gcloud storage rm gs://BUCKET_NAME --recursive

    מחליפים את BUCKET_NAME בשם הקטגוריה שלכם.

    אם הפקודה מסתיימת בלי שגיאות, היא תחזיר פלט דומה לזה:

    Removing gs://my-bucket/kitten.png#1676488739323620...
     Removing gs://my-bucket/...

המאמרים הבאים