如何将文件从本地笔记本电脑放到远程HDFS?

问题描述:

我的Hadoop 2.8.1如何将文件从本地笔记本电脑放到远程HDFS?

可配置HDFS-site.xml中

<configuration> 
# Add the following inside the configuration tag 
<property> 
     <name>dfs.data.dir</name> 
     <value>/app/dfs/name/data</value> 
     <final>true</final> 
</property> 
<property> 
     <name>dfs.name.dir</name> 
     <value>/app/dfs/name</value> 
     <final>true</final> 
</property> 
<property> 
     <name>dfs.replication</name> 
     <value>1</value> 
</property> 
<property> 
    <name>dfs.webhdfs.enabled</name> 
    <value>true</value> 
</property> 
</configuration> 

难道被Python发现这个代码

from pywebhdfs.webhdfs import PyWebHdfsClient 
from pprint import pprint 

hdfs = PyWebHdfsClient(host='hadoop01',port='50070', user_name='hadoop') # your Namenode IP & username here 

my_data = "01010101010101010101010101010101000111 Example DataSet" 
my_file = '/examples/myfile.txt' 
hdfs.create_file(my_file, my_data.encode('utf-8')) 

这个变种工作。 但我想把已经准备好的文件放到远程HDFS上。

试图写

with open("C:\\Downloads\\Demographic_Statistics_By_Zip_Code.csv") as file_data: 
    print(file_data) 

但文件并没有投入到HDFS。 只返回

<_io.TextIOWrapper name='C:\\Downloads\\Demographic_Statistics_By_Zip_Code.csv' mode='r' encoding='cp1251'> 

如何解决这种情况?

如何使用hdfs cli? 请参考copyFromLocal或从这个链接把命令:

https://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-common/FileSystemShell.html