HDFS为文件及其所有目录授予权限

问题描述 投票:0回答:2

我在HDFS中有以下数据(2个文件):

/a
  /b
    /c
      /f1.txt
      /f2.txt

我想将f1.txt和f2.txt的权限更改为644:例如hadoop fs -chmod 644 /a/b/c/*.txt

但是,为了真正授予对这些文件的访问权限,我需要将/b/c的权限更改为755+x到包含这些文件的目录。注意:我没有/a,这已经是世界可读的。

是否有一个hadoop fs命令让我这样做? Java / Scala代码怎么样?

java scala hadoop hdfs hadoop2
2个回答
1
投票

您可以使用acls

为用户提供读写和执行访问权限

hdfs dfs -setfacl -m -R user:UserName:rwx /a/b/c/f1.txt

如果要查看文件的权限,请使用getfacl hdfs dfs -getfacl -m -R user:UserName:rwx /a/b/c/f1.txt

SetFacl from hadoop guide :

setfacl的

用法:hdfs dfs -setfacl [-R] [-b|-k -m|-x <acl_spec> <path>]|[--set <acl_spec> <path>]

设置文件和目录的访问控制列表(ACL)。

选项:

-b: Remove all but the base ACL entries. The entries for user, group and others are retained for compatibility with permission bits.
-k: Remove the default ACL.
-R: Apply operations to all files and directories recursively.
-m: Modify ACL. New entries are added to the ACL, and existing entries are retained.
-x: Remove specified ACL entries. Other ACL entries are retained.
--set: Fully replace the ACL, discarding all existing entries. The acl_spec must include entries for user, group, and others for compatibility with permission bits.
acl_spec: Comma separated list of ACL entries.
path: File or directory to modify.

例子:

hdfs dfs -setfacl -m user:hadoop:rw- /file
hdfs dfs -setfacl -x user:hadoop /file
hdfs dfs -setfacl -b /file
hdfs dfs -setfacl -k /dir
hdfs dfs -setfacl --set user::rw-,user:hadoop:rw-,group::r--,other::r-- /file
hdfs dfs -setfacl -R -m user:hadoop:r-x /dir
hdfs dfs -setfacl -m default:user:hadoop:r-x /dir
Exit Code:

Returns 0 on success and non-zero on error.

0
投票

使用-R(递归)选项。它允许存在于目录中的所有文件。

hadoop fs -chmod -R 755 /a/b/c/
© www.soinside.com 2019 - 2024. All rights reserved.