使用 Google Cloud 控制台建立叢集

本頁說明如何使用 Google Cloud 控制台建立 Managed Service for Apache Spark 叢集、在叢集中執行基本的 Apache Spark 工作,然後修改叢集中的 worker 數量。


如要直接在 Google Cloud 控制台中,按照這項工作的逐步指南操作,請按一下「Guide me」(逐步引導)

「Guide me」(逐步引導)


事前準備

  1. 登入 Google Cloud 帳戶。如果您是 Google Cloud新手,歡迎 建立帳戶,親自評估產品在實際工作環境中的成效。新客戶還能獲得價值 $300 美元的免費抵免額,可用於執行、測試及部署工作負載。
  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 role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  3. Verify that you have the permissions required to complete this guide.

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

  5. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

  6. 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 the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  7. Verify that you have the permissions required to complete this guide.

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

  9. 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 the serviceusage.services.enable permission. Learn how to grant roles.

    Enable the API

必要的角色

如要執行本頁的範例,您必須具備特定 IAM 角色。視組織政策而定,系統可能已授予這些角色。如要檢查角色授予情形,請參閱「是否需要授予角色?」一節。

如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。

使用者角色

如要取得建立 Managed Service for Apache Spark 叢集所需的權限,請要求管理員授予您下列 IAM 角色:

  • 專案的 Dataproc 編輯者 (roles/dataproc.editor)
  • Compute Engine 預設服務帳戶的「服務帳戶使用者」 (roles/iam.serviceAccountUser)

服務帳戶角色

為確保 Compute Engine 預設服務帳戶具備建立 Managed Service for Apache Spark 叢集的必要權限,請要求管理員在專案中,將 Dataproc Worker (roles/dataproc.worker) IAM 角色授予 Compute Engine 預設服務帳戶。

建立叢集

  1. 前往 Google Cloud 控制台的「Managed Service for Apache Spark Clusters」(Apache Spark 叢集代管服務) 頁面。

    前往叢集

  2. 按一下 [Create cluster] (建立叢集)

  3. 在「Create Dataproc cluster」(建立 Dataproc 叢集) 對話方塊中,按一下「Cluster on Compute Engine」(Compute Engine 上的叢集) 列中的「Create」(建立)

  4. 在「Cluster name」(叢集名稱) 欄位中輸入 example-cluster

  5. 在「Region」(區域) 和「Zone」(可用區) 清單中,選取區域和可用區。

    選取一個區域 (例如 us-east1europe-west1),即可將 Managed Service for Apache Spark 所使用的資源 (如虛擬機器 (VM) 執行個體、Cloud Storage 及中繼資料儲存位置) 隔離在該區域中。詳情請參閱「適用區域及可用區」和「叢集區域」。

  6. 所有其他選項請使用預設設定。

  7. 如要建立叢集,請按一下「Create」(建立)

    新叢集會顯示在「Clusters」(叢集)頁面的清單中。在叢集準備好可以使用之前,狀態會顯示為「Provisioning」(佈建中),之後狀態就會變更為「Running」(執行中)。佈建叢集可能需要幾分鐘。

提交 Spark 工作

提交估算圓周率的 Spark 工作:

  1. 在 Managed Service for Apache Spark 導覽選單中,按一下「Jobs」(工作)
  2. 在「Jobs」(工作)頁面中,按一下 「Submit job」(提交工作),然後執行下列操作:

    1. 請在「Job ID」(工作 ID) 欄位中使用預設設定,或提供 Google Cloud 專案專屬的唯一 ID。
    2. 在「Cluster」(叢集) 下拉式選單中,選取「example-cluster」。
    3. 在「Job type」(工作類型) 區段選取「Spark」。
    4. 在「Main class or jar」(主要類別或 jar) 欄位輸入 org.apache.spark.examples.SparkPi
    5. 在「Jar files」(Jar 檔案) 欄位輸入 file:///usr/lib/spark/examples/jars/spark-examples.jar
    6. 在「Arguments」(引數) 欄位輸入 1000 以設定工作數量。

    7. 按一下「Submit」(提交)

      「Job details」(工作詳細資料) 頁面會顯示您的工作。工作狀態為「Running」(執行中)或「Starting」(啟動中),提交後會變更為「Succeeded」(已成功)

      如要避免在輸出內容中捲動,請按一下「Line wrap: off」(換行:關閉)。輸出內容大致如下:

      Pi is roughly 3.1416759514167594
      

      如要查看工作詳細資料,請按一下「Configuration」(設定) 分頁標籤。

更新叢集

若要更新叢集,請變更 worker 執行個體的數量,方法如下:

  1. 在 Managed Service for Apache Spark 導覽選單中,按一下「Clusters」(叢集)
  2. 在叢集清單中,按一下「example-cluster」。
  3. 在「Cluster details」(叢集詳細資料) 頁面中,按一下「Configuration」(設定) 分頁標籤。

    系統會顯示叢集設定。

  4. 按一下「Edit」(編輯)

  5. 在「Worker 節點數」欄位中輸入 5

  6. 按一下「Save」(儲存)

此時,叢集即已更新完成,如要將 worker 節點數減至原始值,請按照相同程序操作。

清除所用資源

為了避免系統向您的 Google Cloud 帳戶收取本頁面所用資源的費用,請按照下列步驟操作。

  1. 如要刪除叢集,請在「example-cluster」的「Cluster details」(叢集詳細資料) 頁面中,按一下「Delete」(刪除)
  2. 按一下「Delete」(刪除),確認刪除叢集。

後續步驟