使用 Google Cloud 控制台建立 Dataproc 叢集
本頁說明如何使用 Google Cloud 控制台建立 Dataproc 叢集、在叢集中執行基本 Apache Spark 工作,然後修改叢集中的工作站數量。
如要直接在 Google Cloud 控制台按照逐步指南操作,請按一下「Guide me」(逐步引導):
事前準備
- 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.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Dataproc API.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Dataproc API.
建立叢集
在 Google Cloud 控制台中,前往 Dataproc「Clusters」(叢集) 頁面。
按一下 [Create cluster] (建立叢集)。
在「Create Dataproc cluster」(建立 Dataproc 叢集) 對話方塊中,按一下「Clusters on Compute Engine」(Compute Engine 上的叢集) 列中的「Create」(建立)。
在「Cluster name」(叢集名稱) 欄位中輸入
example-cluster
。在「Region」(區域) 和「Zone」(可用區) 清單中,選取區域和可用區。
選取區域 (例如
us-east1
或europe-west1
) 即可隔離該區域中的資源,例如虛擬機器 (VM) 執行個體,以及 Dataproc 使用的 Cloud Storage 和中繼資料儲存位置。詳情請參閱「可用的地區和區域」和「地區端點」。其他選項請使用預設設定。
如要建立叢集,請按一下「建立」。
新的叢集會列在「叢集」頁面的清單中。在叢集準備好可供使用之前,狀態會顯示為「佈建中」,之後狀態會變更為「執行中」。佈建叢集可能需要幾分鐘的時間。
提交 Spark 工作
提交可估算圓周率值的 Spark 工作:
- 在 Dataproc 導覽選單中,按一下「Jobs」。
在「工作」頁面中,按一下
「提交工作」,然後執行下列操作:- 在「Job ID」欄位中,使用預設設定,或提供專屬於 Google Cloud 專案的 ID。
- 在「叢集」下拉式選單中,選取
example-cluster
。 - 在「Job type」(工作類型) 中,選取「Spark」。
- 在「Main class or jar」(主要類別或 jar) 欄位中輸入
org.apache.spark.examples.SparkPi
。 - 在「Jar files」欄位中輸入
file:///usr/lib/spark/examples/jars/spark-examples.jar
。 在「Arguments」欄位中輸入
1000
來設定工作數。按一下「提交」。
工作會顯示在「Job details」頁面上。工作狀態為「執行中」或「開始」,提交後會變更為「已完成」。
如要避免輸出內容捲動,請按一下「Line wrap: off」。輸出內容會類似以下內容:
Pi is roughly 3.1416759514167594
如要查看工作詳細資料,請按一下「Configuration」(設定) 分頁標籤。
更新叢集
變更工作站執行個體數量來更新叢集:
- 在 Dataproc 導覽選單中,按一下「Clusters」。
- 在叢集清單中,按一下「
example-cluster
」。 在「Cluster details」(叢集詳細資料) 頁面中,按一下「Configuration」(設定) 分頁標籤。
畫面上會顯示叢集設定。
按一下「Edit」(編輯)
。在「工作站節點數」欄位中輸入
5
。按一下 [儲存]。
叢集已更新完成,如要將工作站節點數減至原始值,請遵循相同的程序。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取您在本頁所用資源的費用,請按照下列步驟操作。
- 如要刪除叢集,請在
example-cluster
的「Cluster details」頁面中,按一下 「Delete」。 - 按一下「Delete」(刪除),確認刪除叢集。
後續步驟
- 請試著使用其他工具來執行本快速入門導覽課程:
- 瞭解如何在建立專案時建立完善的防火牆規則。
- 瞭解如何編寫及執行 Spark Scala 工作。