使用 gcloud CLI 建立 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.
-
Make sure 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.
-
Make sure that billing is enabled for your Google Cloud project.
- 如果尚未安裝 Google Cloud CLI,請先安裝。
系統提示時,請選擇在上方選取或建立的專案。
如果您已安裝 Google Cloud CLI,請更新。
gcloud components update
建立 Memorystore for Redis 執行個體
如要建立 Memorystore for Redis 執行個體,請按照下列步驟操作:
- 開啟終端機視窗。
輸入下列指令,將您要建立執行個體的專案設定為
gcloud
的預設專案:gcloud config set core/project PROJECT_ID
輸入下列指令,在
us-central1
區域建立 2 GiB 基本級 Redis 執行個體:gcloud redis instances create myinstance --size=2 --region=us-central1 \ --redis-version=redis_6_x
執行個體建立完成後,請輸入
describe
指令以取得執行個體的 IP 位址和通訊埠:gcloud redis instances describe myinstance --region=us-central1
如果成功,
gcloud
會傳回下列內容: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
您將會使用
host
和port
的值連線至執行個體。
從 Compute Engine VM 連線至 Redis 執行個體
您可以從使用 Redis 執行個體授權網路的任何 Compute Engine VM,透過支援的 RFC 1918 IP 位址連線至 Redis 執行個體。
Compute Engine VM 必須與 Redis 執行個體使用相同授權網路,如果不存在這樣的 VM,請按照快速入門導覽課程:使用 Linux VM 來建立及連線至 VM。
使用
apt-get
安裝telnet
:sudo apt-get install telnet
在終端機中,透過 telnet 連線至 Redis 執行個體的 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 帳戶收取這個快速入門導覽課程所用資源的費用,請輸入下列指令來刪除執行個體:
gcloud redis instances delete myinstance --region=us-central1
輸入
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]
如果成功,
gcloud
會傳回下列回應:Deleted instance [myinstance].
後續步驟
- 進一步瞭解如何建立及管理執行個體。
- 瞭解連線至 Redis 執行個體的其他方式。
- 瞭解 Redis 執行個體的特性。