HDFS ACL权限管理 初解
- 2019 年 12 月 30 日
- 筆記
就是一系列下定决心的努力
· 正 · 文 · 来 · 啦 ·

What is ACL
Hadoop中的ACL与Linux中的ACL机制基本相同,都是用于为文件系统提供更精细化的权限控制。
参考 HDFS ACLs: Fine-Grained Permission for HDFS Files in Hadoop
getfacl
getfacl
用于查看一个文件/目录的ACL状态,例如:
[root@Master ~]# hadoop dfs -getfacl /user/hive DEPRECATED: Use of this script to execute hdfs command is deprecated. Instead use the hdfs command for it. # file: /user/hive # owner: hive # group: hdfs user::rwx group::r-x other::r-x
setfacl
基本用法
假设,我们有一个HDFS目录/user/tao/xt-data
,它目前的权限为drwxrwxr-x tao supergroup
。我希望让另一个用户hbase
(不属于任何group)对该目录有rwx
的权限,那么可以如下操作:
[root@Master ~]$ hadoop dfs -setfacl -m user:hbase:rwx /user/tao/xt-data [root@Master ~]$ 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 [root@Master ~]# sudo -u hbase hadoop dfs -mkdir /user/tao/xt-data/testDir [root@Master ~]# 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 2018-11-25 16:33 /user/tao/xt-data/testDir [root@Master ~]# 可以看到,现在用户hbase可以在/user/tao/xt-data中新建一个目录testDir了。那么,这个新建的目录的权限是什么呢? [root@Master ~]# hadoop dfs -getfacl /user/tao/xt-data/testDir DEPRECATED: Use of this script to execute hdfs command is deprecated. Instead use the hdfs command for it. # file: /user/tao/xt-data/testDir # owner: hbase # group: supergroup user::rwx group::r-x other::r-x
(可左右滑动(⊙o⊙)哦)
Default ACL
可以为某个目录设置一个默认的ACL权限,使得以后在该目录中新建文件或者子目录时,新建的文件/目录的ACL权限都是之前设置的default ACLs。
例如,现在已经有了一个HDFS目录/user/tao
,其当前的ACL状态为:
[root@Master ~]# hadoop dfs -getfacl /user/tao # file: /user/tao # owner: tao # group: supergroup user::rwx group::rwx other::rwx
(可左右滑动(⊙o⊙)哦)
我们想将其default acl权限设置为user:hbase:rwx
,用命令:
[root@Master ~]# sudo -u tao hadoop dfs -setfacl -m default:user:hbase:rwx /user/tao [root@Master ~]# 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
(可左右滑动(⊙o⊙)哦)
检查是否生效:
[root@Master ~]# sudo -u tao hadoop dfs -mkdir /user/tao/testDir [root@Master ~]# hadoop dfs -getfacl /user/tao/testDir # file: /user/tao/testDir # owner: tao # group: supergroup user::rwx user:hbase:rwx #effective:r-x group::rwx #effective:r-x mask::r-x other::r-x default:user::rwx default:user:hbase:rwx default:group::rwx default:mask::rwx default:other::rwx
(可左右滑动(⊙o⊙)哦)
‘ 所谓成功 ’
坚持把简单的事情做好就是不简单,
坚持把平凡的事情做好就是不平凡。
每个人都有潜在的能量,只是很容易–
被习惯所掩盖,
被时间所迷离,
被惰性所消磨。
那么,成功呢?就是在平凡中做出不平凡的坚持。