可以在 init 脚本中引用哪些文件?

对引用 init 脚本中的其他文件的支持取决于所引用文件的存储位置。 本文概述了这种行为并提供了建议。

Databricks 建议将所有 init 脚本作为群集范围的 init 脚本进行管理。

什么标识用于运行 init 脚本?

在专用访问模式(以前是单个用户)中,将使用分配的主体(用户或组)的标识。

在标准访问模式(以前共享)或无隔离共享访问模式中,init 脚本使用群集所有者的标识。

并非所有 Databricks Runtime 版本和访问模式都支持所有用于存储 init 脚本的位置。 请参阅 init 脚本可以安装在何处?

是否可以从初始化脚本引用 Unity Catalog 卷中的文件?

可以从存储在 Unity Catalog 卷中的 init 脚本引用存储在 Unity Catalog 卷中的库和 init 脚本。

重要

访问 Unity Catalog 卷中存储的其他文件所需的凭据仅在 Unity Catalog 卷中存储的 init 脚本中可用。 不能从其他位置配置的 init 脚本引用 Unity Catalog 卷中的任何文件。

对于具有标准访问模式的群集,只需将配置的 init 脚本添加到允许列表。 对 init 脚本中引用的其他文件的访问由 Unity Catalog 控制。

是否可以从 init 脚本引用工作区文件?

在 Databricks Runtime 11.3 LTS 及更高版本中,可以从使用工作区文件存储的 init 脚本中引用其他工作区文件,例如库、配置文件或 shell 脚本。

是否可以从 init 脚本引用云对象存储中的文件?

可以从 init 脚本引用存储在云对象存储中的库和其他初始化脚本。

对于具有标准访问模式的群集,只需将配置的 init 脚本添加到允许列表。 对 init 脚本中引用的其他文件的访问权限取决于配置的对云对象存储的访问权限。

Databricks 建议使用 Microsoft Entra ID 服务主体来管理对存储在 Azure Data Lake Storage Gen2 中的库和 init 脚本的访问。 请使用以下链接的文档完成此设置:

  1. 创建对所需 Blob 具有读取和列出权限的服务主体。 请参阅使用服务主体与 Microsoft Entra ID (Azure Active Directory) 访问存储

  2. 使用机密保存凭据。 请参阅管理机密

  3. 请在创建群集时在 Spark 配置和环境变量中设置属性,如以下示例所示:

    Spark 配置:

    spark.hadoop.fs.azure.account.auth.type.<storage-account>.dfs.core.chinacloudapi.cn OAuth
    spark.hadoop.fs.azure.account.oauth.provider.type.<storage-account>.dfs.core.chinacloudapi.cn org.apache.hadoop.fs.azurebfs.oauth2.ClientCredsTokenProvider
    spark.hadoop.fs.azure.account.oauth2.client.id.<storage-account>.dfs.core.chinacloudapi.cn <application-id>
    spark.hadoop.fs.azure.account.oauth2.client.secret.<storage-account>.dfs.core.chinacloudapi.cn {{secrets/<secret-scope>/<service-credential-key>}}
    spark.hadoop.fs.azure.account.oauth2.client.endpoint.<storage-account>.dfs.core.chinacloudapi.cn https://login.chinacloudapi.cn/<tenant-id>/oauth2/token
    

    环境变量:

    SERVICE_CREDENTIAL={{secrets/<secret-scope>/<service-credential-key>}}
    
  4. (可选)使用 azcopyAzure CLI 重构 init 脚本。

    可以在 init 脚本中引用配置群集期间设置的环境变量,以传递作为机密存储的凭据进行验证。