Membuat instance Memorystore for Redis menggunakan gcloud CLI

Pelajari cara membuat instance Memorystore for Redis, menghubungkannya, lalu menghapusnya.


Untuk mengikuti panduan langkah demi langkah untuk tugas ini langsung di Google Cloud konsol, klik Pandu saya:

Pandu saya


Sebelum memulai

  1. 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.
  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. Jika Anda menggunakan project yang sudah ada untuk panduan ini, pastikan Anda memiliki izin yang diperlukan untuk menyelesaikan panduan ini. Jika berhasil membuat project baru, berarti Anda sudah memiliki izin yang diperlukan.

  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. Jika Anda menggunakan project yang sudah ada untuk panduan ini, pastikan Anda memiliki izin yang diperlukan untuk menyelesaikan panduan ini. Jika berhasil membuat project baru, berarti Anda sudah memiliki izin yang diperlukan.

  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

  10. Jika Anda belum melakukannya, instal Google Cloud CLI.

    Saat diminta, pilih project yang Anda pilih atau buat.

  11. Jika Anda sudah menginstal Google Cloud CLI, update.

    gcloud components update
  12. Peran yang diperlukan

    Untuk mendapatkan izin yang Anda perlukan guna membuat instance Memorystore for Redis, minta administrator untuk memberi Anda peran IAM berikut pada project:

    Untuk mengetahui informasi selengkapnya tentang pemberian peran, lihat Mengelola akses ke project, folder, dan organisasi.

    Anda mungkin juga bisa mendapatkan izin yang diperlukan melalui peran khusus atau peran bawaan lainnya.

Buat instance Memorystore for Redis

Di bagian ini, Anda akan membuat instance Memorystore for Redis 2 GB yang berada di region us-central1 dan menggunakan paket Dasar. Untuk mengetahui informasi selengkapnya tentang tingkat, lihat Kemampuan tingkat Redis.

  1. Buka jendela terminal.
  2. Untuk menetapkan project tempat Anda ingin membuat instance sebagai project default, masukkan perintah berikut:

    gcloud config set core/project PROJECT_ID
    
  3. Untuk membuat instance Redis Tingkat Dasar 2 GiB di region us-central1, masukkan perintah berikut:

    gcloud redis instances create myinstance --size=2 --region=us-central1 \
    --redis-version=redis_6_x
    
  4. Setelah membuat instance, untuk mendapatkan alamat IP dan nomor port instance, masukkan perintah berikut:

    gcloud redis instances describe myinstance --region=us-central1
    

    Jika Anda dapat mengakses instance, perintah akan menampilkan hasil ini:

    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

  5. Catat nilai host dan port instance Anda. Anda memerlukan nilai-nilai ini untuk terhubung ke instance.

Menghubungkan ke instance Memorystore for Redis dari VM Compute Engine

Anda dapat terhubung ke instance Memorystore for Redis dari VM Compute Engine mana pun yang menggunakan jaringan resmi instance dengan alamat IP RFC 1918 yang didukung.

  1. Jika Anda tidak memiliki VM Compute Engine yang menggunakan jaringan resmi yang sama dengan instance Anda, buat VM tersebut, lalu hubungkan ke VM menggunakan SSH. Untuk melakukannya, ikuti langkah-langkah di Membuat instance VM Linux di Compute Engine.

  2. Gunakan apt-get untuk menginstal telnet:

    sudo apt-get install telnet
    
  3. Dari terminal, telnet ke alamat IP instance. Ganti VARIABLES dengan nilai yang sesuai.

    telnet INSTANCE_IP_ADDRESS 6379
    

    Jika Anda dapat terhubung ke instance, perintah akan menampilkan hasil ini:

    Trying INSTANCE_IP_ADDRESS…
    Connected to INSTANCE_IP_ADDRESS
    
  4. Dalam sesi telnet, masukkan beberapa perintah Redis:

    Enter:

    PING
    

    Hasil:

    PONG
    

    Enter

    SET HELLO WORLD
    

    Hasil:

    +OK
    

    Enter:

    GET HELLO
    

    Hasil:

    $5
    WORLD
    

Pembersihan

Agar akun Google Cloud Anda tidak dikenai biaya untuk resource yang digunakan pada halaman ini, ikuti langkah-langkah berikut.

  1. Untuk menghapus instance, masukkan perintah berikut:

    gcloud redis instances delete myinstance --region=us-central1
  2. Untuk mengonfirmasi penghapusan, masukkan 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]

    Jika Anda dapat menghapus instance, perintah akan menampilkan hasil ini:

    Deleted instance [myinstance].

  3. Opsional. Jika Anda membuat VM Compute Engine untuk panduan memulai ini, hapus VM tersebut.

Langkah berikutnya