HDFS支持权限控制,但支持较弱。HDFS的设计是基于POSIX模型的,支持按用户、用户组、其他用户的读写执行控制权限。在linux命令行下,可以使用下面的命令修改文件的权限、文件所有者,文件所属组:
sudo addgroup Hadoop#添加一个hadoop组
sudo usermod -a -G hadoop larry#将当前用户加入到hadoop组
sudo gedit etc/sudoers#将hadoop组加入到sudoer
在root ALL=(ALL) ALL后 hadoop ALL=(ALL) ALL
修改hadoop目录的权限
sudo chown -R larry:hadoop /home/larry/hadoop<所有者:组 文件>
sudo chmod -R 755 /home/larry/hadoop
修改hdfs的权限
sudo bin/hadoop dfs -chmod -R 755 /
sudo bin/hadoop dfs -ls /
修改hdfs文件的所有者
sudo bin/hadoop fs -chown -R larry /
sudo bin/hadoop dfsadmin -safemode leave #解除hadoop的安全模式
hadoop fs -copyFromLocal <localsrc> URI#拷贝本地文件到hdfs
hadoop fs -cat file:///file3 /user/hadoop/file4#将路径指定文件的内容输出到stdout
hadoop fs -chgrp [-R] GROUP URI#改变文件的所属组
hadoop fs -chmod [-R] 755 URI#改变用户访问权限
hadoop fs -chown [-R] [OWNER][:[GROUP]] URI [URI ]#修改文件的所有者
hadoop fs -copyToLocal URI localdst#拷贝hdfs文件到本地
hadoop fs -cp URI [URI …] <dest>#拷贝hdfs文件到其它目录
hadoop fs -du URI [URI …]#显示目录中所有文件的大小
hadoop fs -getmerge <src> <localdst> [addnl]#合并文件到本地目录
如:
root@cdh3:~# hdfs dfs -ls /
Found 8 items
drwxr-xr-x – hbase hbase 0 2017-06-24 10:05 /hbase
drwxrwxr-x – solr solr 0 2016-12-01 22:43 /solr
drwxr-xr-x – root supergroup 0 2017-04-24 22:58 /sparklib
drwxr-xr-x – root supergroup 0 2017-07-19 17:44 /sparklib-2.1.0
drwxr-xr-x – hdfs supergroup 0 2016-12-05 09:08 /system
drwxrwxrwt – hdfs supergroup 0 2017-07-13 09:40 /tmp
drwxr-xrwx – hdfs supergroup 0 2017-06-23 10:54 /user
drwxr-xr-x – root supergroup 0 2017-04-13 11:12 /file
root@cdh3:~# hdfs dfs -chown Administrator /file
chown: changing ownership of ‘/file’: Non-super user cannot change owner
root@cdh3:~# hdfs dfs -chown -R Administrator /file
chown: changing ownership of ‘/file’: Non-super user cannot change owner
root@cdh3:~# su hdfs
hdfs@cdh3:/root$ hdfs dfs -chown -R Administrator /file
hdfs@cdh3:/root$ hdfs dfs -chgrp -R Administrator /file
hdfs@cdh3:/root$ hdfs dfs -ls /file
Found 9 items
-rw-r–r– 2 Administrator Administrator 3302 2017-04-13 11:11 /file/data-transfer.properties
-rw-r–r– 2 Administrator Administrator 313898 2017-04-13 11:00 /file/dom4j-1.6.1.jar
drwxr-xr-x – Administrator Administrator 0 2017-04-12 10:03 /file/hangxin
-rw-r–r– 2 Administrator Administrator 24212 2017-03-17 12:06 /file/hx.jar
-rw-r–r– 2 Administrator Administrator 802721 2017-03-17 11:50 /file/mysql-connector-java-5.1.20-bin.jar
drwxr-xr-x – Administrator Administrator 0 2017-03-22 09:46 /file/notregex
drwxr-xr-x – Administrator Administrator 0 2017-04-25 00:01 /file/regex
-rw-r–r– 2 Administrator Administrator 106006 2017-04-13 11:12 /file/sihconfig.xml
-rw-r–r– 2 Administrator Administrator 123 2017-03-16 14:31 /file/spark-config.properties
#