gcloud CLI를 사용하여 Memorystore for Redis 인스턴스 만들기

Redis용 Memorystore 인스턴스를 만들고, 연결하고, 삭제하는 방법을 알아봅니다.


Google Cloud 콘솔에서 이 태스크에 대한 단계별 안내를 직접 수행하려면 둘러보기를 클릭합니다.

둘러보기


시작하기 전에

  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. 이 가이드에 기존 프로젝트를 사용하는 경우 이 가이드를 완료하는 데 필요한 권한이 있는지 확인합니다. 새 프로젝트를 만든 경우 필요한 권한이 이미 있습니다.

  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. 이 가이드에 기존 프로젝트를 사용하는 경우 이 가이드를 완료하는 데 필요한 권한이 있는지 확인합니다. 새 프로젝트를 만든 경우 필요한 권한이 이미 있습니다.

  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. 아직 설치하지 않았으면 Google Cloud CLI를 설치합니다.

    메시지가 표시되면 선택하거나 만든 프로젝트를 선택합니다.

  11. Google Cloud CLI가 이미 설치되어 있으면 업데이트합니다.

    gcloud components update
  12. 필요한 역할

    Memorystore for Redis 인스턴스를 만드는 데 필요한 권한을 얻으려면 관리자에게 프로젝트에 대한 다음 IAM 역할을 부여해 달라고 요청하세요.

    역할 부여에 대한 자세한 내용은 프로젝트, 폴더, 조직에 대한 액세스 관리를 참조하세요.

    커스텀 역할이나 다른 사전 정의된 역할을 통해 필요한 권한을 얻을 수도 있습니다.

Redis용 Memorystore 인스턴스 만들기

이 섹션에서는 us-central1 리전에 있고 기본 등급인 2GB Memorystore for Redis 인스턴스를 만듭니다. 등급에 대한 자세한 내용은 Redis 등급 기능을 참고하세요.

  1. 터미널 창을 엽니다.
  2. 인스턴스를 만들 프로젝트를 기본 프로젝트로 설정하려면 다음 명령어를 입력합니다.

    gcloud config set core/project PROJECT_ID
    
  3. us-central1 리전에 2GiB 기본 등급 Redis 인스턴스를 만들려면 다음 명령어를 입력합니다.

    gcloud redis instances create myinstance --size=2 --region=us-central1 \
    --redis-version=redis_6_x
    
  4. 인스턴스를 만든 후 인스턴스의 IP 주소와 포트 번호를 가져오려면 다음 명령어를 입력합니다.

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

    인스턴스에 액세스할 수 있으면 명령어가 다음 결과를 반환합니다.

    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. 인스턴스의 hostport 값을 기록해 둡니다. 인스턴스에 연결하려면 이 값이 필요합니다.

Compute Engine VM에서 Memorystore for Redis 인스턴스에 연결

지원되는 RFC 1918 IP 주소를 사용하여 인스턴스의 승인된 네트워크를 사용하는 모든 Compute Engine VM에서 Redis용 Memorystore 인스턴스에 연결할 수 있습니다.

  1. 인스턴스와 동일한 승인된 네트워크를 사용하는 Compute Engine VM이 없으면 VM을 만들고 SSH를 사용하여 연결합니다. 이렇게 하려면 Compute Engine에서 Linux VM 인스턴스 만들기의 단계를 따르세요.

  2. apt-get를 사용하여 telnet을 설치합니다.

    sudo apt-get install telnet
    
  3. 터미널에서 인스턴스의 IP 주소를 텔넷으로 연결합니다. VARIABLES를 적절한 값으로 바꿉니다.

    telnet INSTANCE_IP_ADDRESS 6379
    

    인스턴스에 연결할 수 있으면 명령어가 다음 결과를 반환합니다.

    Trying INSTANCE_IP_ADDRESS…
    Connected to INSTANCE_IP_ADDRESS
    
  4. 텔넷 세션에서 몇 가지 Redis 명령어를 입력합니다.

    다음을 입력합니다.

    PING
    

    결과:

    PONG
    

    입력

    SET HELLO WORLD
    

    결과:

    +OK
    

    다음을 입력합니다.

    GET HELLO
    

    결과:

    $5
    WORLD
    

삭제

이 페이지에서 사용한 리소스 비용이 Google Cloud 계정에 청구되지 않도록 하려면 다음 단계를 수행합니다.

  1. 인스턴스를 삭제하려면 다음 명령어를 입력합니다.

    gcloud redis instances delete myinstance --region=us-central1
  2. 삭제를 확인하려면 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]

    인스턴스를 삭제할 수 있으면 명령어가 다음 결과를 반환합니다.

    Deleted instance [myinstance].

  3. 선택사항. 이 빠른 시작을 위해 Compute Engine VM을 만든 경우 삭제합니다.

다음 단계