按照官网手册安装完单机Hadoop集群(见我的另外一篇文章:搭建单节点Hadoop集群-CSDN博客),电脑重启后,在启动HDFS时NameNode启动失败,出现以下错误信息:
$ sbin/start-dfs.sh
Starting namenodes on [localhost]
pdsh@frin: localhost: ssh exited with exit code 1
Starting datanodes
Starting secondary namenodes [frin]
查看NameNode启动日志可以看到以下错误信息:
2024-08-10 21:02:21,500 ERROR org.apache.hadoop.hdfs.server.namenode.NameNode: Failed to start namenode.
org.apache.hadoop.hdfs.server.common.InconsistentFSStateException: Directory /tmp/hadoop-zhangjc/dfs/name is in an inconsistent state: storage directory does not exist or is not accessible.
at org.apache.hadoop.hdfs.server.namenode.FSImage.recoverStorageDirs(FSImage.java:392)
at org.apache.hadoop.hdfs.server.namenode.FSImage.recoverTransitionRead(FSImage.java:243)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFSImage(FSNamesystem.java:1236)
at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.loadFromDisk(FSNamesystem.java:808)
at org.apache.hadoop.hdfs.server.namenode.NameNode.loadNamesystem(NameNode.java:694)
at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:781)
at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:1033)
at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:1008)
at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1782)
at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1847)
2024-08-10 21:02:21,501 INFO org.apache.hadoop.util.ExitUtil: Exiting with status 1: org.apache.hadoop.hdfs.server.common.InconsistentFSStateException: Directory /tmp/hadoop-zhangjc/dfs/name is in an inconsistent state: storage directory does not exist or is not accessible.
2024-08-10 21:02:21,502 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at frin/127.0.0.1
************************************************************/
这是因为HDFS的元数据信息默认存储在临时目录tmp中,机器重启后这些临时目录会被清理掉。增加以下配置:
etc/hadoop/hdfs-site.xml
<property>
<name>dfs.namenode.name.dir</name>
<value>file:///home/zhangjc/frin/hadoop/dfs/name</value>
</property>
重新格式化HDFS,并重启即可。