• HDFS涉及ACLs的命令


    What is ACL

    Hadoop中的ACL与Linux中的ACL机制基本相同,都是用于为文件系统提供更精细化的权限控制。

    参考 HDFS ACLs: Fine-Grained Permission for HDFS Files in Hadoop

    开启ACLs

    默认情况下ACLs是关闭的,想要开启此功能需要在hdfs-site.xml的配置项里找到dfs.namenode.acls.enabled把属性设为true才可以。重要:Namenode节点必须要设定的用户或用户组
    <property>
    <name>dfs.namenode.acls.enabled</name>
    <value>true</value>
    </property>

    getfacl

    getfacl用于查看一个文件/目录的ACL状态,例如:

     1 [root@ecs1 tao]# hadoop dfs -getfacl /user/tao
     2 DEPRECATED: Use of this script to execute hdfs command is deprecated.
     3 Instead use the hdfs command for it.
     4 
     5 # file: /user/tao
     6 # owner: tao
     7 # group: supergroup
     8 user::rwx
     9 group::rwx
    10 other::rwx

    setfacl

    基本用法

    假设,我们有一个HDFS目录/user/tao/xt-data,它目前的权限为drwxrwxr-x tao supergroup。我希望让另一个用户Hbase(不属于任何group)对该目录有rwx的权限,那么可以如下操作:

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

    <!-- COMMAND OPTIONS <path>: 路径 -R: 遍历路径里的所有文件。 -b: 撤销除了基本用户和组权限以外的所有权限。 -k: 撤销默认的ACL设置。 -m: 添加新的权限来使用此ACL。不影响现有权限。 -x: 只撤销指定的ACL。 <acl_spec>: 逗号分隔的ACL权限列表。 --set: 使用该选项指定的路径完全取代现有的ACL。 之前的ACL将不再适用。 -->

      

    [tao@ecs3 ~]$ hadoop dfs -setfacl -m user:hbase:rwx /user/tao/xt-data
    
    [tao@ecs3 ~]$ hadoop dfs -getfacl /user/tao/xt-data
    DEPRECATED: Use of this script to execute hdfs command is deprecated.
    Instead use the hdfs command for it.
    
    # file: /user/tao/xt-data
    # owner: tao
    # group: supergroup
    user::rwx
    user:hbase:rwx
    group::r-x
    mask::rwx
    other::r-x
    
    [tao@ecs3 ~]$ su
    
    [root@ecs3 tao]# sudo -u hbase hadoop dfs -mkdir /user/tao/xt-data/testDir
    
    [root@ecs3 tao]# sudo -u hbase hadoop dfs -ls /user/tao/xt-data
    DEPRECATED: Use of this script to execute hdfs command is deprecated.
    Instead use the hdfs command for it.
    
    Found 1 items
    drwxr-xr-x   - hbase supergroup          0 2015-05-22 16:33 /user/tao/xt-data/testDir
    [root@ecs3 tao]# 

    可以看到,现在用户hbase可以在/user/tao/xt-data中新建一个目录testDir了。那么,这个新建的目录的权限是什么呢?

     1 [root@ecs3 tao]# hadoop dfs -getfacl /user/tao/xt-data/testDir
     2 DEPRECATED: Use of this script to execute hdfs command is deprecated.
     3 Instead use the hdfs command for it.
     4 
     5 # file: /user/tao/xt-data/testDir
     6 # owner: hbase
     7 # group: supergroup
     8 user::rwx
     9 group::r-x
    10 other::r-x
     

    可以看到,这个新建的目录与其他普通的目录在权限是一样的。如果想使得新建的目录/文件的ACL也满足我们的要求,可以使用default acl来实现。

    关于权限标志位的顺序: 在命令hadoop dfs -setfacl -m user:hbase:rwx /user/tao/xt-data中,权限标志位rwx的顺序不能改变,否则会报错:-setfacl: Invalid permission in
    正确的写法有: rwx, r-x, -r-, -rx等;
    错误的写法有:wrxw-x等。

    Default ACL

    可以为某个目录设置一个默认的ACL权限,使得以后在该目录中新建文件或者子目录时,新建的文件/目录的ACL权限都是之前设置的default ACLs。

    例如,现在已经有了一个HDFS目录/user/tao,其当前的ACL状态为:

    [root@ecs1 tao]# hadoop dfs -getfacl /user/tao
    # file: /user/tao
    # owner: tao
    # group: supergroup
    user::rwx
    group::rwx
    other::rwx

    我们想将其default acl权限设置为user:hbase:rwx,用命令:

    [root@ecs1 tao]# sudo -u tao hadoop dfs -setfacl -m default:user:hbase:rwx /user/tao
    
    [root@ecs1 tao]# hadoop dfs -getfacl /user/tao
    # file: /user/tao
    # owner: tao
    # group: supergroup
    user::rwx
    group::rwx
    other::rwx
    default:user::rwx
    default:user:hbase:rwx
    default:group::rwx
    default:mask::rwx
    default:other::rwx

    检查是否生效:

     1 [root@ecs1 tao]# sudo -u tao hadoop dfs -mkdir /user/tao/testDir
     2 
     3 [root@ecs1 tao]# hadoop dfs -getfacl /user/tao/testDir
     4 # file: /user/tao/testDir
     5 # owner: tao
     6 # group: supergroup
     7 user::rwx
     8 user:hbase:rwx  #effective:r-x
     9 group::rwx  #effective:r-x
    10 mask::r-x
    11 other::r-x
    12 default:user::rwx
    13 default:user:hbase:rwx
    14 default:group::rwx
    15 default:mask::rwx
    16 default:other::rwx
  • 相关阅读:
    Redis 如何保证缓存与数据库双写时的数据一致性
    Redis 缓存雪崩和缓存穿透问题
    Redis 的并发竞争 Key 问题
    【转】intelliJ IDEA集成checkStyle
    【转】hadoop深入研究:(十一)——序列化与Writable实现
    【转】Hadoop在MapReduce中使用压缩详解
    【转】JDK工具jinfo用法详解
    【转】JVM统计监控工具-jstat
    【转】jps命令使用
    基于MLlib的机器学习--协同过滤与推荐
  • 原文地址:https://www.cnblogs.com/royfans/p/7326859.html
Copyright © 2020-2023  润新知