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

异常描述:

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

 [shirdrn@localhost bin]$ hadoop namenode -format
// :: INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = java.net.UnknownHostException: localhost.localdomain: localhost.localdomain
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 0.20.0
STARTUP_MSG: build = https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.20 -r 763504; compiled by 'ndaley' on Thu Apr 9 05:18:40 UTC 2009
************************************************************/
Re-format filesystem in /tmp/hadoop/hadoop-shirdrn/dfs/name ? (Y or N) Y
// :: INFO namenode.FSNamesystem: fsOwner=shirdrn,shirdrn
// :: INFO namenode.FSNamesystem: supergroup=supergroup
// :: INFO namenode.FSNamesystem: isPermissionEnabled=true
// :: INFO metrics.MetricsUtil: Unable to obtain hostName
java.net.UnknownHostException: localhost.localdomain: localhost.localdomain
at java.net.InetAddress.getLocalHost(InetAddress.java:)
at org.apache.hadoop.metrics.MetricsUtil.getHostName(MetricsUtil.java:)
at org.apache.hadoop.metrics.MetricsUtil.createRecord(MetricsUtil.java:)
at org.apache.hadoop.hdfs.server.namenode.FSDirectory.initialize(FSDirectory.java:)
at org.apache.hadoop.hdfs.server.namenode.FSDirectory.<init>(FSDirectory.java:)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.<init>(FSNamesystem.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:)
// :: INFO common.Storage: Image file of size saved in seconds.
// :: INFO common.Storage: Storage directory /tmp/hadoop/hadoop-shirdrn/dfs/name has been successfully formatted.
// :: INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at java.net.UnknownHostException: localhost.localdomain: localhost.localdomain
************************************************************/

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

[shirdrn@localhost bin]# hostname
localhost.localdomain

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

[root@localhost bin]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost localhost
192.168.1.103 localhost localhost

也就说,通过localhost.localdomain根本无法映射到一个IP地址,所以报错了。

此时,我们查看一下/etc/sysconfig/network文件:

NETWORKING=yes
NETWORKING_IPV6=yes
HOSTNAME=localhost.localdomain

可见,执行hostname获取到这里配置的HOSTNAME的值。

解决方法

修改/etc/sysconfig/network中HOSTNAME的值为localhost,或者自己指定的主机名,保证localhost在/etc/hosts文件中映射为正确的IP地址,然后重新启动网络服务:

[root@localhost bin]# /etc/rc.d/init.d/network restart
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0:
Determining IP information for eth0... done.
[ OK ]

这时,再执行格式化HDFS命令,以及启动HDFS集群就正常了。

格式化:

[shirdrn@localhost bin]$ hadoop namenode -format
// :: INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: host = localhost/127.0.0.1
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 0.20.0
STARTUP_MSG: build = https://svn.apache.org/repos/asf/hadoop/core/branches/branch-0.20 -r 763504; compiled by 'ndaley' on Thu Apr 9 05:18:40 UTC 2009
************************************************************/
// :: INFO namenode.FSNamesystem: fsOwner=shirdrn,shirdrn
// :: INFO namenode.FSNamesystem: supergroup=supergroup
// :: INFO namenode.FSNamesystem: isPermissionEnabled=true
// :: INFO common.Storage: Image file of size saved in seconds.
// :: INFO common.Storage: Storage directory /tmp/hadoop/hadoop-shirdrn/dfs/name has been successfully formatted.
// :: INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at localhost/127.0.0.1
************************************************************/

启动:

[shirdrn@localhost bin]$ start-all.sh
starting namenode, logging to /home/shirdrn/eclipse/eclipse-3.5./hadoop/hadoop-0.20./logs/hadoop-shirdrn-namenode-localhost.out
localhost: starting datanode, logging to /home/shirdrn/eclipse/eclipse-3.5./hadoop/hadoop-0.20./logs/hadoop-shirdrn-datanode-localhost.out
localhost: starting secondarynamenode, logging to /home/shirdrn/eclipse/eclipse-3.5./hadoop/hadoop-0.20./logs/hadoop-shirdrn-secondarynamenode-localhost.out
starting jobtracker, logging to /home/shirdrn/eclipse/eclipse-3.5./hadoop/hadoop-0.20./logs/hadoop-shirdrn-jobtracker-localhost.out
localhost: starting tasktracker, logging to /home/shirdrn/eclipse/eclipse-3.5./hadoop/hadoop-0.20./logs/hadoop-shirdrn-tasktracker-localhost.out

查看:

[shirdrn@localhost bin]$ jps
TaskTracker
DataNode
NameNode
JobTracker
SecondaryNameNode
Jps
上一篇:pickle和json模块


下一篇:String.Format将人民币符号改成美元符号{0:C}