解決從本地文件系統上傳到HDFS時的權限問題

當使用 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

相關文章
相關標籤/搜索