HDFS & WebHDFS
使用 dvc remote add 命令定义远程存储:
$ dvc remote add -d myremote hdfs://user@example.com:path⚠️ 在 Hadoop 集群中使用 HDFS 可能需要额外的配置。我们假设客户端已配置好可直接使用。具体来说,应安装 libhdfs。
HDFS 配置参数
如果以下参数包含敏感用户信息,请使用 --local 选项添加,以确保它们被写入 Git 忽略的配置文件中。
-
url- 远程位置:$ dvc remote modify myremote url hdfs://user@example.com/path -
user- 访问远程存储的用户名。$ dvc remote modify --local myremote user myuser -
kerb_ticket- Kerberos 安全保护的 HDFS 集群所用的 Kerberos 票据缓存路径$ dvc remote modify --local myremote \ kerb_ticket /path/to/ticket/cache -
replication- HDFS 集群写操作的副本因子。默认值为 3。$ dvc remote modify myremote replication 2
WebHDFS
也可以通过 WebHDFS API 将 HDFS 集群用作远程存储。
如果您的集群是安全保护的,则 WebHDFS 通常与 Kerberos 和 HTTPS 一起使用。要为 DVC 远程启用这些功能,请将 use_https 和 kerberos 设置为 true。
$ dvc remote add -d myremote webhdfs://example.com/path
$ dvc remote modify myremote use_https true
$ dvc remote modify myremote kerberos true
$ dvc remote modify --local myremote token SOME_BASE64_ENCODED_TOKEN⚠️ 使用 WebHDFS 需要在集群中启用 REST API 访问:在 hdfs-site.xml 中将配置属性 dfs.webhdfs.enabled 设置为 true。
💡 建议在使用远程存储前运行 kinit,以确保您拥有有效的 Kerberos 会话。
WebHDFS 配置参数
如果以下参数包含敏感用户信息,请使用 --local 选项添加,以确保它们被写入 Git 忽略的配置文件中。
-
url- 远程位置:$ dvc remote modify myremote url webhdfs://user@example.com/path在使用
kerberos或token身份验证时,请勿在 URL 中提供user。 -
user- 访问远程存储的用户名。当使用kerberos或token身份验证时,请勿设置此参数。$ dvc remote modify --local myremote user myuser -
kerberos- 启用 Kerberos 身份验证(默认为false):$ dvc remote modify myremote kerberos true -
kerberos_principal- 要使用的 Kerberos 主体,适用于存在多个主体的情况(例如服务账户)。仅当kerberos为true时使用。$ dvc remote modify myremote kerberos_principal myprincipal -
proxy_to- 作为代理的 Hadoop 超级用户。集群必须启用“代理用户”功能,并且该用户必须具有正确的访问权限。如果集群是安全保护的,则必须启用 Kerberos(将kerberos设置为true)才能使此功能生效。此参数与token不兼容。$ dvc remote modify myremote proxy_to myuser -
use_https- 启用 SWebHdfs。请注意,DVC 仍期望url中的协议为webhdfs://,如果使用swebhdfs://则会失败。$ dvc remote modify myremote use_https true -
ssl_verify- 是否验证 SSL 请求。当启用use_https时默认为true,否则为false。$ dvc remote modify myremote ssl_verify false -
token- Hadoop 委托令牌(由 WebHDFS API 返回)。如果集群是安全保护的,则必须启用 Kerberos(将kerberos设置为true)才能使此功能生效。此参数与提供user和使用proxy_to不兼容。$ dvc remote modify myremote token "mysecret" -
password- 与user一起用于基本身份验证的密码。如果提供了password,则也必须提供user。由于这是密码,建议将其存储在本地配置中(即不提交到 Git)。$ dvc remote modify --local password "mypassword" -
data_proxy_target- 调用 fsspec WebHDFS 构造函数时使用的目标映射(参见 https://filesystem-spec.readthedocs.io/en/latest/api.html?highlight=data_proxy#fsspec.implementations.webhdfs.WebHDFS.__init__ )。此功能支持访问位于高可用性代理服务器后的 WebHDFS 集群,并重写连接所用的 URL。例如,如果你提供的 URL 为
webhdfs://host:port/,并且为data_proxy_target参数提供了值https://host:port/gateway/cluster,那么 fsspec WebHDFS 内部会将每个https://host:port/webhdfs/v1替换为https://host:port/gateway/cluster/webhdfs/v1$ dvc remote modify data_proxy_target "https://host:port/gateway/cluster"