设为首页 加入收藏

TOP

使用python连接hdfs 文件系统,实现上传文件
2018-12-07 00:15:05 】 浏览:109
Tags:使用 python 连接 hdfs 文件 系统 实现 上传

一、在用户的根目录下写配置文件

(mypython) [root@hadoop-yarn-117 ~]# vi .hdfscli.cfg 
[global]
default.alias = dev


[dev.alias]
url = http://hadoop-yarn-117:50070
user = root 

二、使用python连接

from hdfs import Config

client = Config().get_client()
'''
list_file = client.list('/data01')
print(list_file)
with client.read('/data01/README.txt', chunk_size=1280) as reader:
    for chunk in reader:
        print(chunk.decode().replace(' ', '\n '))
'''
with open('/root/docu/nginx-access.log') as opener, client.write('/data01/nginx.log') as writer:
    for line in opener:
        writer.write(bytes(line, encoding='utf-8'))


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇通过命令来查看HDFS集群NameNode.. 下一篇centos-7 部署hadoop2.5.1 >&g..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目