使用 Google Cloud 控制台创建 Memorystore for Redis 实例
了解如何创建 Memorystore for Redis 实例、连接该实例以及将其删除。
如需在 Google Cloud 控制台中直接遵循有关此任务的分步指导,请点击操作演示:
准备工作
- 登录您的 Google Cloud 账号。如果您是 Google Cloud新手, 请创建一个账号来评估我们的产品在 实际场景中的表现。新客户还可获享 $300 赠金,用于 运行、测试和部署工作负载。
-
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.
-
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.
-
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.
-
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.
-
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.
所需角色
如需获得创建 Memorystore for Redis 实例所需的权限,请让管理员向您授予项目的以下 IAM 角色:
-
Cloud Memorystore Redis Admin (
roles/redis.admin) -
Compute Instance Admin (v1) (
roles/compute.instanceAdmin.v1) -
Service Account User (
roles/iam.serviceAccountUser)
如需详细了解如何授予角色,请参阅管理对项目、文件夹和组织的访问权限。
创建 Memorystore for Redis 实例
在本部分中,您将创建一个 2 GB 的 Memorystore for Redis 实例,该实例位于 us-central1 区域,并且属于基本层级。如需详细了解层级,请参阅 Redis 层级功能。
在 Google Cloud 控制台中,前往 Memorystore for Redis 页面。
点击创建实例 。
在创建 Redis 实例 页面中,为要创建的实例进行以下配置:
- 在实例 ID 字段中,输入
my-instance-1。 - 在显示名称 字段中,输入
My Quickstart Instance。 - 在层级选择 部分中,选择基本 。此层级指定独立的 Redis 节点,而标准层级则使用副本节点来备份数据。
- 在容量 字段中,输入
5。这会将您的实例容量设置为 5 GB。 - 在区域 菜单中,选择 us-central1(爱荷华) 。
- 在网络 菜单中,选择默认 。
- 展开配置 节点,然后在版本 菜单中,
选择
7.2(推荐)。
- 在实例 ID 字段中,输入
点击创建实例 。
创建实例后,请按照以下步骤获取实例的
IP address:- 在 Google Cloud 控制台中,前往 Memorystore for Redis 页面。
Memorystore for Redis - 点击实例的 ID:
my-instance-1。 - 在连接 部分中,记下实例的
主端点 和端口 号
6379。您需要使用端点和端口号来连接到实例。
- 在 Google Cloud 控制台中,前往 Memorystore for Redis 页面。
从 Compute Engine 虚拟机连接到 Memorystore for Redis 实例
您可以从任何具有支持的 RFC 1918 IP 地址且使用实例的授权网络的 Compute Engine 虚拟机连接到 Memorystore for Redis 实例。
如果您没有与实例使用同一授权网络的 Compute Engine 虚拟机,请创建一个虚拟机并使用 SSH 连接到该虚拟机。为此,请按照在 Compute Engine 中创建 Linux 虚拟机实例中的步骤操作。
使用
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
输入
SET HELLO WORLD
结果:
+OK
请输入:
GET HELLO
结果:
$5 WORLD
清理
为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。
- 在 Google Cloud 控制台中,前往 Memorystore for Redis 页面。
Memorystore for Redis - 点击要删除的实例的 ID。
- 点击删除 。
- 在出现的提示符处,输入实例 ID。
- 点击删除 。
- 可选 。如果您为此快速入门创建了 Compute Engine 虚拟机, 请将其删除。
后续步骤
- 详细了解如何创建和管理实例。
- 了解其他连接到 Redis 实例的方式。
- 了解 Redis 实例的特性。