使用 Google Cloud 控制台建立 Dataproc 叢集
本頁說明如何使用 Google Cloud 控制台建立 Dataproc 叢集、在叢集中執行基本的 Apache Spark 工作,然後修改叢集中的 worker 數量。
如要直接在 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.
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Dataproc API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles. -
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 theresourcemanager.projects.createpermission. Learn how to grant roles.
-
Verify that billing is enabled for your Google Cloud project.
-
Enable the Dataproc API.
Roles required to enable APIs
To enable APIs, you need the Service Usage Admin IAM role (
roles/serviceusage.serviceUsageAdmin), which contains theserviceusage.services.enablepermission. Learn how to grant roles.
建立叢集
前往 Google Cloud 控制台的 Dataproc「Clusters」(叢集) 頁面。
按一下 [Create cluster] (建立叢集)。
在「Create Dataproc cluster」(建立 Dataproc 叢集) 對話方塊中,按一下「Cluster on Compute Engine」(Compute Engine 上的叢集) 列中的「Create」(建立)。
在「Cluster name」(叢集名稱) 欄位中輸入
example-cluster。在「Region」(區域) 和「Zone」(可用區) 清單中,選取區域和可用區。
選取一個區域 (例如
us-east1或europe-west1),即可將 Dataproc 所使用的資源 (如虛擬機器 (VM) 執行個體、Cloud Storage 及中繼資料儲存位置) 隔離在該區域中。詳情請參閱「適用區域及可用區」和「區域端點」。所有其他選項請使用預設設定。
如要建立叢集,請按一下「Create」(建立)。
新叢集會顯示在「Clusters」(叢集)頁面的清單中。在叢集準備好可以使用之前,狀態會顯示為「Provisioning」(佈建中),之後狀態就會變更為「Running」(執行中)。佈建叢集可能需要幾分鐘。
提交 Spark 工作
提交估算圓周率的 Spark 工作:
- 在 Dataproc 導覽選單中,按一下「Jobs」(工作)。
在「Jobs」(工作)頁面中,按一下 「Submit job」(提交工作),然後執行下列操作:
- 請在「Job ID」(工作 ID) 欄位中使用預設設定,或提供 Google Cloud 專案專屬的唯一 ID。
- 在「Cluster」(叢集) 下拉式選單中,選取「
example-cluster」。 - 在「Job type」(工作類型) 區段選取「Spark」。
- 在「Main class or jar」(主要類別或 jar) 欄位輸入
org.apache.spark.examples.SparkPi。 - 在「Jar files」(Jar 檔案) 欄位輸入
file:///usr/lib/spark/examples/jars/spark-examples.jar。 在「Arguments」(引數) 欄位輸入
1000以設定工作數量。按一下「Submit」(提交)。
「Job details」(工作詳細資料) 頁面會顯示您的工作。工作狀態為「Running」(執行中)或「Starting」(啟動中),提交後會變更為「Succeeded」(已成功)。
如要避免在輸出內容中捲動,請按一下「Line wrap: off」(換行:關閉)。輸出內容大致如下:
Pi is roughly 3.1416759514167594
如要查看工作詳細資料,請按一下「Configuration」(設定) 分頁標籤。
更新叢集
若要更新叢集,請變更 worker 執行個體的數量,方法如下:
- 在 Dataproc 導覽選單中,按一下「Clusters」(叢集)。
- 在叢集清單中,按一下「
example-cluster」。 在「Cluster details」(叢集詳細資料) 頁面中,按一下「Configuration」(設定) 分頁標籤。
系統會顯示叢集設定。
按一下「Edit」(編輯)。
在「Worker 節點數」欄位中輸入
5。按一下「Save」(儲存)。
此時,叢集即已更新完成,如要將 worker 節點數減至原始值,請按照相同程序操作。
清除所用資源
為了避免系統向您的 Google Cloud 帳戶收取本頁面所用資源的費用,請按照下列步驟操作。
- 如要刪除叢集,請在「
example-cluster」的「Cluster details」(叢集詳細資料) 頁面中,按一下「Delete」(刪除)。 - 按一下「Delete」(刪除),確認刪除叢集。
後續步驟
- 請試著使用其他工具來執行本快速入門導覽課程:
- 瞭解如何在建立專案時建立完善的防火牆規則。
- 瞭解如何編寫及執行 Spark Scala 工作。