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