有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

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

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

我想更改f1的权限。txt和f2。txt至644: e、 g.hadoop fs -chmod 644 /a/b/c/*.txt

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

hadoop fs命令让我这么做吗?Java/Scala代码呢


共 (2) 个答案

  1. # 1 楼答案

    你可以使用acls来实现:

    授予用户读写和执行权限

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

    如果想查看文件的权限,请使用getfacl

    hdfs dfs -getfacl -R hdfs://somehost:8020/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.
    
  2. # 2 楼答案

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

    hadoop fs -chmod -R 755 /a/b/c/