如何使用 Azure Blob 存储挂载数据?

Ton*_*wyn 2 python azure azure-blob-storage azure-databricks

我是 Azure Databricks 的新手,我的导师建议我完成机器学习训练营:

https://aischool.microsoft.com/en-us/machine-learning/learning-paths/ai-platform-engineering-bootcamps/custom-machine-learning-bootcamp

不幸的是,成功设置 Azure Databricks 后,我在步骤 2 中遇到了一些问题。我成功将 1_01_introduction 文件作为笔记本添加到我的工作区。然而,虽然本教程讨论了如何在 Azure Blob 存储中挂载数据,但它似乎跳过了该步骤,这导致接下来的所有教程编码步骤都会引发错误。第一个代码位(教程告诉我运行)以及随后出现的错误包含在下面。

%运行“../presenter/includes/mnt_blob”

找不到笔记本:presenter/includes/mnt_blob。笔记本可以通过相对路径(./Notebook 或 ../folder/Notebook)或绝对路径(/Abs/Path/to/Notebook)指定。确保您指定的路径正确。

堆栈跟踪:/1_01_introduction:python

据我所知,Azure Blob 存储尚未设置,因此我运行的代码(以及以下所有步骤中的代码)无法找到应该是的教程项目存储在 blob 中。各位好心人能提供的任何帮助将不胜感激。

Jon*_*Jon 9

在 Azure Databricks 中设置和安装 Blob 存储需要几个步骤。

首先,创建一个存储帐户,然后在其中创建一个容器。

接下来,记下以下事项:

  • 存储帐户名称:创建存储帐户时的名称
  • 存储帐户密钥:可以在资源页面的 Azure 门户中找到。
  • 容器名称:容器的名称

在 Azure Databricks 笔记本中,为上述项目创建变量。

storage_account_name = "Storage account name"
storage_account_key = "Storage account key"
container = "Container name"
Run Code Online (Sandbox Code Playgroud)

然后,使用以下代码设置 Spark 配置以指向 Azure Blob 存储实例。

spark.conf.set("fs.azure.account.key.{0}.blob.core.windows.net".format(storage_account_name), storage_account_key)
Run Code Online (Sandbox Code Playgroud)

要将其安装到 Azure Databricks,请使用该dbutils.fs.mount方法。源是 Azure Blob 存储实例和特定容器的地址。装载点是将其装载到 Azure Databricks 上的 Databricks 文件存储中的位置。额外的配置是您传递 Spark 配置的位置,因此并不总是需要设置它。

dbutils.fs.mount(
 source = "wasbs://{0}@{1}.blob.core.windows.net".format(container, storage_account_name),
 mount_point = "/mnt/<Mount name>",
 extra_configs = {"fs.azure.account.key.{0}.blob.core.windows.net".format(storage_account_name): storage_account_key}
)
Run Code Online (Sandbox Code Playgroud)

完成这些设置后,您现在可以开始使用安装座。要检查它是否可以查看存储帐户中的文件,请使用以下dbutils.fs.ls命令。

dbutils.fs.ls("dbfs:/mnt/<Mount name>")
Run Code Online (Sandbox Code Playgroud)

希望有帮助!