Terraform을 사용하여 Memorystore for Redis 클러스터 인스턴스 만들기

이 빠른 시작에서는 Terraform을 사용하여 새 Memorystore for Redis Cluster 인스턴스를 만드는 방법을 보여줍니다. 또한 텔넷을 사용하여 인스턴스에 연결하는 방법도 보여줍니다.

이 빠른 시작에서는 새 Terraform 파일을 시작한다고 가정하며 Google Cloud 제공업체를 설정하기 위한 Terraform 리소스를 포함합니다. 하지만 Google Cloud 제공업체로 Terraform 파일을 인증하는 단계는 생략되어 있습니다.

Google Cloud 제공업체로 Terraform을 인증하는 방법은 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 (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that billing is enabled for your Google Cloud project.

  4. 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 (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  5. Verify that billing is enabled for your Google Cloud project.

  6. 아직 설치하지 않았으면 Google Cloud SDK를 설치합니다.

    메시지가 나타나면 위에서 선택하거나 만든 프로젝트를 선택합니다.

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

    gcloud components update
  8. Memorystore for Redis Cluster API 사용 설정
    Redis용 Memorystore Cluster
  9. Memorystore용 Terraform 구성

    이 섹션에서는 Memorystore for Redis Cluster 인스턴스를 만드는 데 필요한 5가지 Terraform 리소스의 예를 보여줍니다.

    • Google Cloud 제공업체 구성입니다.

    • Memorystore 인스턴스 구성입니다. 이 가이드에서는 us-central1 리전에 redis-highmem-medium 노드가 3개 있는 39GB 클러스터입니다.

    • Private Service Connect 서비스 연결 정책입니다.

    • 인스턴스의 서브넷입니다.

    • 인스턴스의 네트워크입니다.

    이러한 Terraform 리소스를 추가하는 방법은 다음과 같습니다.

    1. Terraform 구성 파일에 다음 리소스를 추가합니다.

      
      provider "google" {
        project = "PROJECT_ID"
      }
      
      resource "google_redis_cluster" "cluster-ha" {
        name           = "CLUSTER_ID"
        shard_count    = 3
        psc_configs {
          network = google_compute_network.producer_net.id
        }
        region = "us-central1"
        replica_count = 1
        depends_on = [
          google_network_connectivity_service_connection_policy.default
        ]
      
      }
      
      resource "google_network_connectivity_service_connection_policy" "default" {
        name = "POLICY_NAME"
        location = "us-central1"
        service_class = "gcp-memorystore-redis"
        description   = "my basic service connection policy"
        network = google_compute_network.producer_net.id
        psc_config {
          subnetworks = [google_compute_subnetwork.producer_subnet.id]
        }
      }
      
      resource "google_compute_subnetwork" "producer_subnet" {
        name          = "SUBNET_ID"
        ip_cidr_range = "10.0.0.248/29"
        region        = "us-central1"
        network       = google_compute_network.producer_net.id
      }
      
      resource "google_compute_network" "producer_net" {
        name                    = "NETWORK_ID"
        auto_create_subnetworks = false
      }
      
      

      다음을 바꿉니다.

      • PROJECT_ID은 인스턴스의 프로젝트 ID입니다.
      • CLUSTER_ID은 만들려는 Memorystore for Redis Cluster 인스턴스의 ID입니다. ID는 1~63자(영문 기준)여야 하며 소문자, 숫자 또는 하이픈만 사용해야 합니다. 소문자로 시작하고 소문자나 숫자로 끝나야 합니다.
      • POLICY_NAME은 프로젝트의 Private Service Connect 서비스 연결 정책에 대해 선택한 이름입니다. 서비스 연결 정책에 대한 자세한 내용은 네트워킹을 참고하세요.
      • SUBNET_ID는 이 예에서 생성되고 Memorystore 클러스터에서 사용되는 서브넷의 선택된 ID입니다.
      • NETWORK_ID는 이 예에서 생성되고 Memorystore 클러스터에서 사용되는 네트워크의 선택된 ID입니다.

    Terraform 구성 파일 배포

    1. terraform init를 실행합니다.

    2. terraform plan를 실행합니다.

    3. terraform apply를 실행합니다.

    Compute Engine VM에서 인스턴스에 연결

    그런 다음 새로 만든 Memorystore for Redis Cluster 인스턴스에 연결합니다.

    인스턴스의 승인된 네트워크를 사용하는 모든 Compute Engine VM에서 인스턴스에 연결할 수 있습니다.

    1. 인스턴스와 동일한 승인된 네트워크를 사용하는 Compute Engine VM이 아직 없으면 빠른 시작: Linux VM 사용을 따라 VM을 만들고 연결합니다.

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

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

      telnet CLUSTER_DISCOVERY_ENDPOINT_IP_ADDRESS CLUSTER_DISCOVERY_ENDPOINT_PORT_NUMBER
      
    4. 텔넷 세션에서 몇 가지 Redis 명령어를 입력합니다.

      입력:

      PING
      

      결과:

      PONG
      

    삭제

    이 빠른 시작에서 사용한 리소스의 비용이 Google Cloud 계정에 청구되지 않도록 하려면 다음 단계를 따라 Redis 인스턴스를 삭제하세요.

    1. Terraform 구성 파일에서 google_redis_instance 리소스를 삭제합니다.
    2. Terraform init, plan, apply를 실행하여 Redis 리소스를 삭제합니다.
    3. 이 빠른 시작에서 만든 Compute Engine VM을 삭제합니다.

    여러 VPC 네트워크를 설정하도록 Terraform 구성

    이 페이지의 섹션에서는 Memorystore for Redis 클러스터 인스턴스를 만들고 Virtual Private Cloud (VPC) 네트워크에서 연결을 설정하는 예를 보여줍니다. Terraform을 사용하여 여러 VPC 네트워크에서 연결을 설정하는 방법과 예시를 확인하려면 google_redis_cluster_user_created_connections 페이지를 참고하세요.

다음 단계