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


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

 

原文:http://www.cnblogs.com/hapjin/p/4846853.html


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM