目标
本教程介绍如何在新集群上安装 Managed Service for Apache Spark Jupyter 组件,然后使用 Managed Service for Apache Spark 组件网关从本地浏览器连接到在集群上运行的 Jupyter 笔记本界面。
费用
在本文档中,您将使用 Google Cloud的以下收费组件:
如需根据您的预计使用情况来估算费用,请使用价格计算器。
准备工作
如果您尚未创建项目和 Cloud Storage 存储桶,请先创建这些资源。 Google Cloud
设置项目
- 登录您的 Google Cloud 账号。如果您是 Google Cloud新手,请 创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
-
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, Compute Engine, and Cloud Storage APIs.
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 CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init -
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, Compute Engine, and Cloud Storage APIs.
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 CLI。
-
如果您使用的是外部身份提供方 (IdP),则必须先使用联合身份登录 gcloud CLI。
-
如需初始化 gcloud CLI,请运行以下命令:
gcloud init
在您的项目中创建 Cloud Storage 存储分区,以存储您在本教程中创建的任何笔记本。
- 在 Google Cloud 控制台中,前往 Cloud Storage 存储分区页面。
- 点击 创建。
- 在创建存储桶页面上,输入您的存储桶信息。要转到下一步,请点击继续。
- 在开始使用部分中,执行以下操作:
- 在选择数据存储位置部分,执行以下操作:
- 在选择数据存储方式部分中,执行以下操作:
- 在选择如何控制对对象的访问权限部分中,选择存储桶是否强制执行禁止公开访问,然后为存储桶对象选择访问权限控制方法。
- 在选择如何保护对象数据部分中,执行以下操作:
- 点击创建。 您的笔记本将存储在 Cloud Storage 中的
gs://bucket-name/notebooks/jupyter下。
创建集群并安装 Jupyter 组件
打开 Jupyter 和 JupyterLab 界面
点击 Google Cloud 控制台的Google Cloud 控制台组件网关链接,以打开集群主节点上运行的 Jupyter 笔记本或 JupyterLab 界面。
Jupyter 实例显示的顶级目录是一个虚拟目录,可让您查看 Cloud Storage 存储桶或本地文件系统的内容。您可以通过点击 Cloud Storage 的 GCS 链接或集群中主节点的本地文件系统的本地磁盘来选择位置。
- 点击 GCS 链接。Jupyter 笔记本网页界面会显示存储在 Cloud Storage 存储桶中的笔记本,包括您在本教程中创建的所有笔记本。

清理
完成本教程后,您可以清理您创建的资源,让它们停止使用配额,以免产生费用。以下部分介绍如何删除或关闭这些资源。
删除项目
为了避免产生费用,最简单的方法是删除您为本教程创建的项目。
要删除项目,请执行以下操作:
- 在 Google Cloud 控制台中,前往管理资源页面。
- 在项目列表中,选择要删除的项目,然后点击删除。
- 在对话框中输入项目 ID,然后点击关闭以删除项目。
删除集群
- 如需删除您的集群,请输入以下命令:
gcloud dataproc clusters delete cluster-name \ --region=${REGION}
删除存储桶
- 如需删除您在准备工作第 2 步中创建的 Cloud Storage 存储桶,包括存储在存储桶中的笔记本,请运行以下命令:
gcloud storage rm gs://${BUCKET_NAME} --recursive