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

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

במדריך למתחילים הזה תבצעו את הפעולות הבאות:

  • התקנת Cloud Storage FUSE ב-Debian או ב-Ubuntu

  • טעינת הקטגוריה כתיקייה במכונה

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

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

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

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

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. 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 Google Cloud 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 Google Cloud 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 email address for a Google Account.

    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.
  5. התקינו את ה-CLI של Google Cloud.

  6. אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

  7. כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:

    gcloud init
  8. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  9. Verify that billing is enabled for your Google Cloud project.

  10. 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 Google Cloud 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 Google Cloud 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 email address for a Google Account.

    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.
  11. התקינו את ה-CLI של Google Cloud.

  12. אם אתם משתמשים בספק זהויות חיצוני (IdP), קודם אתם צריכים להיכנס ל-CLI של gcloud באמצעות המאגר המאוחד לניהול זהויות.

  13. כדי לאתחל את ה-CLI של gcloud, הריצו את הפקודה הבאה:

    gcloud init
  14. יש לכם קטגוריה של 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.

הסרת המשאבים

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

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

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