Hadoop_Hdfs ACL 权限控制详解

借鉴文章:

1.HDFS ACL 权限管理

http://blog.csdn.net/u011491148/article/details/45918841

2.Hadoop-2.4.1学习之HDFS文件权限和ACL

http://blog.csdn.net/skywalker_only/article/details/40709447

3.Hadoop 创建用户及HDFS权限,HDFS操作等常用Shell命令

http://www.linuxidc.com/Linux/2012-05/60635.htm


该文章主要讲解Hadoop 的ACL权限控制,对基础的权限控制不做过多介绍:

基础的权限控制可以参考文章3。


1.开启ACL权限控制

Hadoop HDFS 默认没有使用 ACL 权限控制机制。这里介绍下如何开启 hdfs 的权限控制机制:

     第一次使用需要修改hdfs-site.xml 把以下配置加进hdfs-site.xml 中, 并重启NameNode。

<property>
<name>dfs.namenode.acls.enabled</name>
<value>true</value>
</property>

       我们主要是通过  setfacl  getfacl  这两个指令对 hdfs 的 acl 权限控制进行管理。

下面介绍下什么是ACL, 以及如何使用 setfaclgetfacl 对hdfs 的权限进行管控。




2.What is ACL

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

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

上述文章对Hadoop的 ACL进行了介绍,并对比比较了ACL 与 普通的Linux 位文件系统的区别。

文章ACL 介绍部分摘录:

In general, plain Unix permissions aren’t sufficient when you have permission requirements that don’t map cleanly to an enterprise’s natural hierarchy of users and groups.  Working in collaboration with the Apache community, we developed the HDFS ACLs feature to address this shortcoming.  HDFS ACLs will be available in Apache Hadoop 2.4.0 and Hortonworks Data Platform 2.1.

HDFS ACLs give you the ability to specify fine-grained file permissions for specific named users or named groups, not just the file’s owner and group.  HDFS ACLs are modeled after POSIX ACLs [5].  If you’ve ever used POSIX ACLs on a Linux file system, then you already know how ACLs work in HDFS.  Best practice is to rely on traditional permission bits to implement most permission requirements, and define a smaller number of ACLs to augment the permission bits with a few exceptional rules.

下面附上我自己的理解:

普通的位权限控制 与 ACL权限控制 的区别 与优势 :

普通的位权限:

     对于 单个文件, 该文件只能从属于 一个用户 , 一个组,  如果使得 该文件属于多个组, 这种需求没办法实现。

ACL 权限控制:

     对于一个文件,该文件有着 自己的所属用户,所属组。 如一些特定的突发性需求: 

     1.该文件对另外的一个组开放     

     2.组内的某个人对该文件不可修改,ACL可以非常方便的实现该文件对 特定人,特定组的 一个权限管控。不仅是文件的 所属用户, 所属组。


普通的位权限控制 与 ACL权限控制 的关联:

     ACL权限控制只是对 普通的位权限控制的一个补充,其基础还是构建于 rwx 这种位权限控制上的。最好的方案是对于一个文件,尽量的使用基础的位权限控制,尽量少用ACL权限增加额外的控制。 优化 hdfs 文件的所有者, 设置合适的所有组,而不是一味的添加其他的组用户进行管控。 



3.getfacl  与 setfacl 命令介绍:

getfacl

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

[root@ecs1 tao]# hadoop dfs -getfacl /user/tao
DEPRECATED: Use of this script to execute hdfs command is deprecated.
Instead use the hdfs command for it.

# file: /user/tao
# owner: tao
# group: supergroup
user::rwx
group::rwx
other::rwx
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10




setfacl

基本用法

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

[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]# 
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26

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

[root@ecs3 tao]# 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

   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

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

关于权限标志位的顺序: 在命令hadoop dfs -setfacl -m user:hbase:rwx /user/tao/xt-data中,权限标志位rwx的顺序不能改变,否则会报错:-setfacl: Invalid permission in 
正确的写法有: rwxr-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
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7



我们想将其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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

检查是否生效:

[root@ecs1 tao]# sudo -u tao hadoop dfs -mkdir /user/tao/testDir

[root@ecs1 tao]# 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
   
   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16





4.ACL 与 普通位权限判断的优先级:


It’s important to keep in mind the order of evaluation for ACL entries when a user attempts to access a file system object:


1.If the user is the file owner, then the owner permission bits are enforced.

2.Else if the user has a named user ACL entry, then those permissions are enforced.

3.Else if the user is a member of the file’s group or any named group in an ACL entry, then the union of permissions for all matching entries are enforced.  (The user may be a member of multiple groups.)

4.If none of the above were applicable, then the other permission bits are enforced.


In this example, the named user ACL entry accomplished our goal, because the user is not the file owner, and the named user entry takes precedence over all other entries.


优先级为 1最高 4最小:

下面对原文进行下翻译:

当对hdfs 中的文件进行访问的时候, 需要对 执行hadoop 的客户端 的用户权限进行检测。取1,2,3,4的并集,  只要执行hdfs 指令用户只要满足 1,2,3,4的一种情况即可。(取最高优先级的访问权限)

1. 文件所有者 位权限 (rwx) 优先级最高。

2. 文件的特定ACL用户的权限。

3. 该用户是文件的所有组 或者是 ACL组内用户, 取满足条件组的权限并集。

4.是ohter用户


  • 0
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 这个错误提示表示 Hadoop 找不到正确的 HDFS 安装路径。你需要检查 Hadoop 配置文件中的 hadoop_hdfs_home 参数是否正确设置,或者确认 HDFS 是否已经正确安装并设置了环境变量。 ### 回答2: Hadoop 是一款大数据处理框架,需要依赖 Hadoop HDFS 存储系统。在配置 Hadoop 环境时,需要设置环境变量 HADOOP_HDFS_HOME,以指定 Hadoop HDFS 的安装路径。当出现 "error: invalid hadoop_hdfs_home" 错误时,意味着系统无法识别该环境变量,即 Hadoop HDFS 安装路径无效。 解决该问题的方法是检查环境变量的设置是否正确。首先在命令行界面输入 echo $HADOOP_HDFS_HOME 命令,以检查系统是否能识别该环境变量。如果该命令无法输出正确的路径,则需要修改环境变量的设置。 可以在 ~/.bashrc 或 ~/.bash_profile 文件中添加以下环境变量设置语句: export HADOOP_HDFS_HOME=/path/to/hadoop-hdfs 其中,/path/to/hadoop-hdfsHadoop HDFS 的安装路径。设置好这个环境变量之后,可以输入 source ~/.bashrc 或 source ~/.bash_profile 命令,以使环境变量的改动生效。 另外,还可通过设置 Hadoop 的配置文件来修改 Hadoop HDFS 的安装路径。可以在 Hadoop 配置文件 core-site.xml 中添加以下配置: <property> <name>hadoop.hdfs.home</name> <value>/path/to/hadoop-hdfs</value> </property> 在以上配置中,/path/to/hadoop-hdfsHadoop HDFS 的安装路径。保存好配置文件后,重新启动 Hadoop,即可解决 "error: invalid hadoop_hdfs_home" 错误。 ### 回答3: 这个错误信息意味着在运行hadoop相关命令时,系统无法找到指定的hadoop_hdfs_home环境变量。hadoop_hdfs_home是一个关键的环境变量,用于指定hadoop分布式文件系统(HDFS)的安装目录。如果系统无法找到或者无法识别该环境变量,就会出现invalid错误提示。 要解决这个问题,可以尝试以下步骤: 1.检查hadoop_hdfs_home环境变量是否正确设置,可以通过运行echo $hadoop_hdfs_home命令来确认该环境变量的值是否正确。 2.如果hadoop_hdfs_home环境变量未设置,可以通过手动设置该变量或者运行hadoop-env.sh脚本来设置该变量。 3.如果hadoop_hdfs_home环境变量设置正确,但仍然无法正常运行hadoop相关命令,可以尝试重新安装hadoop,并确保正确配置了环境变量。 4.最后,如果你还是无法解决这个问题,可以查看系统日志文件或运行hadoop日志命令来查找更详细的信息和错误提示,以帮助你进一步解决该问题。 总之,如果出现invalid hadoop_hdfs_home错误提示,需要确认hadoop_hdfs_home环境变量设置是否正确,并根据具体情况采取适当措施,以解决此问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值