Hadoop格式化时,出现java.net.UnknownHostException: XXX: XXX异常

错误提示:找不到主机名

错误代码如下:

java.net.UnknownHostException: liujian: liujian
	at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
	at org.apache.hadoop.net.DNS.resolveLocalHostname(DNS.java:264)
	at org.apache.hadoop.net.DNS.(DNS.java:57)
	at org.apache.hadoop.hdfs.server.namenode.NNStorage.newBlockPoolID(NNStorage.java:947)
	at org.apache.hadoop.hdfs.server.namenode.NNStorage.newNamespaceInfo(NNStorage.java:573)
	at org.apache.hadoop.hdfs.server.namenode.FSImage.format(FSImage.java:144)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:926)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1354)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1473)
Caused by: java.net.UnknownHostException: liujian
	at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
	at java.net.InetAddress.getLocalHost(InetAddress.java:1469)
	... 8 more
20/07/27 20:13:44 WARN net.DNS: Unable to determine address of the host-falling back to "localhost" address
java.net.UnknownHostException: liujian: liujian
	at java.net.InetAddress.getLocalHost(InetAddress.java:1473)
	at org.apache.hadoop.net.DNS.resolveLocalHostIPAddress(DNS.java:287)
	at org.apache.hadoop.net.DNS.(DNS.java:58)
	at org.apache.hadoop.hdfs.server.namenode.NNStorage.newBlockPoolID(NNStorage.java:947)
	at org.apache.hadoop.hdfs.server.namenode.NNStorage.newNamespaceInfo(NNStorage.java:573)
	at org.apache.hadoop.hdfs.server.namenode.FSImage.format(FSImage.java:144)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:926)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1354)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1473)
Caused by: java.net.UnknownHostException: liujian
	at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:901)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1293)
	at java.net.InetAddress.getLocalHost(InetAddress.java:1469)

解决方法:

 编辑:/etc/hosts文件

注释:

192.xxx.1.xxx  : 应用ip地址

localhost.localdomain : 为域名,可以不加

liujian:主机名称

------------------------------------------

再次执行格式化:

 bin/hdfs namenode -format

完事!(完成后检查是否还有其他报错)

你可能感兴趣的:(hadoop)