当使用 hadoop fs -put localfile /user/xxx 时提示:html
put: Permission denied: user=root, access=WRITE, inode="/user/shijin":hdfs:supergroup:drwxr-xr-xnode
代表:权限不够。这里涉及到两个方面的权限。一个是本地文件系统中localfile 文件的权限,一个是HDFS上 /user/xxx目录的权限。linux
先看看 /user/xxx目录的权限:drwxr-xr-x - hdfs supergroup 表示它属于hdfs用户,组名为 supergroupapache
所以须要使用 sudo -u hdfs hadoop fs -put localfile /user/xxx 来指定使用 hdfs 用户来执行上传命令。参考ide
当高兴地执行sudo -u hdfs hadoop fs -put localfile /user/xxx 觉得能成功上传时,又报错:
put: localfile No such file or directory 说找不到本地文件localfile,但是用 ls 明明 能看到 localfile ,后来在一篇文章(参考)中发现发来是lcoalfile的权限问题。oop
由于我如今是使用hdfs用户来执行命令。而hdfs用户对 localfile 是没有相关权限的。此时,问题基本解决了,就是让hdfs 用户对 lcoalfile 有相关权限,(注意目录权限该该目录下文件权限的影响,参考:linux下文件与目录权限关系)ui
一种简单的解决方法。直接把须要上传的文件复制到/tmp目录下。由于/tmp目录的权限为 rwxrwxrwx。而后执行:this
sudo -u hdfs hadoop fs -put localfile /user/xxx 上传成功。spa
关于HDFS的权限问题:操作系统
HDFS文件系统的权限模型与 POSIX 模型相似
The Hadoop Distributed File System (HDFS) implements a permissions model for files and directories that shares much of the POSIX model.
Each file and directory is associated with an owner and a group.
当建立文件或目录时,它的owner(全部者)是客户端进程的 user identity.
When a file or directory is created, its owner is the user identity of the client process,
and its group is the group of the parent directory (the BSD rule).
访问HDFS时,须要验证:user name(用户名) 和 group list(所属的用户组)
Each client process that accesses HDFS has a two-part identity composed of the user name, and groups list.
Whenever HDFS must do a permissions check for a file or directory ‘foo’ accessed by a client process
Hadoop支持两种不一样的操做模型(simple 和 kerberos)从而决定 user identity,由配置选项:hadoop.security.authentication property 来决定使用哪一种模型
As of Hadoop 0.22, Hadoop supports two different modes of operation to determine the user’s identity,
specified by the hadoop.security.authentication property:
对于Simple模型而言,客户端进程的身份(identity) 是由提交 操做命令的那台主机所在的操做系统(的用户名)决定的。本文报的“权限不够”的错误,是在 Simple模型下出错的,至于kerberos模型,可参考官方文档:Apache Hadoop 2.7.2 HDFS 中的介绍
In this mode of operation, the identity of a client process is determined by the host operating system.
On Unix-like systems, the user name is the equivalent of `whoami`.
参考连接:https://hadoop.apache.org/docs/r2.7.2/hadoop-project-dist/hadoop-hdfs/HdfsPermissionsGuide.html
原文:http://www.cnblogs.com/hapjin/p/4846853.html