一、异常现象
安装好hadoop之后,执行格式化namenode命令时,抛出以下异常:
// :: WARN net.DNS: Unable to determine local hostname -falling back to "localhost"
java.net.UnknownHostException: rayner: rayner
at java.net.InetAddress.getLocalHost(InetAddress.java:)
at org.apache.hadoop.net.DNS.resolveLocalHostname(DNS.java:)
at org.apache.hadoop.net.DNS.<clinit>(DNS.java:)
at org.apache.hadoop.hdfs.server.namenode.NNStorage.newBlockPoolID(NNStorage.java:)
at org.apache.hadoop.hdfs.server.namenode.NNStorage.newNamespaceInfo(NNStorage.java:)
at org.apache.hadoop.hdfs.server.namenode.FSImage.format(FSImage.java:)
at org.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:)
at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:)
at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:)
Caused by: java.net.UnknownHostException: rayner
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$.lookupAllHostAddr(InetAddress.java:)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:)
at java.net.InetAddress.getLocalHost(InetAddress.java:)
... more
// :: WARN net.DNS: Unable to determine address of the host-falling back to "localhost" address
java.net.UnknownHostException: rayner: rayner
at java.net.InetAddress.getLocalHost(InetAddress.java:)
at org.apache.hadoop.net.DNS.resolveLocalHostIPAddress(DNS.java:)
at org.apache.hadoop.net.DNS.<clinit>(DNS.java:)
at org.apache.hadoop.hdfs.server.namenode.NNStorage.newBlockPoolID(NNStorage.java:)
at org.apache.hadoop.hdfs.server.namenode.NNStorage.newNamespaceInfo(NNStorage.java:)
at org.apache.hadoop.hdfs.server.namenode.FSImage.format(FSImage.java:)
at org.apache.hadoop.hdfs.server.namenode.NameNode.format(NameNode.java:)
at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:)
at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:)
Caused by: java.net.UnknownHostException: rayner
at java.net.Inet4AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$.lookupAllHostAddr(InetAddress.java:)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:)
at java.net.InetAddress.getLocalHost(InetAddress.java:)
... more
二、异常原因
是因为更改了虚拟机的hostname
vim /etc/sysconfig/network
而/etc/hosts 下的文件没有修改
三、异常解决
(1)编辑 /etc/hosts 文件
vim /etc/hosts
(2)将 主机IP 和 对应的主机名称 进行映射
添加下图红框中内容
192.168.1.102 rayner
三、参考资料
1.Unable to determine local hostname -falling back to "localhost"