1 概述
解决hadoop启动hdfs时,datanode无法启动的问题。错误为:
[plain] view plaincopy
<embed id="ZeroClipboardMovie_1" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_1" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=1&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">
- java.io.IOException: Incompatible clusterIDs in /home/lxh/hadoop/hdfs/data: namenode clusterID = CID-a3938a0b-57b5-458d-841c-d096e2b7a71c; datanode clusterID = CID-200e6206-98b5-44b2-9e48-262871884eeb
2 问题描述
执行start-dfs.sh后,根据打印日志,可以看到分别执行了NameNode、DataNode的操作。
[plain] view plaincopy
<embed id="ZeroClipboardMovie_2" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_2" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=2&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">
- Starting namenodes on [localhost]
- localhost: starting namenode, logging to /home/lxh/hadoop/hadoop-2.4.1/logs/hadoop-lxh-namenode-ubuntu.out
- localhost: starting datanode, logging to /home/lxh/hadoop/hadoop-2.4.1/logs/hadoop-lxh-datanode-ubuntu.out
但是执行jps查看启动结果时,返现DataNode并没有启动。
[plain] view plaincopy
<embed id="ZeroClipboardMovie_3" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_3" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=3&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">
- 10256 ResourceManager
- 29634 NameNode
- 29939 SecondaryNameNode
- 30054 Jps
- 10399 NodeManager
3 查找问题
很是费解,刚刚还能够正常运行,并且执行了wordcount的测试程序。于是回想了一下刚才的操作,执行了dfs格式化(hdfs namenode -format和hdfs datanode -format),然后重新启动就出现了这个情况。难道与格式化有关?于是查看日志:
[plain] view plaincopy
<embed id="ZeroClipboardMovie_4" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_4" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=4&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">
- 2014-08-08 00:32:08,787 FATAL org.apache.hadoop.hdfs.server.datanode.DataNode: Initialization failed for Block pool <registering> (Datanode Uuid unassigned) service to localhost/127.0.0.1:9000. Exiting.
- java.io.IOException: Incompatible clusterIDs in /home/lxh/hadoop/hdfs/data: namenode clusterID = CID-a3938a0b-57b5-458d-841c-d096e2b7a71c; datanode clusterID = CID-200e6206-98b5-44b2-9e48-262871884eeb
- at org.apache.hadoop.hdfs.server.datanode.DataStorage.doTransition(DataStorage.java:477)
- at org.apache.hadoop.hdfs.server.datanode.DataStorage.recoverTransitionRead(DataStorage.java:226)
- at org.apache.hadoop.hdfs.server.datanode.DataStorage.recoverTransitionRead(DataStorage.java:254)
- at org.apache.hadoop.hdfs.server.datanode.DataNode.initStorage(DataNode.java:974)
- at org.apache.hadoop.hdfs.server.datanode.DataNode.initBlockPool(DataNode.java:945)
- at org.apache.hadoop.hdfs.server.datanode.BPOfferService.verifyAndSetNamespaceInfo(BPOfferService.java:278)
- at org.apache.hadoop.hdfs.server.datanode.BPServiceActor.connectToNNAndHandshake(BPServiceActor.java:220)
- at org.apache.hadoop.hdfs.server.datanode.BPServiceActor.run(BPServiceActor.java:816)
- at java.lang.Thread.run(Thread.java:745)
- 2014-08-08 00:32:08,790 WARN org.apache.hadoop.hdfs.server.datanode.DataNode: Ending block pool service for: Block pool <registering> (Datanode Uuid unassigned) service to localhost/127.0.0.1:9000
- 2014-08-08 00:32:08,791 INFO org.apache.hadoop.hdfs.server.datanode.DataNode: Removed Block pool <registering> (Datanode Uuid unassigned)
根据日志描述,原因是datanode的clusterID 和 namenode的clusterID 不匹配。
原因找到,看看是否如日志描述的这样。
打开hdfs-site.xml中关于datanode和namenode对应的目录,分别打开其中的current/VERSION文件,进行对比。
${datanode}/current/VERSION:
[plain] view plaincopy
<embed id="ZeroClipboardMovie_5" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_5" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=5&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">
- storageID=DS-be8dfa2b-17b1-4c9f-bbfe-4898956a39ed
- clusterID=CID-200e6206-98b5-44b2-9e48-262871884eeb
- cTime=0
- datanodeUuid=406b6d6a-0cb1-453d-b689-9ee62433b15d
- storageType=DATA_NODE
- layoutVersion=-55
${namenode}/current/VERSION:
[plain] view plaincopy
<embed id="ZeroClipboardMovie_6" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_6" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=6&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">
- namespaceID=670379
- clusterID=CID-a3938a0b-57b5-458d-841c-d096e2b7a71c
- cTime=0
- storageType=NAME_NODE
- blockpoolID=BP-325596647-127.0.1.1-1407429078192
- layoutVersion=-56
果然如日志中记录的一样,于是修改datanode的VERSION文件中的clusterID,使与namenode保持一致,然后启动dfs(执行start-dfs.sh),在执行jps查看启动情况,发现全部正常启动。
[plain] view plaincopy
<embed id="ZeroClipboardMovie_7" src="https://csdnimg.cn/public/highlighter/ZeroClipboard.swf" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="16" height="16" name="ZeroClipboardMovie_7" align="middle" allowscriptaccess="always" allowfullscreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="id=7&width=16&height=16" wmode="transparent" style="box-sizing: border-box;">
- 10256 ResourceManager
- 30614 NameNode
- 30759 DataNode
- 30935 SecondaryNameNode
- 31038 Jps
- 10399 NodeManager
4 分析问题原因
执行hdfs namenode -format后,current目录会删除并重新生成,其中VERSION文件中的clusterID也会随之变化,而datanode的VERSION文件中的clusterID保持不变,造成两个clusterID不一致。
所以为了避免这种情况,可以再执行的namenode格式化之后,删除datanode的current文件夹,或者修改datanode的VERSION文件中出clusterID与namenode的VERSION文件中的clusterID一样,然后重新启动dfs。