Remote access to namenode is not allowed despite the services are already started.

woraphol.j picture woraphol.j · Jan 1, 2012 · Viewed 9.7k times · Source

I successfully installed and run Hadoop on a single machine whose ip is 192.168.1.109 (In fact it is actually an Ubuntu instance running on virtual box ) . When typing jps it shows

2473 DataNode

2765 TaskTracker

3373 Jps

2361 NameNode

2588 SecondaryNameNode

2655 JobTracker

This should mean that the hadoop is up and running. Running commands like ./hadoop fs -ls is fine and produces the expected result.

But If I try to connect it from my windows box whose ip is 192.168.1.80 by writing Java code's HDFS API to connect it as follows:

Configuration conf = new Configuration();

FileSystem hdfs = null;

Path filenamePath = new Path(FILE_NAME);

hdfs = FileSystem.get(conf); <-- the problem occurred at this line

when I run the code, the error displayed as follows:

11/12/07 20:37:24 INFO ipc.Client: Retrying connect to server: /192.168.1.109:9000. Already tried 0 time(s).

11/12/07 20:37:26 INFO ipc.Client: Retrying connect to server: /192.168.1.109:9000. Already tried 1 time(s).

11/12/07 20:37:28 INFO ipc.Client: Retrying connect to server: /192.168.1.109:9000. Already tried 2 time(s).

11/12/07 20:37:30 INFO ipc.Client: Retrying connect to server: /192.168.1.109:9000. Already tried 3 time(s).

11/12/07 20:37:32 INFO ipc.Client: Retrying connect to server: /192.168.1.109:9000. Already tried 4 time(s).

11/12/07 20:37:33 INFO ipc.Client: Retrying connect to server: /192.168.1.109:9000. Already tried 5 time(s).

11/12/07 20:37:35 INFO ipc.Client: Retrying connect to server: /192.168.1.109:9000. Already tried 6 time(s).

11/12/07 20:37:37 INFO ipc.Client: Retrying connect to server: /192.168.1.109:9000. Already tried 7 time(s).

11/12/07 20:37:39 INFO ipc.Client: Retrying connect to server: /192.168.1.109:9000. Already tried 8 time(s).

11/12/07 20:37:41 INFO ipc.Client: Retrying connect to server: /192.168.1.109:9000. Already tried 9 time(s).

java.net.ConnectException: Call to /192.168.1.109:9000 failed on connection exception: java.net.ConnectException: Connection refused: no further information

To make sure if the socket is already opened and waits for the incoming connections on the hadoop serer, I netstat on the ubuntu box the result shows as follows:

tcp 0 0 localhost:51201 : LISTEN 2765/java
tcp 0 0 *:50020 : LISTEN 2473/java
tcp 0 0 localhost:9000 : LISTEN 2361/java
tcp 0 0 localhost:9001 : LISTEN 2655/java
tcp 0 0 *:mysql : LISTEN -
tcp 0 0 *:50090 : LISTEN 2588/java
tcp 0 0 *:11211 : LISTEN -
tcp 0 0 *:40843 : LISTEN 2473/java
tcp 0 0 *:58699 : LISTEN -
tcp 0 0 *:50060 : LISTEN 2765/java
tcp 0 0 *:50030 : LISTEN 2655/java
tcp 0 0 *:53966 : LISTEN 2655/java
tcp 0 0 *:www : LISTEN -
tcp 0 0 *:epmd : LISTEN -
tcp 0 0 *:55826 : LISTEN 2588/java
tcp 0 0 *:ftp : LISTEN -
tcp 0 0 *:50070 : LISTEN 2361/java
tcp 0 0 *:52822 : LISTEN 2361/java
tcp 0 0 *:ssh : LISTEN -
tcp 0 0 *:55672 : LISTEN -
tcp 0 0 *:50010 : LISTEN 2473/java
tcp 0 0 *:50075 : LISTEN 2473/java

I noticed that if the local address column is something like localhost:9000 (starts with localhost: not *:) It will not be able to be connected from remote host or even in it own box in some case. I tried telnet localhost 9000 it works, I means it can connect to the port but If I use telnet 192.168.1.109 9000 The errors displays like

$ telnet 192.168.1.109 9000 Trying 192.168.1.109... telnet: Unable to connect to remote host: Connection refused

I have spent almost a week figuring out the issue I am really exhausted now and I hope someone can help me.

Note: I am not sure if namenode by default refuses remote connection. Do I need to change some settings in order for it to allow remote connections?

Answer

Praveen Sripati picture Praveen Sripati · Jan 1, 2012

Change the value of fs.default.name to hdfs://106.77.211.187:9000 from hdfs://localhost:9000in core-site.xml for both the client and the NameNode. Replace the IP address with the IP address of the node on which the NameNode is running or with the hostname.

Was able to telnet 106.77.211.187 9000 and here is the output of netstat -a | grep 9000

tcp6 0 0 106.77.211.187:9000 [::]:* LISTEN
tcp6 0 0 106.77.211.187:50753 106.77.211.187%819:9000 ESTABLISHED
tcp6 0 0 106.77.211.187:9000 106.77.211.187%81:50753 ESTABLISHED

As to why, the source code look like the following for fs.default.name set to localhost

ServerSocket socket = new ServerSocket(9000);
socket.bind(localhost);

Because bind address is assigned to localhost, the namenode process only can accept connection from localhost. If bind address is assigned to the name of machine name or ip address, then namenode process can accept any connection from remote machine.