0
  package org.myorg;

  import java.security.PrivilegedExceptionAction;

  import org.apache.hadoop.conf.*;
  import org.apache.hadoop.security.UserGroupInformation;
  import org.apache.hadoop.fs.Path;
  import org.apache.hadoop.fs.FileSystem;
  import org.apache.hadoop.fs.FileStatus;

  public class Write{

    public static void main(String args[]) {
           try {
                // UserGroupInformation ugi = UserGroupInformation.createRemoteUser("hbase");

                 UserGroupInformation ugi = UserGroupInformation.getLoginUser();

                 ugi.doAs(new PrivilegedExceptionAction<Void>() {
                     public Void run() throws Exception
                     {
                         Configuration conf = new Configuration();
                         conf.set("fs.default.name", "hdfs://10.72.40.XX:8020/user/hbase");

                        //conf.set("hadoop.job.ugi", "hbase");

                         conf.set("hadoop.job.ugi", "root");
                         FileSystem fs = FileSystem.get(conf);

                         fs.createNewFile(new Path("/user/hbase/test"));

                         System.out.println("File Created");
                        return null;
                     }
                 });
               }
          catch(Exception e)
         {
            e.printStackTrace();
         }

 }
}

This is my java file.

My ip is 10.72.40.XX

  hostname -i

gives this ip to me.

 jps

says

 Jobtracker, namenode, datanode, tasktracker, secondarynamenode, jps

are running.

I compiled this java program using

 javac -classpath hadoop-core-1.1.2.jar -d Write/ Write.java

Created jar using

 jar -cvf Write.jar -C Write/ .

Run this program using

 hadoop-1.2.1/bin/hadoop jar Write.jar org.myorg.Write

It says,

 Retrying 0-9 [10] times

  failed on connection exception: java.net.ConnectException: Connection refused

Then i checked if something is listening at port 8020

 netstat -plten | grep java

 tcp        0      0 ::ffff:127.0.0.1:8020       :::*                        LISTEN      0          55639      15717/java

returns service is listening at port 8020.

Then, for debugging purpose, i replaced ip with localhost, It is succeeded. What could be the problem?

How do i solve it?

Does ip and localhost are different for the same machine?

Gibbs
  • 21,904
  • 13
  • 74
  • 138
  • plus1 for the security mindedness of hiding the last octet of your local ip address! –  Feb 12 '15 at 12:39
  • What is the actual output of the netstat command? – muru Feb 12 '15 at 12:55
  • @muru updated the question with netstat actual outpu – Gibbs Feb 12 '15 at 13:02
  • @GopsAB There you have it. The process is only listening on localhost, that's why you can only connect on localhost. Look through the configuration, there must be some place where you can specify which IP/interface it should listen on. – muru Feb 12 '15 at 13:10
  • ok muru. So i should change localhost to my ip in my conf file. Right? – Gibbs Feb 12 '15 at 14:11
  • @muru Credit goes to you. I thought both loclahost and ip are same. But you cracked it. Please add it as answer. – Gibbs Feb 12 '15 at 14:38

1 Answers1

0

The netstat output indicates that it is only listening on localhost (::ffff:127.0.0.1:8020 is port 8020 on localhost). You could edit your service configuration, where there must be an entry for the interface/IP it listens on. There, you can change localhost/127.0.0.1 to the external IP. For many services, you can use 0.0.0.0 to indicate that it should listen on all services.

muru
  • 4,723
  • 1
  • 34
  • 78
  • 1
    Thanks. edit `core-site.xml` where there is a value `localhost:8020`. Replace it with the ip. Then it ll work fine. – Gibbs Feb 12 '15 at 14:44
  • Will you please help me with [this](http://stackoverflow.com/questions/28582312/connection-is-not-being-established) – Gibbs Feb 18 '15 at 11:21