如何判断 hadoop namenode 是否已经格式化?
当第一次配置我的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那么你可以检查这个文件
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.
是的,使用该命令格式化 Namenode
会将 Namenode 重置为干净的状态,擦除所有现有元数据并创建一个新的空文件系统结构。
如果您以交互方式运行该命令并且 Namenode 已格式化,系统将提示您选择是否要继续,并显示如下消息:
目录
/tmp/hadoop-root/dfs/name
shown提示符中是Namenode的目录,说明Namenode已经格式化了。但是通过以非交互方式运行命令,
Namenode 将会被格式化,即使它已经被格式化。
确保Namenode不会无意中重新格式化的一种方法是将
dfs.reformat.disabled
设置为true
(
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命令进行格式化
(
hdfs getconf -confKey hadoop.tmp.dir
返回hadoop.tmp.dir的计算值
)此时,如果您知道自己在做什么,则可以使用选项
-force
来格式化Namenode,即使
dfs.reformat.disabled
为true 。Yes formatting the Namenode with the command
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:
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
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
totrue
(
dfs.reformat.disabled
is by defaultfalse
--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 defaultfile://${hadoop.tmp.dir}/dfs/name
wherehadoop.tmp.dir
is by default/tmp/hadoop-${user.name}
anduser.name
is the user who started/owns the DFS, usuallyhdfs
).In short, you can use this command to check if the Namenode is already formatted with a bash command
(
hdfs getconf -confKey hadoop.tmp.dir
returns the computed value ofhadoop.tmp.dir
)At this point if you know what you're doing you can use the option
-force
to format the Namenode even if
dfs.reformat.disabled
is true.