簡體   English   中英

如何在 DBFS 上掛載 Azure 數據湖存儲

[英]How to mount Azure Data Lake Store on DBFS

我需要使用 Azure 服務主體客戶端憑據在 Azure Databricks 文件系統上安裝 Azure Data Lake Store Gen1 數據文件夾。 請幫忙

訪問 Azure Data Lake Storage Gen1 的三種方式:

  1. 傳遞您的 Azure Active Directory 憑據,也稱為憑據傳遞。
  2. 使用服務主體和 OAuth 2.0 將 Azure Data Lake Storage Gen1 文件系統裝載到 DBFS。
  3. 直接使用服務主體。

1. 傳遞您的 Azure Active Directory 憑據,也稱為憑據傳遞:

You can authenticate automatically to Azure Data Lake Storage Gen1 from Azure Databricks clusters using the same Azure Active Directory (Azure AD) identity that you use to log into Azure Databricks. 當您為集群啟用 Azure AD 憑據直通時,您在該集群上運行的命令將能夠讀取和寫入 Azure Data Lake Storage Gen1 中的數據,而無需您配置服務主體憑據以訪問存儲。

為標准集群啟用 Azure Data Lake Storage 憑證直通

在此處輸入圖像描述

有關完整的設置和使用說明,請參閱使用 Azure Active Directory 憑據直通安全訪問 Azure Data Lake Storage

2. 使用服務主體和 OAuth 2.0 將 Azure Data Lake Storage Gen1 文件系統安裝到 DBFS。

步驟 1:創建並授予服務主體權限

如果您選擇的訪問方法需要具有足夠權限的服務主體,而您沒有,請執行以下步驟:

  1. 創建可以訪問資源的 Azure AD 應用程序和服務主體。 請注意以下屬性:

    application-id:唯一標識客戶端應用程序的 ID。

    directory-id:唯一標識 Azure AD 實例的 ID。

    service-credential:應用程序用來證明其身份的字符串。

  2. 在 Azure Data Lake Storage Gen1 帳戶上注冊服務主體,授予正確的角色分配,例如參與者。

步驟 2:使用服務主體和 OAuth 2.0 裝載 Azure Data Lake Storage Gen1 資源

Python代碼:

configs = {"<prefix>.oauth2.access.token.provider.type": "ClientCredential",
           "<prefix>.oauth2.client.id": "<application-id>",
           "<prefix>.oauth2.credential": dbutils.secrets.get(scope = "<scope-name>", key = "<key-name-for-service-credential>"),
           "<prefix>.oauth2.refresh.url": "https://login.microsoftonline.com/<directory-id>/oauth2/token"}

# Optionally, you can add <directory-name> to the source URI of your mount point.
dbutils.fs.mount(
  source = "adl://<storage-resource>.azuredatalakestore.net/<directory-name>",
  mount_point = "/mnt/<mount-name>",
  extra_configs = configs)

在此處輸入圖像描述

3. 使用服務主體和 OAuth 2.0 直接使用 Spark API 訪問

您可以使用服務主體通過 OAuth 2.0 直接訪問 Azure Data Lake Storage Gen1 存儲帳戶(而不是使用 DBFS 安裝)。

使用 DataFrame API 訪問:

要從 Azure Data Lake Storage Gen1 帳戶中讀取數據,您可以將 Spark 配置為使用筆記本中的以下代碼段的服務憑證:

spark.conf.set("<prefix>.oauth2.access.token.provider.type", "ClientCredential")
spark.conf.set("<prefix>.oauth2.client.id", "<application-id>")
spark.conf.set("<prefix>.oauth2.credential","<key-name-for-service-credential>"))
spark.conf.set("<prefix>.oauth2.refresh.url", "https://login.microsoftonline.com/<directory-id>/oauth2/token")

在此處輸入圖像描述

參考: Azure Databricks - Azure Data Lake Storage Gen1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM