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

HDFS connection failed:
Common causes of errors may be:
1. Hadoop is not started (not all started). Hadoop is normally started including the following services. If the services are not all started, you can check the log

2. Installation of pseudo-distributed mode; localhost or is used in the configuration file; at this time, the real ID should be changed, including core-site.xml, Mapred-site.xml, Slaves,
Masters, after modifying IP, the dataNode may fail to start,
Set DFS. Data.dir in the HDFs-site.xml profile:
& lt; property>
& lt; name> dfs.data.dir< /name>
& lt; value> /data/hdfs/data< /value>
& lt; /property>  
Delete all files in the folder in Hadoop and restart Hadoop

Read More: