解决从本地文件系统上传到HDFS时的权限问题 您所在的位置:网站首页 bonbon软件权限问题 解决从本地文件系统上传到HDFS时的权限问题

解决从本地文件系统上传到HDFS时的权限问题

2024-05-30 13:31| 来源: 网络整理| 查看: 265

当使用 hadoop fs -put localfile /user/xxx 时提示:

put: Permission denied: user=root, access=WRITE, inode="/user/shijin":hdfs:supergroup:drwxr-xr-x

表明:权限不够。这里涉及到两个方面的权限。一个是本地文件系统中localfile 文件的权限,一个是HDFS上 /user/xxx目录的权限。

 

先看看 /user/xxx目录的权限:drwxr-xr-x   - hdfs supergroup      表示它属于hdfs用户,组名为 supergroup

因此需要使用 sudo -u hdfs hadoop fs -put localfile /user/xxx   来指定使用 hdfs 用户来执行上传命令。参考

 

当高兴地执行sudo -u hdfs hadoop fs -put localfile /user/xxx  以为能成功上传时,又报错: put: localfile   No such file or directory   说找不到本地文件localfile,可是用 ls 明明 能看到 localfile ,后来在一篇文章(参考)中发现发来是lcoalfile的权限问题。

因为我现在是使用hdfs用户来执行命令。而hdfs用户对 localfile 是没有相关权限的。此时,问题基本解决了,就是让hdfs 用户对 lcoalfile 有相关权限,(注意目录权限该该目录下文件权限的影响,参考:linux下文件与目录权限关系)

 

一种简单的解决方法。直接把需要上传的文件复制到/tmp目录下。因为/tmp目录的权限为 rwxrwxrwx。然后执行:

sudo -u hdfs hadoop fs -put localfile /user/xxx   上传成功。

 

关于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

本文转自hapjin博客园博客,原文链接:http://www.cnblogs.com/hapjin/,如需转载请自行联系原作者



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有