יצירת מכונה של Memorystore for Redis באמצעות ה-CLI של gcloud

במאמר הזה מוסבר איך ליצור מכונת Memorystore for Redis, להתחבר אליה ואז למחוק אותה.


לחצו על תראו לי איך כדי לקרוא הסבר מפורט על המשימה ישירות במסוף Google Cloud :

תראו לי איך


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

  1. נכנסים לחשבון Google Cloud . אם אתם משתמשים חדשים ב- Google Cloud, צרו חשבון כדי שתוכלו להעריך את הביצועים של המוצרים שלנו בתרחישים מהעולם האמיתי. לקוחות חדשים מקבלים בחינם גם קרדיט בשווי 300$ להרצה, לבדיקה ולפריסה של עומסי העבודה.
  2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • 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. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

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

  5. Enable the Memorystore for Redis API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  6. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • 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

  7. If you're using an existing project for this guide, verify that you have the permissions required to complete this guide. If you created a new project, then you already have the required permissions.

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

  9. Enable the Memorystore for Redis API.

    Roles required to enable APIs

    To enable APIs, you need the Service Usage Admin IAM role (roles/serviceusage.serviceUsageAdmin), which contains the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  10. אם עדיין לא עשיתם זאת, מתקינים את Google Cloud CLI.

    כשמתבקשים, בוחרים את הפרויקט שבחרתם או יצרתם.

  11. אם כבר התקנתם את Google Cloud CLI, צריך לעדכן אותו.

    gcloud components update

התפקידים הנדרשים

כדי לקבל את ההרשאות שדרושות ליצירת מכונת Memorystore for Redis, צריך לבקש מהאדמין להקצות לכם את תפקידי ה-IAM הבאים בפרויקט:

להסבר על מתן תפקידים, ראו איך מנהלים את הגישה ברמת הפרויקט, התיקייה והארגון.

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

יצירת מכונה של Memorystore for Redis

בקטע הזה יוצרים מכונת Memorystore for Redis בנפח 2GB שנמצאת באזור us-central1 וברמת Basic. מידע נוסף על הרמות זמין במאמר יכולות של רמות Redis.

  1. פותחים חלון טרמינל.
  2. כדי להגדיר את הפרויקט שבו רוצים ליצור את המופע כפרויקט ברירת המחדל, מזינים את הפקודה הבאה:

    gcloud config set core/project PROJECT_ID
    
  3. כדי ליצור מכונת Redis במסלול בסיסי בגודל 2GiB באזור us-central1, מזינים את הפקודה הבאה:

    gcloud redis instances create myinstance --size=2 --region=us-central1 \
    --redis-version=redis_6_x
    
  4. אחרי שיוצרים את המופע, כדי לקבל את כתובת ה-IP ואת מספר היציאה של המופע, מזינים את הפקודה הבאה:

    gcloud redis instances describe myinstance --region=us-central1
    

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

    authorizedNetwork: projects/my-project/global/networks/default
    createTime: '2018-04-09T21:47:56.824081Z'
    currentLocationId: us-central1-a
    host: 10.0.0.27
    locationId: us-central1-a
    memorySizeGb: 2
    name: projects/my-project/locations/us-central1/instances/myinstance
    networkThroughputGbps: 2
    port: 6379
    redisVersion: REDIS_6_X
    reservedIpRange: 10.0.0.24/29
    state: READY
    tier: BASIC

  5. רושמים את הערכים של host ושל port של המכונה. תצטרכו את הערכים האלה כדי להתחבר למכונה.

התחברות למכונת Memorystore for Redis ממכונה וירטואלית ב-Compute Engine

אפשר להתחבר למופע של Memorystore for Redis מכל מכונה וירטואלית ב-Compute Engine שמשתמשת ברשת המורשית של המופע עם כתובת IP נתמכת מסוג RFC 1918.

  1. אם אין לכם מכונה וירטואלית של Compute Engine שמשתמשת באותה רשת מורשית כמו המופע שלכם, אתם צריכים ליצור אחת כזו ולהתחבר אליה באמצעות SSH. כדי לעשות זאת, פועלים לפי השלבים במאמר יצירת מכונה וירטואלית של Linux ב-Compute Engine.

  2. משתמשים ב-apt-get כדי להתקין את telnet:

    sudo apt-get install telnet
    
  3. מהטרמינל, מתחברים באמצעות Telnet לכתובת ה-IP של המכונה. מחליפים את VARIABLES בערכים המתאימים.

    telnet INSTANCE_IP_ADDRESS 6379
    

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

    Trying INSTANCE_IP_ADDRESS…
    Connected to INSTANCE_IP_ADDRESS
    
  4. בסשן של telnet, מזינים כמה פקודות Redis:

    צריך להזין את הפרטים הבאים:

    PING
    

    תוצאה:

    PONG
    

    Enter

    SET HELLO WORLD
    

    תוצאה:

    +OK
    

    צריך להזין את הפרטים הבאים:

    GET HELLO
    

    תוצאה:

    $5
    WORLD
    

הסרת המשאבים

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

  1. כדי למחוק את המופע, מזינים את הפקודה הבאה:

    gcloud redis instances delete myinstance --region=us-central1
  2. כדי לאשר את המחיקה, מזינים Y:

    You are about to delete instance [myinstance] in [us-central1].
    Any associated data will be lost.
    Do you want to continue (Y/n)? Y
    Delete request issued for: [myinstance]

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

    Deleted instance [myinstance].

  3. אופציונלי. אם יצרתם מכונה וירטואלית ב-Compute Engine לצורך המדריך למתחילים הזה, צריך למחוק אותה.

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