如何判断hadoop namenode是否已经格式化?

问题描述 投票:0回答:2

第一次配置我的hadoop namenode时,我知道我需要运行

bin/hadoop namenode -format

但是在将数据加载到 HDFS 后第二次运行此操作将清除所有内容并重新格式化。有没有一种简单的方法来判断名称节点是否已经格式化?

hadoop hdfs
2个回答
4
投票

你可以检查这个文件 商店1/名称/当前/版本

如果存在则已格式化。

PS:在生产系统中,您一生中只需要格式化一次。最好在安装过程中执行或在紧急恢复时手动执行。


0
投票

是的,使用命令格式化Namenode

hadoop namenode -format

会将Namenode重置为干净的状态,擦除所有现有元数据并创建一个新的空文件系统结构。

如果您以交互方式运行命令并且 Namenode 已格式化,系统将提示您选择是否要继续,并显示如下消息:

Re-format filesystem in Storage Directory root= /tmp/hadoop-root/dfs/name; location= null ? (Y or N) 

然后提示中显示的目录

/tmp/hadoop-root/dfs/name
就是Namenode的目录,说明Namenode已经格式化了。

但是通过非交互方式运行命令

hdfs namenode -format -nonInteractive

Namenode即使已经格式化也会被格式化。

确保 Namenode 不会无意中重新格式化的一种方法是将

dfs.reformat.disabled
设置为
true

<property>
    <name>dfs.reformat.disabled</name>
    <value>false</value>
    <description>
      Disable reformat of NameNode. If it's value is set to "true"
      and metadata directories already exist then attempt to format NameNode
      will throw NameNodeFormatException.
    </description>
  </property>

dfs.reformat.disabled
默认为
false
--参见https://hadoop.apache.org/.../hdfs-default.xml

补充@thejaswi-r的答案,您可以检查目录

dfs.namenode.name.dir
是否存在(这是默认的file://${hadoop.tmp.dir}/dfs/name
,其中
hadoop.tmp.dir
是默认的
/tmp/hadoop-${user.name}
user.name
是启动/拥有 DFS 的用户,通常是
hdfs
)。
简而言之,你可以使用这个命令来检查Namenode是否已经用bash命令格式化了

[[ -d $(hdfs getconf -confKey hadoop.tmp.dir)/dfs/name ]] && echo "formatted"

(
hdfs getconf -confKey hadoop.tmp.dir

返回

hadoop.tmp.dir
的计算值)
此时,如果您知道自己在做什么,则可以使用该选项 

-force

hdfs namenode -format -nonInteractive -force 

即使 
dfs.reformat.disabled

为 true,也要格式化 Namenode。

    

© www.soinside.com 2019 - 2024. All rights reserved.