Hadoop格式化HDFS报错java.net.UnknownHostException: localhost.localdomain: localhost.localdomain

妖狐艹你老母 2022-07-15 11:18 114阅读 0赞

异常描述

在对HDFS格式化,执行Hadoop namenode -format命令时,出现未知的主机名的问题,异常信息如下所示:

  1. java.net.UnknownHostException: localhost.localdomain: localhost.localdomain
  2. at java.net.InetAddress.getLocalHost(InetAddress.java:1353)
  3. at org.apache.hadoop.metrics.MetricsUtil.getHostName(MetricsUtil.java:91)
  4. at org.apache.hadoop.metrics.MetricsUtil.createRecord(MetricsUtil.java:80)
  5. at org.apache.hadoop.hdfs.server.namenode.FSDirectory.initialize(FSDirectory.java:73)
  6. at org.apache.hadoop.hdfs.server.namenode.FSDirectory.<init>(FSDirectory.java:68)
  7. at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.<init>(FSNamesystem.java:370)
  8. at org.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:853)
  9. at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:947)
  10. at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:964)
  11. 11/06/22 07:33:36 INFO common.Storage: Image file of size 97 saved in 0 seconds.
  12. 11/06/22 07:33:36 INFO common.Storage: Storage directory /tmp/hadoop/hadoop-shirdrn/dfs/name has been successfully formatted.
  13. 11/06/22 07:33:36 INFO namenode.NameNode: SHUTDOWN_MSG:
  14. /************************************************************
  15. SHUTDOWN_MSG: Shutting down NameNode at java.net.UnknownHostException: localhost.localdomain: localhost.localdomain
  16. ************************************************************/

我们通过执行hostname命令可以看到:

  1. [root@localhost bin]# hostname
  2. master.localdomain

也就是说,Hadoop在格式化HDFS的时候,通过hostname命令获取到的主机名是localhost.localdomain,然后在/etc/hosts文件中进行映射的时候,没有找到,看下我的/etc/hosts内容:

  1. [root@localhost bin]# cat /etc/hosts
  2. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  3. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  4. 172.16.34.84 master
  5. 172.16.34.85 node01

也就说,通过lmaster根本无法映射到一个IP地址,所以报错了。
此时,我们查看一下/etc/sysconfig/network文件:

  1. NETWORKING=yes
  2. NETWORKING_IPV6=yes
  3. HOSTNAME=master.localdomain

解决方法

修改hosts内容为

  1. 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
  2. ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
  3. 172.16.34.84 master.localdomain
  4. 172.16.34.85 node01.localdomian

保证hosts文件内容与network里面的HOSTNAME一致,然后重新启动网络服务:

发表评论

表情:
评论列表 (有 0 条评论,114人围观)

还没有评论,来说两句吧...

相关阅读