gcloud CLI를 사용하여 Dataproc 클러스터 만들기

이 페이지에서는 Google Cloud CLI gcloud 명령줄 도구를 사용하여 Dataproc 클러스터를 만들고, 클러스터에서 Apache Spark 작업을 실행한 다음 클러스터의 작업자 수를 수정하는 방법을 보여줍니다.

동일하거나 유사한 작업을 수행하는 방법은 API 탐색기를 사용한 빠른 시작, Google Cloud 콘솔을 사용하여 Dataproc 클러스터 만들기의 Google Cloud 콘솔, 클라이언트 라이브러리를 사용하여 Dataproc 클러스터 만들기의 클라이언트 라이브러리 사용을 참조하세요.

시작하기 전에

  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.

    Go to project selector

  3. Make sure that billing is enabled for your Google Cloud project.

  4. Enable the Dataproc API.

    Enable the API

  5. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

    Go to project selector

  6. Make sure that billing is enabled for your Google Cloud project.

  7. Enable the Dataproc API.

    Enable the API

클러스터 만들기

example-cluster라는 클러스터를 만들려면 다음 명령어를 실행합니다.

gcloud dataproc clusters create example-cluster --region=REGION

명령어 출력에서 클러스터 생성을 확인할 수 있습니다.

Waiting for cluster creation operation...done.
Created [... example-cluster]

리전 선택에 대한 자세한 내용은 사용 가능한 리전 및 영역을 참고하세요. 사용 가능한 리전 목록을 보려면 gcloud compute regions list 명령어를 실행합니다. 리전 엔드포인트에 대해 알아보려면 리전 엔드포인트를 참고하세요.

작업 제출

대략적인 pi 값을 계산하는 Spark 작업 샘플을 제출하려면 다음 명령을 실행합니다.

gcloud dataproc jobs submit spark --cluster example-cluster \
    --region=REGION \
    --class org.apache.spark.examples.SparkPi \
    --jars file:///usr/lib/spark/examples/jars/spark-examples.jar -- 1000

이 명령어는 다음을 지정합니다.

  • 지정된 리전의 example-cluster 클러스터에서 spark 작업을 실행하려는 경우
  • 작업에서 pi를 계산하는 애플리케이션의 기본 메서드가 포함된 class
  • 작업의 코드가 포함된 jar 파일의 위치
  • 작업에 전달할 매개변수. 이 경우 태스크의 수(1000)

작업의 실행과 최종 출력은 터미널 창에 표시됩니다.

Waiting for job output...
...
Pi is roughly 3.14118528
...
Job finished successfully.

클러스터 업데이트

클러스터의 작업자 수를 5로 변경하려면 다음 명령을 실행합니다.

gcloud dataproc clusters update example-cluster \
    --region=REGION \
    --num-workers 5

명령어 출력에 클러스터 세부정보가 표시됩니다. 예를 들면 다음과 같습니다.

workerConfig:
...
  instanceNames:
  - example-cluster-w-0
  - example-cluster-w-1
  - example-cluster-w-2
  - example-cluster-w-3
  - example-cluster-w-4
  numInstances: 5
statusHistory:
...
- detail: Add 3 workers.

작업자 노드 수를 기존 값으로 줄이려면 동일한 명령어를 사용합니다.

gcloud dataproc clusters update example-cluster \
    --region=REGION \
    --num-workers 2

삭제

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

  1. example-cluster를 삭제하려면 clusters delete 명령어를 실행합니다.

    gcloud dataproc clusters delete example-cluster \
        --region=REGION
    

  2. 클러스터 삭제를 확인하고 완료하려면 y를 누른 다음 메시지가 표시되면 Enter 키를 누릅니다.

다음 단계