在 Dataproc 叢集中執行代管型筆記本執行個體
本頁說明如何在 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.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Notebooks and Dataproc APIs.
-
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 Notebooks and Dataproc APIs.
- 如果您尚未建立代管型筆記本執行個體,請先完成這項作業。
-
Dataproc 工作站 (
roles/dataproc.worker
) 專案 -
Dataproc 編輯者 (
roles/dataproc.editor
) 叢集上的dataproc.clusters.use
權限 -
dataproc.agents.create
-
dataproc.agents.delete
-
dataproc.agents.get
-
dataproc.agents.update
-
dataproc.tasks.lease
-
dataproc.tasks.listInvalidatedLeases
-
dataproc.tasks.reportStatus
-
dataproc.clusters.use
必須啟用叢集的元件閘道。
叢集必須具備 Jupyter 元件。
叢集必須與受管理筆記本執行個體位於相同區域。
REGION
:受管理筆記本執行個體的位置 Google CloudCLUSTER_NAME
:新叢集的名稱如果尚未建立代管型筆記本執行個體,請在與 Dataproc 叢集相同的區域中建立。
前往 Google Cloud 控制台的「受管理筆記本」頁面。
按一下代管型筆記本執行個體名稱旁的「Open JupyterLab」(開啟 JupyterLab)。
在受管理筆記本執行個體的 JupyterLab 介面中,依序選取「File」>「New」>「Notebook」。
Dataproc 叢集可用的核心會顯示在「選取核心」選單中。選取要使用的核心,然後按一下「選取」。
系統會開啟新的筆記本檔案。
將程式碼新增至新筆記本檔案,然後執行程式碼。
在代管型筆記本執行個體的 JupyterLab 介面中,按一下「檔案瀏覽器」
按鈕,然後前往並開啟要執行的筆記本檔案。如要開啟「Select kernel」對話方塊,請按一下筆記本檔案的核心名稱,例如「Python (Local)」。
如要從 Dataproc 叢集選取核心,請選取核心名稱,結尾須包含叢集名稱。舉例來說,如果 Dataproc 叢集名為
mycluster
,則該叢集上的 PySpark 核心會命名為「PySpark on mycluster」。按一下「選取」即可關閉對話方塊。
您現在可以在 Dataproc 叢集上執行筆記本檔案的程式碼。
- 進一步瞭解 Dataproc。
必要的角色
為確保服務帳戶具備在 Dataproc 無伺服器叢集上執行筆記本檔案的必要權限,請要求管理員授予服務帳戶下列 IAM 角色:
如要進一步瞭解如何授予角色,請參閱「管理專案、資料夾和機構的存取權」。
這些預先定義的角色具備在 Dataproc Serverless 叢集上執行筆記本檔案所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要在 Dataproc Serverless 叢集上執行筆記本檔案,您必須具備下列權限:
管理員或許還可透過自訂角色或其他預先定義的角色,將這些權限授予服務帳戶。
建立 Dataproc 叢集
如要在 Dataproc 叢集中執行代管型筆記本執行個體的筆記本檔案,叢集必須符合下列條件:
如要建立 Dataproc 叢集,請在 Cloud Shell 或已安裝 Google Cloud CLI 的其他環境中,輸入下列指令。
gcloud dataproc clusters create CLUSTER_NAME\ --region=REGION \ --enable-component-gateway \ --optional-components=JUPYTER
更改下列內容:
幾分鐘後,您就能使用 Dataproc 叢集。進一步瞭解如何建立 Dataproc 叢集。
開啟 JupyterLab
在 Dataproc 叢集中執行筆記本檔案
您可以在相同專案和區域中,從任何代管型筆記本執行個體,在 Dataproc 叢集中執行筆記本檔案。
執行新的筆記本檔案
如要在建立筆記本檔案後變更要使用的核心,請參閱下一節。