使用 Google Cloud 控制台建立 Memorystore for Redis 執行個體

瞭解如何建立 Memorystore for Redis 執行個體、連線至該執行個體,然後刪除執行個體。


如要直接在 Google Cloud 控制台中,按照這項工作的逐步指南操作,請按一下「Guide me」(逐步引導)

「Guide me」(逐步引導)


事前準備

  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

必要的角色

如要取得建立 Memorystore for Redis 執行個體所需的權限,請要求管理員授予您專案的下列 IAM 角色:

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。

您或許也能透過自訂角色或其他預先定義的角色,取得必要權限。

建立 Memorystore for Redis 執行個體

在本節中,您將建立位於 us-central1 區域的 2 GB Memorystore for Redis 執行個體,並採用 Basic 級。如要進一步瞭解層級資訊,請參閱「Redis 層級功能」。

  1. 在 Google Cloud 控制台中,前往「Memorystore for Redis」頁面。

    Memorystore for Redis

  2. 點選「建立執行個體」

  3. 在「建立 Redis 執行個體」頁面中,為要建立的執行個體進行下列設定:

    • 在「Instance ID」(執行個體 ID) 欄位中輸入 my-instance-1
    • 在「Display name」(顯示名稱) 欄位中,輸入 My Quickstart Instance
    • 在「層級選取」部分,選取「基本」。這個層級會指定獨立的 Redis 節點,而非標準層級,後者會使用備用節點備份資料。
    • 在「容量」欄位中輸入 5。這會將執行個體的容量設為 5 GB。
    • 從「Region」(區域) 選單中,選取「us-central1 (Iowa)」(us-central1 (愛荷華州))
    • 從「Network」(網路) 選單中,選取「default」(預設)
    • 展開「Configuration」節點,然後從「Version」選單中,選取「7.2 (Recommended)」
  4. 點選「建立執行個體」

  5. 建立執行個體後,請按照下列步驟取得執行個體的 IP address

    1. 前往 Google Cloud 控制台的「Memorystore for Redis」頁面。
      Memorystore for Redis
    2. 按一下執行個體的 ID:my-instance-1
    3. 在「連線」部分,記下執行個體的「主要端點」和「連接埠」編號 6379。您需要端點和通訊埠編號,才能連線至執行個體。

從 Compute Engine VM 連線至 Memorystore for Redis 執行個體

您可以從任何使用執行個體授權網路的 Compute Engine VM,連線至 Memorystore for Redis 執行個體,並使用支援的 RFC 1918 IP 位址

  1. 如果沒有與執行個體使用相同授權網路的 Compute Engine VM,請建立一個並使用 SSH 連線至 VM。如要這麼做,請按照「在 Compute Engine 中建立 Linux VM 執行個體」一文中的步驟操作。

  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. 前往 Google Cloud 控制台的「Memorystore for Redis」頁面。
    Memorystore for Redis
  2. 按一下要刪除的執行個體 ID。
  3. 點選「刪除」。
  4. 在隨即顯示的提示中輸入執行個體 ID。
  5. 點選「刪除」。
  6. (選用) 如果您為這個快速入門導覽課程建立了 Compute Engine VM,請刪除該 VM。

後續步驟