Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Host and port to use to list a directory in hdfs

First of all, I'm using HortonWorks Sandbox as Hadoop dist, with no custom configuration at all.

Once connected on the sandbox, I'm able to list files of a HDFS directory doing :

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

but if I try to specify a host and port I get only errors :

[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

Once I know the correct host and port to use, I'll be able to use them in my Java call :

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

like image 995
Tristan Avatar asked Nov 24 '14 14:11

Tristan


People also ask

How do I list only directories in HDFS?

hadoop fs -ls -R command list all the files and directories in HDFS. grep “^d” will get you only the directories.

How do I search for a directory in HDFS?

Using the ls command, we can check for the directories in HDFS.

How do I find my HDFS port number?

You can open this address in your browser and check the namenode information. The default address of namenode server is hdfs://localhost:8020/. You can connect to it to access HDFS by HDFS api.

Which command is used for display the list of files and directories in HDFS?

ls: List directories present under a specific directory in HDFS, similar to Unix ls command. The -lsr command can be used for recursive listing of directories and files.


1 Answers

Check the value of property fs.defaultFS in core-site.xml this contains the ip-address/hostname and port on which NameNode daemon should bind to when it start's up.

I see that you are using hortonworks sandbox, here is the property in core-site.xml and its located in /etc/hadoop/conf/core-site.xml

<property>
  <name>fs.defaultFS</name>
  <value>hdfs://sandbox.hortonworks.com:8020</value>
</property>

So, you could try something like this:

hadoop fs -ls hdfs://sandbox.hortonworks.com:8020/user/guest 

Or you could also replace the ip address of sandbox.hortonworks.com from its respective entry in /etc/hosts, on my vm which looks something like this:

127.0.0.1       localhost.localdomain localhost
192.168.1.3 sandbox.hortonworks.com sandbox

So, I could try this as well:

hadoop fs -ls hdfs://192.168.1.3:8020/user/guest
like image 157
Ashrith Avatar answered Oct 29 '22 06:10

Ashrith