[Solved] Call to localhost/ failed on connection exception:java.net.ConnectException

Call to localhost/ failed on connection exception:java.net.ConnectException Solutions for

When starting Hadoop, the following error occurred:

Call From java.net.UnknownHostException: ubuntu-larntin: ubuntu-larntin to localhost:9000 failed on connection exception: java.net.ConnectException: Connection refused;

And start datanode, yarn are normal, only the namenode has been hanging up

The solution is as follows:

[email protected]:~$ hadoop namenode -format

After that, restart all the clusters

[email protected]:~$ cd /home/wrr/java/hadoop-2.7.6/sbin
[email protected]:~/java/hadoop-2.7.6/sbin$ ./hadoop-daemon.sh start namenode
starting namenode, logging to /home/wrr/java/hadoop-2.7.6/logs/hadoop-wrr-namenode-ubuntu.out
[email protected]:~/java/hadoop-2.7.6/sbin$ jps
8307 DataNode
9317 NameNode
9352 Jps
8476 ResourceManager

After that, run the program on eclipse again, and it’s OK

A new Java file is created

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
public class HDFSFileIfExist {
    public static void main(String[] args){
            String fileName = "test";
            Configuration conf = new Configuration();
            conf.set("fs.defaultFS", "hdfs://localhost:9000");
            conf.set("fs.hdfs.impl", "org.apache.hadoop.hdfs.DistributedFileSystem");
            FileSystem fs = FileSystem.get(conf);
            if(fs.exists(new Path(fileName))){
                System.out.println("Files Exsit");
                System.out.println("Files Do Not Exsit");
        }catch (Exception e){

Determine whether the test file exists in the current hadoop-2.7.6 directory

Similar Posts: