Hadoop格式化HDFS报错java.net.UnknownHostException: centos64
异常描述
在对HDFS格式化,执行hadoop namenode -format命令时,出现未知的主机名的问题,异常信息如下所示:
- [shirdrn@localhost bin]$ hadoop namenode -format
- 11/06/22 07:33:31 INFO namenode.NameNode: STARTUP_MSG:
- /************************************************************
- STARTUP_MSG: Starting NameNode
- STARTUP_MSG: <span style="color: #ff0000;">host = java.net.UnknownHostException: centos64:centos64
- </span>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
- 11/06/22 07:33:36 INFO namenode.FSNamesystem: fsOwner=shirdrn,shirdrn
- 11/06/22 07:33:36 INFO namenode.FSNamesystem: supergroup=supergroup
- 11/06/22 07:33:36 INFO namenode.FSNamesystem: isPermissionEnabled=true
- 11/06/22 07:33:36 INFO metrics.MetricsUtil: Unable to obtain hostName
- java.net.UnknownHostException: <span style="color: #ff0000;">localhost.localdomain: localhost.localdomain
- </span> 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
- ************************************************************/
再执行 /bin/start-all.sh 就不成功。
通过执行hostname命令可以看到:
- [shirdrn@localhost bin]# hostname
- centos64
也就是说,Hadoop在格式化HDFS的时候,通过hostname命令获取到的主机名是centos64,然后在/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.18.130 localhost localhost
在:查看一下/etc/sysconfig/network文件: 保存的是hostname 也就是主机名 。
在 /etc/hosts 中修改
127.0.0.1 localhost centos64
192.168.18.130 localhost centos64
让主机名centos64 在 hosts中能有一个IP与之相映射对应 。
2. 或修改 /etc/sysconfig/network 中的 hostname 为 localhost
再:[root@localhost bin]# /etc/rc.d/init.d/network restart
以上修改完后,再执行格式化HDFS命令,以及启动HDFS集群就正常了。
再启用 bin/start-all.sh
再用 jps .
以上是单机版的 hadoop1.2安装,如果是在集群中安装,
1.把在master中的 /etc/hosts 中把所有slave的 IP 加进来,
如
192.168.18.130 h0
192.168.18.131 h1
192.168.18.132 h2
2. 建立好SSH,实现无密码登陆 ,见另一个blog
3. 修改 vi /home/hadoop1.2/conf/master
h0
vi /home/hadoop1.2/conf/slave
h1
h2
zhuanzi http://lihongchao87.iteye.com/blog/1998347