curl操作hadoop hdfs文件系统
最近在研究hadoop,hdfs文件系统,对于客户端访问hdfs文件系统的方式,研究了好几天,发现除了用hadoop内部的命令操作hdfs文件系统以外,还可以用调用webhdfs的接口方式来访问hdfs文件系统。下面引用了一部分内容进行说明。最后面会有我自己系统上亲自测试的记录。
什么是REST 与RESTful
Hadoop的RESTful API接口
API示例
第一部分:什么是REST 与RESTful
什么是REST及RESTful
REST 描述了一个架构样式的互联系统(如 Web 应用程序)。REST 约束条件作为一个整体应用时,将生成一个简单、可扩展、有效、安全、可靠的架构。由于它简便、轻量级以及通过 HTTP 直接传输数据的特性,RESTful Web 服务成为基于 SOAP 服务的一个最有前途的替代方案。用于 web 服务和动态 Web 应用程序的多层架构可以实现可重用性、简单性、可扩展性和组件可响应性的清晰分离。Ajax 和 RESTful Web 服务本质上是互为补充的。开发人员可以轻松使用 Ajax 和 RESTful Web 服务一起创建丰富的界面。
REST 指的是一组架构约束条件和原则。满足这些约束条件和原则的应用程序或设计就是 RESTful。
RESTful 原则
客户端和服务器之间的交互在请求之间是无状态的。从客户端到服务器的每个请求都必须包含理解请求所必需的信息。如果服务器在请求之间的任何时间点重启,客户端不会得到通知。此外,无状态请求可以由任何可用服务器回答,这十分适合云计算之类的环境。客户端可以缓存数据以改进性能。
在服务器端,应用程序状态和功能可以分为各种资源。资源是一个有趣的概念实体,它向客户端公开。资源的例子有:应用程序对象、数据库记录、算法等等。每个资源都使用 URI (Universal Resource Identifier) 得到一个惟一的地址。所有资源都共享统一的界面,以便在客户端和服务器之间传输状态。使用的是标准的 HTTP 方法,比如 GET、PUT、POST 和 DELETE。Hypermedia 是应用程序状态的引擎,资源表示通过超链接互联。
分层系统,这表示组件无法了解它与之交互的中间层以外的组件。通过将系统知识限制在单个层,可以限制整个系统的复杂性,促进了底层的独立性。
REST 实现方式
RESTfulWeb 服务与RPC 样式的Web 服务
WebService
RESTfulWeb 服务的Java 框架
Restlet
JSR-311
构建RESTful Web 服务的多层架构
SSH
REST 特点
REST 从资源的角度来观察整个网络,分布在各处的资源由URI确定,而客户端的应用通过URI来获取资源的表示方式。获得这些表徵致使这些应用程序转变了其状态。随着不断获取资源的表示方式,客户端应用不断地在转变着其状态
REST 中的资源操作
资源是由URI来指定。
对资源的操作包括获取、创建、修改和删除资源,这些操作正好对应HTTP协议提供的GET、POST、PUT和DELETE方法。
通过操作资源的表现形式来操作资源。
资源的表现形式则是XML或者HTML,取决于读者是机器还是人,是消费web服务的客户软件还是web浏览器。当然也可以是任何其他的格式。
RESTful API 要求
客户端和服务器结构
连接协议具有无状态性
能够利用Cache机制增进性能
层次化的系统随需代码 - Javascript (可选)
REST的优点
可以利用缓存Cache来提高响应速度
通讯本身的无状态性可以让不同的服务器的处理一系列请求中的不同请求,提高服务器的扩展性浏览器即可作为客户端,
简化软件需求
相对于其他叠加在HTTP协议之上的机制,REST的软件依赖性更小不需要额外的资源发现机制
在软件技术演进中的长期的兼容性更好
RESTful Web 服务
RESTful Web 服务(也称为 RESTful Web API)是一个使用HTTP并遵循REST原则的Web服务。
Web服务接受与返回的互联网媒体类型,比如:JSON,XML ,YAML 等
Web服务在该资源上所支持的一系列请求方法(比如:POST,GET,PUT或DELETE)。
不像基于SOAP的Web服务,RESTful Web服务并没有的“正式”标准。这是因为REST是一种架构,而SOAP只是一个协议。虽然REST不是一个标准,但在实现RESTful Web服务时可以使用其他各种标准(比如HTTP,URL,XML,PNG等)。
第二部分:Hadoop RESTful API接口
Hadoop RESTful API 介绍
全称为webHDFS
在Hadoop 1.0 提供
Hadoop RESTful API-Get
操作
参考
OPEN
FileSystem.open
GETFILESTATUS
FileSystem.getFileStatus
GETCONTENTSUMMARY
FileSystem.getContentSummary
LISTSTATUS
FileSystem.listStatus
GETFILECHECKSUM
FileSystem.getFileChecksum
GETHOMEDIRECTORY
FileSystem.getHomeDirectory
GETDELEGATIONTOKEN
FileSystem.getDelegationToken
Hadoop RESTful API-Put
操作
参考
CREATE
FileSystem.create
MKDIRS
FileSystem.mkdirs
RENAME
FileSystem.rename
SETREPLICATION
FileSystem.setReplication
SETOWNER
FileSystem.setOwner
SETPERMISSION
FileSystem.setTimes
SETTIMES
FileSystem.getDelegationToken
RENEWDELEGATIONTOKEN
DistributedFileSystem.renewDelegationToken
CANCELDELEGATIONTOKEN
DistributedFileSystem.cancelDelegationToken
Hadoop RESTful API-Post与Delete
操作
参考
APPEND
FileSystem.append
DELETE
FileSystem.delete
第三部分:API 示例
Hadoop RESTful API 示例
什么是curl
curl是一个利用URL语法在命令行方式下工作的文件传输工具。它支持很多协议:FTP, FTPS, HTTP, HTTPS, GOPHER, TELNET, DICT,FILE 以及 LDAP。
curl同样支持HTTPS认证,HTTP POST方法, HTTP PUT方法, FTP 上传, kerberos认证, HTTP上传, 代理服务器, cookies, 用户名/密码认证, 下载文件断点续传, 上载文件断点续传, http代理服务器管道( proxy tunneling), 甚至它还支持IPv6, socks5代理服务器, 通过http代理服务器上传文件到FTP服务器等等,功能十分强大。Windows操作系统下的网络蚂蚁,网际快车(FlashGet)的功能它都可以做到。准确的说,curl支
持文件的上传和下载,所以是一个综合传输工具,但是按照传统,用户习惯称curl为下载工具。
配置RESTful API 可用
安装sudo apt-get install curl
在HDFS中设置 dfs.webhdfs.enabled = true
以下是我在自己的hdfs系统里测试的记录。需要注意以下两点:
一、配置
1、修改hadoop配置文件hdfs-site.xml,查看是否有下面配置项,如果没有请手动添加:
<property>
<name>dfs.webhdfs.enabled</name>
<value>true</value>
</property>
注:此配置在集群中所以节点的机器上都需要修改
2、同样配置hdfs-site.xml文件,查看是否有下面的配置项,如果没有就手动添加,dfs.permissions设置为false就是关闭了权限认证,因为我这里没有设置账号安全访问,所以需要设置为false,否则在测试的时候会报错 。报错信息类似“Permission denied: user=dr.who, access=WRITE”。
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
注:此配置在集群中所以机器上都需要修改
以下是我测试的记录:
1、创建并写一个文件
curl -i -X PUT"http://localhost:50070/webhdfs/v1/<PATH>?op=CREATE
[&overwrite=<true|false>][&blocksize=<LONG>][&replication=<SHORT>]
[&permission=<OCTAL>][&buffersize=<INT>]“
curl -i -X PUT -T<LOCAL_FILE> "http://<DATANODE>:<PORT>/webhdfs/v1/<PATH>?
op=CREATE...“
注意这个地方填入的是DataNode的信息
举例:
[root@hdb1 ~]# curl -i -X PUT "http://hdb1.yc.com:50070/webhdfs/v1/test?op=CREATE&overwrite=false&blocksize=1048576&replication=3&permission=755"
HTTP/1.1307 TEMPORARY_REDIRECT
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 04:02:39 GMT
Date:Fri, 21 Feb 2014 04:02:39 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 04:02:39 GMT
Date:Fri, 21 Feb 2014 04:02:39 GMT
Pragma:no-cache
Content-Type:application/octet-stream
Location:http://hdb2.yc.com:50075/webhdfs/v1/test?op=CREATE&namenoderpcaddress=hdb1.yc.com:8020&blocksize=1048576&overwrite=false&permission=755&replication=3
Content-Length:0
Server:Jetty(6.1.26)
[root@hdb1 ~]# curl -i -X PUT -T /etc/hosts "http://hdb2.yc.com:50075/webhdfs/v1/test/hostsac?op=CREATE&namenoderpcaddress=hdb1.yc.com:8020&blocksize=1048576&overwrite=false&permission=755&replication=3"
HTTP/1.1100 Continue
HTTP/1.1201 Created
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 06:14:13 GMT
Date:Fri, 21 Feb 2014 06:14:13 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 06:14:13 GMT
Date:Fri, 21 Feb 2014 06:14:13 GMT
Pragma:no-cache
Content-Type:application/octet-stream
Location:webhdfs://hda1.yc.com:50070/test/hostsac
Content-Length:0
Server:Jetty(6.1.26)
2、在一个文件内追加内容
curl -i -X POST"http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=APPEND[&buffersize=<INT>]”
curl -i -X POST -T<LOCAL_FILE> "http://<DATANODE>:<PORT>/webhdfs/v1/<PATH>?
op=APPEND...“
注意该条命令获得的是DataNode的信息。
举例:
[root@long-1 ~]# curl -i -X POST "http://hdb1.yc.com:50070/webhdfs/v1/test/hostsac?op=APPEND"
HTTP/1.1307 TEMPORARY_REDIRECT
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 06:20:30 GMT
Date:Fri, 21 Feb 2014 06:20:30 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 06:20:30 GMT
Date:Fri, 21 Feb 2014 06:20:30 GMT
Pragma:no-cache
Content-Type:application/octet-stream
Location:http://hda3.yc.com:50075/webhdfs/v1/test/hostsac?op=APPEND&namenoderpcaddress=hdb1.yc.com:8020
Content-Length:0
Server:Jetty(6.1.26)
[root@long-1 ~]# curl -i -X POST -T /var/log/yum.log"http://hda3.yc.com:50075/webhdfs/v1/test/hostsac?op=APPEND&namenoderpcaddress=hdb1.yc.com:8020"
HTTP/1.1100 Continue
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 06:22:43 GMT
Date:Fri, 21 Feb 2014 06:22:43 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 06:22:43 GMT
Date:Fri, 21 Feb 2014 06:22:43 GMT
Pragma:no-cache
Content-Type:application/octet-stream
Content-Length:0
Server:Jetty(6.1.26)
3、打开并读取一个文件
curl -i -L "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=OPEN
[&offset=<LONG>][&length=<LONG>][&buffersize=<INT>]"
举例:
[root@long-1 ~]# curl -i -L "http://hdb1.yc.com:50070/webhdfs/v1/test/hostsac?op=OPEN"
HTTP/1.1307 TEMPORARY_REDIRECT
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 06:39:38 GMT
Date:Fri, 21 Feb 2014 06:39:38 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 06:39:38 GMT
Date:Fri, 21 Feb 2014 06:39:38 GMT
Pragma:no-cache
Content-Type:application/octet-stream
Location:http://hda3.yc.com:50075/webhdfs/v1/test/hostsac?op=OPEN&namenoderpcaddress=hdb1.yc.com:8020&offset=0
Content-Length:0
Server:Jetty(6.1.26)
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 06:39:38 GMT
Date:Fri, 21 Feb 2014 06:39:38 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 06:39:38 GMT
Date:Fri, 21 Feb 2014 06:39:38 GMT
Pragma:no-cache
Content-Type:application/octet-stream
Content-Length:946
Server:Jetty(6.1.26)
127.0.0.1 localhost localhost.localdomain localhost4localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.200.61long-1.yc.com
192.168.200.62long-2.yc.com
192.168.200.63hda1.yc.com
192.168.200.64hda2.yc.com
192.168.200.65hda3.yc.com
192.168.200.66hdb1.yc.com
192.168.200.67hdb2.yc.com
192.168.200.68hdb3.yc.com
Jan 0210:59:57 Installed: tigervnc-1.1.0-5.el6_4.1.x86_64
Jan 0415:01:39 Installed: 1:links-2.2-12.el6.x86_64
Jan 1219:17:06 Installed: cloudera-cdh-4-0.x86_64
Jan 1220:40:51 Updated: 1:nfs-utils-1.2.3-39.el6.x86_64
Jan 2811:51:49 Updated: openssh-5.3p1-94.el6.x86_64
Jan 2811:51:49 Updated: openssh-askpass-5.3p1-94.el6.x86_64
Jan 2811:51:50 Updated: openssh-server-5.3p1-94.el6.x86_64
Jan 2811:51:50 Updated: openssh-clients-5.3p1-94.el6.x86_64
Feb 1401:48:59 Updated: yum-utils-1.1.30-17.el6_5.noarch
Feb 1404:27:30 Updated: iftop-1.0-0.7.pre4.el6.x86_64
4、创建一个目录
curl-i -X PUT "http://<HOST>:<PORT>/<PATH>?op=MKDIRS[&permission=<OCTAL>]"
举例:
[root@long-1 ~]# curl -i -X PUT "http://hdb1.yc.com:50070/webhdfs/v1/test/longge?op=MKDIRS"
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 06:51:00 GMT
Date:Fri, 21 Feb 2014 06:51:00 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 06:51:00 GMT
Date:Fri, 21 Feb 2014 06:51:00 GMT
Pragma:no-cache
Content-Type:application/json
Transfer-Encoding:chunked
Server:Jetty(6.1.26)
5、目录列表
curl-i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=LISTSTATUS"
举例:
[root@long-1 ~]# curl -i "http://hdb1.yc.com:50070/webhdfs/v1/test?op=LISTSTATUS"
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 06:55:02 GMT
Date:Fri, 21 Feb 2014 06:55:02 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 06:55:02 GMT
Date:Fri, 21 Feb 2014 06:55:02 GMT
Pragma:no-cache
Content-Type:application/json
Transfer-Encoding:chunked
Server:Jetty(6.1.26)
{"FileStatuses":{"FileStatus":[
{"accessTime":0,"blockSize":0,"childrenNum":2,"fileId":16796,"group":"hdfs","length":0,"modificationTime":1392489528027,"owner":"hdfs","pathSuffix":"10gsort","permission":"755","replication":0,"type":"DIRECTORY"},
{"accessTime":1392962339305,"blockSize":1048576,"childrenNum":0,"fileId":17204,"group":"hdfs","length":0,"modificationTime":1392962339392,"owner":"dr.who","pathSuffix":"hostsaa","permission":"755","replication":3,"type":"FILE"},
{"accessTime":1392962448632,"blockSize":1048576,"childrenNum":0,"fileId":17205,"group":"hdfs","length":0,"modificationTime":1392962448667,"owner":"dr.who","pathSuffix":"hostsab","permission":"755","replication":3,"type":"FILE"},
{"accessTime":1392963253927,"blockSize":1048576,"childrenNum":0,"fileId":17206,"group":"hdfs","length":946,"modificationTime":1392963766592,"owner":"dr.who","pathSuffix":"hostsac","permission":"755","replication":3,"type":"FILE"},
{"accessTime":0,"blockSize":0,"childrenNum":0,"fileId":17207,"group":"hdfs","length":0,"modificationTime":1392965460048,"owner":"dr.who","pathSuffix":"longge","permission":"755","replication":0,"type":"DIRECTORY"}
]}}
6、删除文件/文件夹
curl-i -X DELETE "http://<host>:<port>/webhdfs/v1/<path>?op=DELETE[&recursive=<true|false>]"
举例:recursive递归
[root@long-1 ~]# curl -i -X DELETE "http://hdb1.yc.com:50070/webhdfs/v1/test/longge?op=DELETE&recursive=true"
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 07:02:32 GMT
Date:Fri, 21 Feb 2014 07:02:32 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 07:02:32 GMT
Date:Fri, 21 Feb 2014 07:02:32 GMT
Pragma:no-cache
Content-Type:application/json
Transfer-Encoding:chunked
Server:Jetty(6.1.26)
7、文件/ 文件夹的状态信息
curl-i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILESTATUS"
举例:
[root@long-1 ~]# curl -i "http://hdb1.yc.com:50070/webhdfs/v1/test?op=GETFILESTATUS"
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 07:04:16 GMT
Date:Fri, 21 Feb 2014 07:04:16 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 07:04:16 GMT
Date:Fri, 21 Feb 2014 07:04:16 GMT
Pragma:no-cache
Content-Type:application/json
Transfer-Encoding:chunked
Server:Jetty(6.1.26)
{"FileStatus":{"accessTime":0,"blockSize":0,"childrenNum":4,"fileId":16795,"group":"hdfs","length":0,"modificationTime":1392966152796,"owner":"hdfs","pathSuffix":"","permission":"755","replication":0,"type":"DIRECTORY"}}
8、重名命文件、文件夹
curl -i -X PUT"<HOST>:<PORT>/webhdfs/v1/<PATH>?op=RENAME&destination=<PATH>"
举例:
[root@long-1 ~]# curl -i -X PUT "http://hdb1.yc.com:50070/webhdfs/v1/test?op=RENAME&destination=/test-long"
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 07:08:38 GMT
Date:Fri, 21 Feb 2014 07:08:38 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 07:08:38 GMT
Date:Fri, 21 Feb 2014 07:08:38 GMT
Pragma:no-cache
Content-Type:application/json
Transfer-Encoding:chunked
Server:Jetty(6.1.26)
查看重命名结果:列出根目录:
[root@long-1 ~]# curl -i "http://hdb1.yc.com:50070/webhdfs/v1/?op=LISTSTATUS"
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 07:11:02 GMT
Date:Fri, 21 Feb 2014 07:11:02 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 07:11:02 GMT
Date:Fri, 21 Feb 2014 07:11:02 GMT
Pragma:no-cache
Content-Type:application/json
Transfer-Encoding:chunked
Server:Jetty(6.1.26)
{"FileStatuses":{"FileStatus":[
{"accessTime":0,"blockSize":0,"childrenNum":2,"fileId":16399,"group":"hadoop","length":0,"modificationTime":1392792439062,"owner":"yarn","pathSuffix":"app-logs","permission":"1777","replication":0,"type":"DIRECTORY"},
{"accessTime":0,"blockSize":0,"childrenNum":3,"fileId":16386,"group":"hdfs","length":0,"modificationTime":1392334692014,"owner":"hdfs","pathSuffix":"apps","permission":"755","replication":0,"type":"DIRECTORY"},
{"accessTime":0,"blockSize":0,"childrenNum":1,"fileId":16395,"group":"hdfs","length":0,"modificationTime":1392334781468,"owner":"mapred","pathSuffix":"mapred","permission":"755","replication":0,"type":"DIRECTORY"},
{"accessTime":0,"blockSize":0,"childrenNum":2,"fileId":16393,"group":"hdfs","length":0,"modificationTime":1392334816125,"owner":"hdfs","pathSuffix":"mr-history","permission":"755","replication":0,"type":"DIRECTORY"},
{"accessTime":0,"blockSize":0,"childrenNum":4,"fileId":16795,"group":"hdfs","length":0,"modificationTime":1392966152796,"owner":"hdfs","pathSuffix":"test-long","permission":"755","replication":0,"type":"DIRECTORY"},
{"accessTime":0,"blockSize":0,"childrenNum":4,"fileId":16390,"group":"hdfs","length":0,"modificationTime":1392792312074,"owner":"hdfs","pathSuffix":"tmp","permission":"777","replication":0,"type":"DIRECTORY"},
{"accessTime":0,"blockSize":0,"childrenNum":5,"fileId":16400,"group":"hdfs","length":0,"modificationTime":1392487709267,"owner":"hdfs","pathSuffix":"user","permission":"755","replication":0,"type":"DIRECTORY"}
]}}
9、获取目录的上下文环境汇总信息
curl -i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETCONTENTSUMMARY"
举例:
[root@long-1 ~]# curl -i "http://hdb1.yc.com:50070/webhdfs/v1/?op=GETCONTENTSUMMARY"
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 07:14:00 GMT
Date:Fri, 21 Feb 2014 07:14:00 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 07:14:00 GMT
Date:Fri, 21 Feb 2014 07:14:00 GMT
Pragma:no-cache
Content-Type:application/json
Transfer-Encoding:chunked
Server:Jetty(6.1.26)
{"ContentSummary":{"directoryCount":159,"fileCount":494,"length":522816747,"quota":9223372036854775807,"spaceConsumed":2778053075,"spaceQuota":-1}}
10、获取Check Sum File
curl-i "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=GETFILECHECKSUM"
举例:
[root@long-1 ~]# curl -i "http://hdb1.yc.com:50070/webhdfs/v1/test-long?op=GETFILECHECKSUM"
HTTP/1.1307 TEMPORARY_REDIRECT
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 07:15:56 GMT
Date:Fri, 21 Feb 2014 07:15:56 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 07:15:56 GMT
Date:Fri, 21 Feb 2014 07:15:56 GMT
Pragma:no-cache
Content-Type:application/octet-stream
Location:http://hda2.yc.com:50075/webhdfs/v1/test-long?op=GETFILECHECKSUM&namenoderpcaddress=hdb1.yc.com:8020
Content-Length:0
Server:Jetty(6.1.26)
11、获取Home 目录
curl-i "http://<HOST>:<PORT>/webhdfs/v1/?op=GETHOMEDIRECTORY"
举例:
[root@long-1 ~]# curl -i "http://hdb1.yc.com:50070/webhdfs/v1/test-long/hostsac?op=GETHOMEDIRECTORY"
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 07:21:06 GMT
Date:Fri, 21 Feb 2014 07:21:06 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 07:21:06 GMT
Date:Fri, 21 Feb 2014 07:21:06 GMT
Pragma:no-cache
Content-Type:application/json
Transfer-Encoding:chunked
Server:Jetty(6.1.26)
{"Path":"/user/dr.who"}
12、设置权限
curl-i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETPERMISSION?[&permission=<OCTAL>]"
举例:
[root@long-1 ~]# curl -i -X PUT "http://hdb1.yc.com:50070/webhdfs/v1/test-long/hostsac?op=SETPERMISSION&permission=766"
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 07:24:37 GMT
Date:Fri, 21 Feb 2014 07:24:37 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 07:24:37 GMT
Date:Fri, 21 Feb 2014 07:24:37 GMT
Pragma:no-cache
Content-Type:application/octet-stream
Content-Length:0
Server:Jetty(6.1.26)
查看权限设置结果:
[root@long-1 ~]#curl -i "http://hdb1.yc.com:50070/webhdfs/v1/test-long/hostsac?op=LISTSTATUS"
HTTP/1.1 200 OK
Cache-Control:no-cache
Expires: Fri, 21 Feb2014 07:25:59 GMT
Date: Fri, 21 Feb2014 07:25:59 GMT
Pragma: no-cache
Expires: Fri, 21 Feb2014 07:25:59 GMT
Date: Fri, 21 Feb2014 07:25:59 GMT
Pragma: no-cache
Content-Type:application/json
Transfer-Encoding:chunked
Server:Jetty(6.1.26)
{"FileStatuses":{"FileStatus":[
{"accessTime":1392963253927,"blockSize":1048576,"childrenNum":0,"fileId":17206,"group":"hdfs","length":946,"modificationTime":1392963766592,"owner":"dr.who","pathSuffix":"","permission":"766","replication":3,"type":"FILE"}
]}}
13、设置所有者
curl -i -X PUT"http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETOWNER?[&owner=<USER>][&group=<GROUP>]"
举例:
[root@long-1 ~]# curl -i -X PUT "http://hdb1.yc.com:50070/webhdfs/v1/test-long/hostsac?op=SETOWNER&owner=hdfs&group=hdfs"
14、设置备份
curl-i -X PUT "http://<HOST>:<PORT>/webhdfs/v1/<PATH>?op=SETREPLICATION?[&replication=<SHORT>]"
举例:
[root@long-1 ~]# curl -i -X PUT "http://hdb1.yc.com:50070/webhdfs/v1/test-long/hostsac?op=SETREPLICATION&replication=4"
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 07:31:24 GMT
Date:Fri, 21 Feb 2014 07:31:24 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 07:31:24 GMT
Date:Fri, 21 Feb 2014 07:31:24 GMT
Pragma:no-cache
Content-Type:application/json
Transfer-Encoding:chunked
Server:Jetty(6.1.26)
[root@long-1 ~]# curl -i "http://hdb1.yc.com:50070/webhdfs/v1/test-long/hostsac?op=LISTSTATUS"
HTTP/1.1200 OK
Cache-Control:no-cache
Expires:Fri, 21 Feb 2014 07:32:00 GMT
Date:Fri, 21 Feb 2014 07:32:00 GMT
Pragma:no-cache
Expires:Fri, 21 Feb 2014 07:32:00 GMT
Date:Fri, 21 Feb 2014 07:32:00 GMT
Pragma:no-cache
Content-Type:application/json
Transfer-Encoding:chunked
Server:Jetty(6.1.26)
{"FileStatuses":{"FileStatus":[
{"accessTime":1392963253927,"blockSize":1048576,"childrenNum":0,"fileId":17206,"group":"hdfs","length":946,"modificationTime":1392963766592,"owner":"dr.who","pathSuffix":"","permission":"766","replication":4,"type":"FILE"}
]}}