在 Dataproc 集群上安装并运行 Jupyter 笔记本


目标

本教程介绍了如何安装 Dataproc Jupyter 组件 然后连接到新集群上运行的 Jupyter 笔记本界面, 从本地浏览器访问集群 组件网关

费用

在本文档中,您将使用 Google Cloud 的以下收费组件:

您可使用价格计算器根据您的预计使用情况来估算费用。 Google Cloud 新用户可能有资格申请免费试用

准备工作

如果您尚未创建 Google Cloud 项目和 Cloud Storage 存储桶

  1. 设置项目

    1. 登录您的 Google Cloud 账号。如果您是 Google Cloud 新手,请创建一个账号来评估我们的产品在实际场景中的表现。新客户还可获享 $300 赠金,用于运行、测试和部署工作负载。
    2. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

      Go to project selector

    3. 确保您的 Google Cloud 项目已启用结算功能

    4. Enable the Dataproc, Compute Engine, and Cloud Storage APIs.

      Enable the APIs

    5. Install the Google Cloud CLI.
    6. To initialize the gcloud CLI, run the following command:

      gcloud init
    7. In the Google Cloud console, on the project selector page, select or create a Google Cloud project.

      Go to project selector

    8. 确保您的 Google Cloud 项目已启用结算功能

    9. Enable the Dataproc, Compute Engine, and Cloud Storage APIs.

      Enable the APIs

    10. Install the Google Cloud CLI.
    11. To initialize the gcloud CLI, run the following command:

      gcloud init

  2. 在您的项目中创建 Cloud Storage 存储分区,以存储您在本教程中创建的任何笔记本。

    1. In the Google Cloud console, go to the Cloud Storage Buckets page.

      Go to Buckets page

    2. Click Create bucket.
    3. On the Create a bucket page, enter your bucket information. To go to the next step, click Continue.
      • For Name your bucket, enter a name that meets the bucket naming requirements.
      • For Choose where to store your data, do the following:
        • Select a Location type option.
        • Select a Location option.
      • For Choose a default storage class for your data, select a storage class.
      • For Choose how to control access to objects, select an Access control option.
      • For Advanced settings (optional), specify an encryption method, a retention policy, or bucket labels.
    4. Click Create.
    5. 您的笔记本将存储在 Cloud Storage 中的 gs://bucket-name/notebooks/jupyter 下。

创建集群并安装 Jupyter 组件

使用已安装的 Jupyter 组件创建集群

打开 Jupyter 和 JupyterLab 界面

点击 Google Cloud 控制台组件网关链接 打开 Jupyter 笔记本 或 JupyterLab 界面。

Jupyter 实例显示的顶级目录是一个虚拟目录,可让您查看 Cloud Storage 存储分区或本地文件系统的内容。您可以通过点击集群中 Cloud Storage 的 GCS 链接或集群中主节点的本地文件系统的本地磁盘来选择位置。

  1. 点击 GCS 链接。Jupyter 笔记本网页界面会显示存储在 Cloud Storage 存储分区中的笔记本,包括您在本教程中创建的所有笔记本。

清除数据

完成本教程后,您可以清理您创建的资源,让它们停止使用配额,以免产生费用。以下部分介绍如何删除或关闭这些资源。

删除项目

为了避免产生费用,最简单的方法是删除您为本教程创建的项目。

要删除项目,请执行以下操作:

  1. In the Google Cloud console, go to the Manage resources page.

    Go to Manage resources

  2. In the project list, select the project that you want to delete, and then click Delete.
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

删除集群

  • 如需删除您的集群,请输入以下命令:
    gcloud dataproc clusters delete cluster-name \
        --region=${REGION}
    

删除存储分区

  • 如需删除您在准备工作第 2 步中创建的 Cloud Storage 存储分区,包括存储在存储分区中的笔记本,请运行以下命令:
    gcloud storage rm gs://${BUCKET_NAME} --recursive
    

后续步骤