Hadoop格式化HDFS报错java.net.UnknownHostException: localhost.localdomain: localhost.localdomain
异常描述
在对HDFS格式化,执行Hadoop namenode -format命令时,出现未知的主机名的问题,异常信息如下所示:
java.net.UnknownHostException: localhost.localdomain: localhost.localdomain
at java.net.InetAddress.getLocalHost(InetAddress.java:1353)
at org.apache.hadoop.metrics.MetricsUtil.getHostName(MetricsUtil.java:91)
at org.apache.hadoop.metrics.MetricsUtil.createRecord(MetricsUtil.java:80)
at org.apache.hadoop.hdfs.server.namenode.FSDirectory.initialize(FSDirectory.java:73)
at org.apache.hadoop.hdfs.server.namenode.FSDirectory.<init>(FSDirectory.java:68)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.<init>(FSNamesystem.java:370)
at org.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:853)
at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:947)
at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:964)
11/06/22 07:33:36 INFO common.Storage: Image file of size 97 saved in 0 seconds.
11/06/22 07:33:36 INFO common.Storage: Storage directory /tmp/hadoop/hadoop-shirdrn/dfs/name has been successfully formatted.
11/06/22 07:33:36 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at java.net.UnknownHostException: localhost.localdomain: localhost.localdomain
************************************************************/
我们通过执行hostname命令可以看到:
[root@localhost bin]# hostname
master.localdomain
也就是说,Hadoop在格式化HDFS的时候,通过hostname命令获取到的主机名是localhost.localdomain,然后在/etc/hosts文件中进行映射的时候,没有找到,看下我的/etc/hosts内容:
[root@localhost bin]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.34.84 master
172.16.34.85 node01
也就说,通过lmaster根本无法映射到一个IP地址,所以报错了。
此时,我们查看一下/etc/sysconfig/network文件:
NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=master.localdomain
解决方法
修改hosts内容为
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.34.84 master.localdomain
172.16.34.85 node01.localdomian
保证hosts文件内容与network里面的HOSTNAME一致,然后重新启动网络服务:
还没有评论,来说两句吧...