WebHDFS使用

WebHDFS提供HDFS的RESTful接口,可通过此接口进行HDFS文件操作。

配置
需要在hdfs-site.xml打开WebHDFS开关,此开关默认打开。

<property>
    <name>dfs.webhdfs.enabled</name>
    <value>true</value>
</property>

使用
连接NameNode的50070端口进行文件操作。

比如:查看知道目录文件列表

http://ip:50070/webhdfs/v1/?op=LISTSTATUS

结果:

{"FileStatuses":{"FileStatus":[
{"accessTime":0,"blockSize":0,"childrenNum":9,"fileId":16386,"group":"supergroup","length":0,"modificationTime":1474375047100,"owner":"root","pathSuffix":"hbase","permission":"755","replication":0,"type":"DIRECTORY"},
{"accessTime":0,"blockSize":0,"childrenNum":0,"fileId":17479,"group":"supergroup","length":0,"modificationTime":1476976935552,"owner":"root","pathSuffix":"test","permission":"755","replication":0,"type":"DIRECTORY"}
]}}

更多查看官方文档:https://hadoop.apache.org/docs/r2.4.1/hadoop-project-dist/hadoop-hdfs/WebHDFS.html