赞
踩
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节点必须要设定的用户或用户组
dfs.namenode.acls.enabled
true
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>
<!-- COMMAND OPTIONS
-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.
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等;
错误的写法有:wrx,w-x等。
Default ACL
可以为某个目录设置一个默认的ACL权限,使得以后在该目录中新建文件或者子目录时,新建的文件/目录的ACL权限都是之前设置的default ACLs。
例如,现在已经有了一个HDFS目录/user/tao,其当前的ACL状态为:
[root@ecs1 tao]# hadoop dfs -getfacl /user/tao
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
user::rwx
group::rwx
other::rwx
default:user::rwx
default:user:hbase:rwx
default:group::rwx
default
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。