使用 Google Cloud 控制台建立 Memorystore for Redis 執行個體
瞭解如何建立 Memorystore for Redis 執行個體、連線至該執行個體,然後刪除執行個體。
如要直接在 Google Cloud 控制台中,按照這項工作的逐步指南操作,請按一下「Guide me」(逐步引導):
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
如要使用現有專案進行本指南中的操作,請確認您具有完成本指南所需的權限。如果您建立新專案,則已具備必要權限。
-
Verify that billing is enabled for your Google Cloud project.
-
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 theserviceusage.services.enablepermission. Learn how to grant roles. -
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
如要使用現有專案進行本指南中的操作,請確認您具有完成本指南所需的權限。如果您建立新專案,則已具備必要權限。
-
Verify that billing is enabled for your Google Cloud project.
-
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 theserviceusage.services.enablepermission. Learn how to grant roles. -
Cloud Memorystore Redis 管理員 (
roles/redis.admin) -
Compute 執行個體管理員 (v1) (
roles/compute.instanceAdmin.v1) -
服務帳戶使用者 (
roles/iam.serviceAccountUser)
必要的角色
如要取得建立 Memorystore for Redis 執行個體所需的權限,請要求管理員在專案中授予您下列 IAM 角色:
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和組織的存取權」。
建立 Memorystore for Redis 執行個體
在本節中,您將在 us-central1 區域建立 2 GB 的 Memorystore for Redis 執行個體,並使用基本級方案。如要進一步瞭解層級資訊,請參閱「Redis 層級功能」。
在 Google Cloud 控制台中,前往「Memorystore for Redis」頁面。
點選「建立執行個體」。
在「建立 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)」
。
- 在「Instance ID」(執行個體 ID) 欄位中輸入
點選「建立執行個體」。
建立執行個體後,請按照下列步驟取得執行個體的
IP address:- 前往 Google Cloud 控制台的「Memorystore for Redis」頁面。
Memorystore for Redis - 按一下執行個體的 ID:
my-instance-1。 - 在「Connections」(連線) 部分中,記下執行個體的「Primary Endpoint」(主要端點) 和「Port」(通訊埠) 編號
6379。您需要端點和通訊埠編號,才能連線至執行個體。
- 前往 Google Cloud 控制台的「Memorystore for Redis」頁面。
從 Compute Engine VM 連線至 Memorystore for Redis 執行個體
您可以從使用執行個體授權網路的任何 Compute Engine VM,透過支援的 RFC 1918 IP 位址連線至 Memorystore for Redis 執行個體。
如果沒有與執行個體使用相同授權網路的 Compute Engine VM,請建立一個並使用 SSH 連線至 VM。如要這麼做,請按照「在 Compute Engine 中建立 Linux VM 執行個體」一文中的步驟操作。
使用
apt-get安裝telnet:sudo apt-get install telnet在終端機中,透過 telnet 連線至執行個體的 IP 位址。將 VARIABLES 改為適當的值。
telnet INSTANCE_IP_ADDRESS 6379
如果可以連線至執行個體,指令會傳回下列結果:
Trying INSTANCE_IP_ADDRESS… Connected to INSTANCE_IP_ADDRESS
在 Telnet 工作階段中,輸入一些 Redis 指令:
輸入:
PING
結果:
PONG
Enter 鍵
SET HELLO WORLD
結果:
+OK
輸入:
GET HELLO
結果:
$5 WORLD
清除所用資源
為了避免系統向您的 Google Cloud 帳戶收取本頁面所用資源的費用,請按照下列步驟操作。
- 前往 Google Cloud 控制台的「Memorystore for Redis」頁面。
Memorystore for Redis - 按一下要刪除的執行個體 ID。
- 按一下「Delete」(刪除)。
- 在隨即顯示的提示中輸入執行個體 ID。
- 按一下「Delete」(刪除)。
- (選用) 如果您為這個快速入門導覽課程建立了 Compute Engine VM,請刪除該 VM。
後續步驟
- 進一步瞭解如何建立及管理執行個體。
- 瞭解連線至 Redis 執行個體的其他方式。
- 瞭解 Redis 執行個體的特性。