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

发布于 2024-10-21 08:30:36 字数 169 浏览 1 评论 0原文

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

bin/hadoop namenode -format

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

When configuring my hadoop namenode for the first time, I know I need to run

bin/hadoop namenode -format

but running this a second time, after loading data into HDFS, will wipe out everything and reformat. Is there an easy way to tell if a namenode has already been formatted?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

子栖 2024-10-28 08:30:36

那么你可以检查这个文件
store1/name/current/VERSION

如果存在则已格式化。

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

Well you can check this file
store1/name/current/VERSION

If it exist then it is already formatted.

PS: You do format only once in life in production system. Its better to do in the installation process or manually in emergency restoration time.

漫雪独思 2024-10-28 08:30:36

是的,使用该命令格式化 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 shown提示符中是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 

来格式化Namenode,即使dfs.reformat.disabled为true 。

Yes formatting the Namenode with the command

hadoop namenode -format

will reset the Namenode to a clean slate, erasing all existing metadata and creating a new, empty filesystem structure.

If you run the command interactively and the Namenode is already formatted, you will be prompted to choose if you want to proceed with a message like this:

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

The directory /tmp/hadoop-root/dfs/name shown in the prompt is the Namenode's directory and it indicates that the Namenode has already been formatted.

But by running the command non-interactively with

hdfs namenode -format -nonInteractive

the Namenode will be formatted even if it is already formatted.

One way to make sure that the Namenode does not get inadvertently reformatted is to set dfs.reformat.disabled to 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 is by default false--see https://hadoop.apache.org/.../hdfs-default.xml)

Complementing @thejaswi-r's answer, you can check for the existence of the directory dfs.namenode.name.dir (this is by default file://${hadoop.tmp.dir}/dfs/name where hadoop.tmp.dir is by default /tmp/hadoop-${user.name} and user.name is the user who started/owns the DFS, usually hdfs).

In short, you can use this command to check if the Namenode is already formatted with a bash command

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

(hdfs getconf -confKey hadoop.tmp.dir returns the computed value of hadoop.tmp.dir)

At this point if you know what you're doing you can use the option -force

hdfs namenode -format -nonInteractive -force 

to format the Namenode even if dfs.reformat.disabled is true.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文