前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在emr中使用httpfs组件

在emr中使用httpfs组件

原创
作者头像
wellgao
修改2018-07-02 17:35:38
1.9K3
修改2018-07-02 17:35:38
举报

httpfs是hadoop中HDFS over HTTP的实现,为HDFS的读写操作提供了统一的REST HTTP接口。在一些特定场景下非常有用,例如不同hadoop版本集群间数据拷贝, 使用httpfs作为对外提供数据访问的网关等。

httpfs组件与namenode内置的http接口都能提供webhdfs http接口,但二者不同的是httpfs可以作为独立服务部署到其他节点上,从而与namenode互相独立。

在emr V2版本中已经默认在master节点上启动了httpfs组件,无需单独部署和启动,emr V1版本或者在非emr节点的客户机中启动方式如下:

代码语言:shell
复制
su - hadoop
/usr/local/service/hadoop/sbin/httpfs.sh start

emr中默认配置的httpfs端口为4032,启动之后即可通过下面方式进行测试:

代码语言:shell
复制
$ curl "localhost:4032/webhdfs/v1?user.name=hadoop&op=gethomedirectory"   
{"Path":"\/user\/hadoop"}

通过hdfs客户端进行测试:

代码语言:shell
复制
$ hdfs dfs -ls webhdfs://localhost:4032/
Found 7 items
drwxr-xr-x   - hadoop supergroup          0 2018-05-25 15:28 webhdfs://localhost:4032/apps
drwxrwx---   - hadoop supergroup          0 2018-05-31 19:06 webhdfs://localhost:4032/emr
drwxr-xr-x   - hadoop supergroup          0 2018-05-29 15:36 webhdfs://localhost:4032/hbase
drwxr-xr-x   - hadoop supergroup          0 2018-06-06 16:49 webhdfs://localhost:4032/spark-history
drwx-wx-wx   - hadoop supergroup          0 2018-05-28 15:09 webhdfs://localhost:4032/tmp
drwxr-xr-x   - hadoop supergroup          0 2018-05-28 15:06 webhdfs://localhost:4032/user
drwxr-xr-x   - hadoop supergroup          0 2018-05-31 19:04 webhdfs://localhost:4032/usr

通过python hdfs模块访问测试:

将测试代码保存至hdfs_t.py, 测试代码如下:

代码语言:python
复制
#!/usr/bin/env python

from hdfs import InsecureClient
client = InsecureClient('http://localhost:4032', user='hadoop')

# Read a file
with client.read('/tmp/1.txt') as reader:
    txt = reader.read()
    print txt
# Write a file
data_str =  "test hdfs write"
client.write('/tmp/2.txt', data=data_str, encoding='utf-8')

# Upload a file
client.upload('/tmp/', './testhttpfs', n_threads=5)

执行以下命令安装模块并执行测试脚本:

代码语言:javascript
复制
# 安装模块
yum -y install python-pip
pip install hdfs
# 准备测试文件
date >1.txt
hdfs dfs -put 1.txt /tmp/
# 执行测试脚本
python hdfs_t.py

webhdfs api文档参考链接:

https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-hdfs/WebHDFS.html

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档