报错背景
hadoop集群安装完成后进行格式化操作,不成功。
报错现象
# hadoop namenode -format
2020-10-16 15:13:15,741 WARN org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Encountered exception loading fsimage java.io.IOException: NameNode is not formatted. at org.apache.hadoop.hdfs.server.namenode.FSImage.recoverTransitionRead(FSImage.java:235) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFSImage(FSNamesystem.java:978) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFromDisk(FSNamesystem.java:685) at org.apache.hadoop.hdfs.server.namenode.NameNode.loadNamesystem(NameNode.java:585) at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:645) at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:819) at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:803) at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1500) at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1566) 2020-10-16 15:13:15,746 INFO org.mortbay.log: Stopped HttpServer2$SelectChannelConnectorWithSafeStartup@bigdata2:50070 2020-10-16 15:13:15,846 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: Stopping NameNode metrics system... 2020-10-16 15:13:15,847 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: NameNode metrics system stopped. 2020-10-16 15:13:15,847 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: NameNode metrics system shutdown complete. 2020-10-16 15:13:15,847 ERROR org.apache.hadoop.hdfs.server.namenode.NameNode: Failed to start namenode. java.io.IOException: NameNode is not formatted. at org.apache.hadoop.hdfs.server.namenode.FSImage.recoverTransitionRead(FSImage.java:235) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFSImage(FSNamesystem.java:978) at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFromDisk(FSNamesystem.java:685) at org.apache.hadoop.hdfs.server.namenode.NameNode.loadNamesystem(NameNode.java:585) at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:645) at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:819) at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:803) at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1500) at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1566) 2020-10-16 15:13:15,850 INFO org.apache.hadoop.util.ExitUtil: Exiting with status 1 2020-10-16 15:13:15,851 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: SHUTDOWN_MSG:
报错原因
(1)确实有可能安装的时候格式化不成功;
(2)也有可能是操作顺序有问题,hadoop集群安装的时候没有将active-namenode中对应目录下格式化时产生的数据复制到 standby-namenode对应目录下,导致系统认为没有格式化成功。
报错解决
(1)重新格式化(解决问题的可能性不大)
(2)检查hadoop中active-namenode格式化后生成的文件目录,/data/hadoop/tmp(我的是这个目录)
发现生成了一下文件,将这些文件拷贝到standby-namenode的相同目录下,然后重启hadoop即可。
查看目录所在位置core-site.xml文件里的hadoop.tmp.dir
<!-- hadoop框架基本配置 集群时需要分发此目录下name到其他节点 --> <property> <name>hadoop.tmp.dir</name> <value>/data/hadoop/tmp</value> </property>