用于在hdfs中列出目录的主机和端口

Tri*_*tan 6 java hadoop hdfs hortonworks-data-platform

首先,我使用HortonWorks Sandbox作为Hadoop dist,根本没有自定义配置.

一旦连接到沙箱上,我就能列出一个HDFS目录的文件:

[root@sandbox ~]# hadoop fs -ls hdfs:///user/guest

但如果我尝试指定主机和端口,我只会得到错误:

[root@sandbox ~]# hadoop fs -ls hdfs://localhost:8020/user/guest ls: Call From sandbox.hortonworks.com/10.0.2.15 to localhost:8020 failed on connection exception: java.net.ConnectException: Connexion refusée; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused

[root@sandbox ~]# hadoop fs -ls hdfs://localhost:9000/user/guest ls: Call From sandbox.hortonworks.com/10.0.2.15 to localhost:9000 failed on connection exception: java.net.ConnectException: Connexion refusée; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused

一旦我知道要使用的正确主机和端口,我就可以在我的Java调用中使用它们:

Path pt = new Path("hdfs://host:port/user/guest/test-text-file.txt");

Ash*_*ith 9

检查的财产的价值fs.defaultFScore-site.xml这个包含其中的NameNode守护进程应该绑定到时候开始的了的IP地址/主机名和端口.

我看到你正在使用hortonworks沙箱,这里是属性core-site.xml和它的位置/etc/hadoop/conf/core-site.xml

<property>
  <name>fs.defaultFS</name>
  <value>hdfs://sandbox.hortonworks.com:8020</value>
</property>
Run Code Online (Sandbox Code Playgroud)

所以,你可以尝试这样的事情:

hadoop fs -ls hdfs://sandbox.hortonworks.com:8020/user/guest 
Run Code Online (Sandbox Code Playgroud)

或者您也可以在我的虚拟机上替换sandbox.hortonworks.com其各自条目中的IP地址,/etc/hosts如下所示:

127.0.0.1       localhost.localdomain localhost
192.168.1.3 sandbox.hortonworks.com sandbox
Run Code Online (Sandbox Code Playgroud)

所以,我也可以试试这个:

hadoop fs -ls hdfs://192.168.1.3:8020/user/guest
Run Code Online (Sandbox Code Playgroud)