使用 Google Cloud 控制台创建 Memorystore for Memcached 实例
本快速入门将引导您完成创建 Memorystore for Memcached 实例、连接到实例、设置值、检索值以及删除实例的步骤。
准备工作
- 登录您的 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.
-
Verify that billing is enabled for your Google Cloud project.
-
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.
-
为您的项目启用 Service Networking API。
启用 Service Networking API。 -
为您的项目启用 Memorystore for Memcached API。
启用 Memorystore for Memcached API
创建 Memcached 实例
前往 Google Cloud 控制台中的 Memorystore for Memcached 页面。
Memorystore for Memcached点击创建实例 按钮。
在控制台中的 Google Cloud 创建 Memcached 实例 页面上选择新实例的配置:
- 请仅使用小写字母、数字和连字符输入实例 ID。
以字母开头。
- 例如
my-memcached-instance-1。
- 例如
- 从区域下拉列表中选择
us-central1。 - 从地区下拉列表中选择
Automatically distribute。 - 在节点下输入
2以创建两个节点。 - 选择每个节点的内存 1 GB。
- 选择每个节点的核心数 1。
为已获授权的网络选择
default。
- 请仅使用小写字母、数字和连字符输入实例 ID。
以字母开头。
点击创建。
创建实例后,点击实例 ID 查看实例详细信息页面。
记下其中一个节点的
IP address。
从 Compute Engine 虚拟机连接到您的实例
要测试连接,请执行以下操作:
连接到 Linux 虚拟机。如需了解连接到 Linux 虚拟机的步骤,请参阅快速入门:使用 Linux 虚拟机。如果您按照快速入门中的说明使用了基于 Debian 的映像创建虚拟机实例,请使用
apt-get安装telnet:sudo apt-get install telnet从该终端,通过 Telnet 连接到其中一个 Memcached 节点的 IP 地址。将 node-ip-address 替换为节点的 IP 地址。
telnet node-ip-address 11211
您应该会看到以下输出,其中
[bracketed-variables]替换了项目的变量:Trying [node-ip-address]… Connected to [node-ip-address]
在 telnet 会话中,输入一些 Memcached 命令:
输入:
get greeting
结果:
END
请输入:
set greeting 1 0 11 hello world
结果:
STORED
请输入:
get greeting
Result:
VALUE greeting 1 11 hello world END
Memorystore for Memcached 支持标准开源 Memcached 库。
清理
为避免因本页中使用的资源导致您的 Google Cloud 账号产生费用,请按照以下步骤操作。
前往 Google Cloud 控制台中的 Memorystore for Memcached 页面。
Memorystore for Memcached点击要删除的实例的 ID。
点击删除按钮。
在显示的提示中,输入实例的 ID。
点击删除按钮。