HDFS格式化失败,java.Net.UnknownHostException异常处理方法

一、HDFS格式化失败

报错代码:

WARN net.DNS: Unable to determine local hostname -falling back to "localhost"
java.net.UnknownHostException: hadoop000: hadoop000
	at java.net.InetAddress.getLocalHost(InetAddress.java:1496)
	at org.apache.hadoop.net.DNS.resolveLocalHostname(DNS.java:264)
	at org.apache.hadoop.net.DNS.<clinit>(DNS.java:57)
	at org.apache.hadoop.hdfs.server.namenode.NNStorage.newBlockPoolID(NNStorage.java:966)
	at org.apache.hadoop.hdfs.server.namenode.NNStorage.newNamespaceInfo(NNStorage.java:575)
	at org.apache.hadoop.hdfs.server.namenode.FSImage.format(FSImage.java:144)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:1041)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1479)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1606)
Caused by: java.net.UnknownHostException: hadoop000
	at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:922)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1316)
	at java.net.InetAddress.getLocalHost(InetAddress.java:1492)
	... 8 more
20/04/15 19:11:25 WARN net.DNS: Unable to determine address of the host-falling back to "localhost" address
java.net.UnknownHostException: hadoop000: hadoop000
	at java.net.InetAddress.getLocalHost(InetAddress.java:1496)
	at org.apache.hadoop.net.DNS.resolveLocalHostIPAddress(DNS.java:287)
	at org.apache.hadoop.net.DNS.<clinit>(DNS.java:58)
	at org.apache.hadoop.hdfs.server.namenode.NNStorage.newBlockPoolID(NNStorage.java:966)
	at org.apache.hadoop.hdfs.server.namenode.NNStorage.newNamespaceInfo(NNStorage.java:575)
	at org.apache.hadoop.hdfs.server.namenode.FSImage.format(FSImage.java:144)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:1041)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1479)
	at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1606)
Caused by: java.net.UnknownHostException: hadoop000
	at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
	at java.net.InetAddress$1.lookupAllHostAddr(InetAddress.java:922)
	at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1316)
	at java.net.InetAddress.getLocalHost(InetAddress.java:1492)
	... 8 more
20/04/15 19:11:25 INFO namenode.FSImage: Allocated new BlockPoolId: BP-737304661-127.0.0.1-1586949085020
20/04/15 19:11:25 INFO common.Storage: Storage directory /home/hadoop/tmp/dfs/name has been successfully formatted.
20/04/15 19:11:25 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 0
20/04/15 19:11:25 INFO util.ExitUtil: Exiting with status 0
20/04/15 19:11:25 INFO namenode.NameNode: SHUTDOWN_MSG: 
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at java.net.UnknownHostException: hadoop000: hadoop000

从报错内容中可以看出,错误出现在
java.Net.UnknownHostException hadoop000
编辑hosts内容

vim /etc/hosts

原来的内容如下

128.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

根据错误提示,更改如下:

128.0.0.1   hadoop000 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6

在保存的时候可能会提示没有权限更改

需要修改权限,直接:

sudo chown hadoop000:hadoop000 /etc/hosts

然后再执行命令:

hadoop namenode -format
start-dfs.sh

可以看到问题成功解决:

6101 SecondaryNameNode
5924 DataNode
6216 Jps
5800 NameNode

二、start-dfs.sh报错:“hadoop000: ssh: Could not resolve hostname hadoop000: Temporary failure in n”

错误原因有两个:

1. 链接库设置问题;(刚开始我认为是ssh问题,然后重新下载ssh,问题并没有被解决)

2.HDFS格式化失败。

解决办法

1.针对原因1的解决办法

export HADOOP_COMMON_LIB_NATIVE_DIR = $HADOOP_HOME/lib/native`

export HADOOP_OPTS =-Djava.library.path=$HADOOP_HOME/lib” 

2.针对原因2的解决办法就在上面。

你可能感兴趣的:(HDFS格式化失败,java.Net.UnknownHostException异常处理方法)