以用戶端程式庫建立 Dataproc 叢集
以下程式碼範例說明如何使用 Cloud 用戶端程式庫建立 Dataproc 叢集、在叢集上執行工作,然後刪除叢集。
您也可以使用下列方法執行這些工作:
- API REST 要求 (請參閱「快速入門導覽課程:使用 API Explorer」)
- Google Cloud 控制台 (請參閱「使用 Google Cloud 控制台建立 Dataproc 叢集」)
- Google Cloud CLI (請參閱「使用 Google Cloud CLI 建立 Dataproc 叢集」)
事前準備
- 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. - 安裝用戶端程式庫 詳情請參閱「設定 Java 開發環境」。
- 設定驗證方法
- 複製並執行 GitHub 程式碼範例。
- 查看輸出內容。程式碼會將作業驅動程式記錄檔輸出至 Cloud Storage 的預設 Dataproc 暫存 bucket。您可以在專案的 Dataproc「Jobs」(工作) 專區,透過 Google Cloud 控制台查看工作驅動程式輸出內容。按一下「Job ID」(工作 ID),即可在「Job details」(工作詳細資料) 頁面查看工作輸出內容。
- 安裝用戶端程式庫 詳情請參閱「設定 Node.js 開發環境」。
- 設定驗證方法
- 複製並執行 GitHub 程式碼範例。
- 查看輸出內容。程式碼會將作業驅動程式記錄檔輸出至 Cloud Storage 的預設 Dataproc 暫存 bucket。您可以在專案的 Dataproc「Jobs」(工作) 專區,透過 Google Cloud 控制台查看工作驅動程式輸出內容。按一下「Job ID」(工作 ID),即可在「Job details」(工作詳細資料) 頁面查看工作輸出內容。
- 安裝用戶端程式庫 詳情請參閱「設定 Python 開發環境」。
- 設定驗證方法
- 複製並執行 GitHub 程式碼範例。
- 查看輸出內容。程式碼會將作業驅動程式記錄檔輸出至 Cloud Storage 的預設 Dataproc 暫存 bucket。您可以在專案的 Dataproc「Jobs」(工作) 專區,透過 Google Cloud 控制台查看工作驅動程式輸出內容。按一下「Job ID」(工作 ID),即可在「Job details」(工作詳細資料) 頁面查看工作輸出內容。
- 請參閱 Dataproc Cloud 用戶端程式庫的「其他資源」。
執行程式碼
嘗試逐步操作說明:按一下「Open in Cloud Shell」(在 Cloud Shell 開啟),執行 Python Cloud 用戶端程式庫逐步操作說明,建立叢集、執行 PySpark 工作,然後刪除叢集。