Membuat cluster Dataproc menggunakan gcloud CLI

Halaman ini menunjukkan cara menggunakan alat command line Google Cloud CLI gcloud untuk membuat cluster Dataproc, menjalankan tugas Apache Spark dalam cluster, lalu mengubah jumlah pekerja dalam cluster.

Anda dapat mengetahui cara melakukan tugas yang sama atau serupa dengan Panduan Memulai Menggunakan API Explorer, Konsol Google Cloud di Membuat cluster Dataproc menggunakan Konsol Google Cloud, dan menggunakan library klien di Membuat cluster Dataproc menggunakan library klien.

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.

    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

Membuat cluster

Untuk membuat cluster bernama example-cluster, jalankan perintah berikut:

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

Output perintah mengonfirmasi pembuatan cluster:

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

Untuk informasi tentang cara memilih region, lihat Region & zona yang tersedia. Untuk melihat daftar region yang tersedia, Anda dapat menjalankan perintah gcloud compute regions list. Untuk mempelajari endpoint regional, lihat Endpoint regional.

Mengirim tugas

Untuk mengirimkan contoh tugas Spark yang menghitung nilai kasar untuk pi, jalankan perintah berikut:

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

Perintah ini menentukan hal berikut:

  • Anda ingin menjalankan tugas spark di cluster example-cluster di region yang ditentukan
  • class yang berisi metode utama untuk aplikasi penghitung pi tugas
  • Lokasi file jar yang berisi kode tugas Anda
  • Parameter apa pun yang ingin Anda teruskan ke tugas—dalam hal ini jumlah tugas, yang berjumlah 1000

Tugas sedang berjalan dan output terakhir ditampilkan di jendela terminal:

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

Mengupdate cluster

Untuk mengubah jumlah pekerja di cluster menjadi lima, jalankan perintah berikut:

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

Output perintah akan menampilkan detail cluster Anda. Contoh:

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.

Untuk mengurangi jumlah node pekerja ke nilai asli, gunakan perintah yang sama:

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

Pembersihan

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

  1. Untuk menghapus example-cluster, jalankan perintah clusters delete:

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

  2. Untuk mengonfirmasi dan menyelesaikan penghapusan cluster, tekan y, lalu tekan Enter saat diminta.

Langkah berikutnya