在 Azure Databricks 中设置和安装 Blob 存储需要几个步骤。
First, 创建存储帐户 https://learn.microsoft.com/en-us/azure/storage/common/storage-quickstart-create-account?tabs=azure-portal进而创建一个容器 https://learn.microsoft.com/en-us/azure/storage/blobs/storage-quickstart-blobs-portal#create-a-container在它里面。
接下来,记下以下事项:
- 存储帐户名称:创建存储帐户时的名称
- 存储帐户密钥:可以在资源页面的 Azure 门户中找到。
- 容器名称:容器的名称
在 Azure Databricks 笔记本中,为上述项目创建变量。
storage_account_name = "Storage account name"
storage_account_key = "Storage account key"
container = "Container name"
然后,使用以下代码设置 Spark 配置以指向 Azure Blob 存储实例。
spark.conf.set("fs.azure.account.key.{0}.blob.core.windows.net".format(storage_account_name), storage_account_key)
要将其安装到 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}
)
完成这些设置后,您现在可以开始使用安装座。要检查它是否可以看到存储帐户中的文件,请使用dbutils.fs.ls
命令。
dbutils.fs.ls("dbfs:/mnt/<Mount name>")
希望有帮助!