Two methods for NameNode fault handling

After the NameNode fails, there are two ways to restore data.

Method 1: Copy the data in SecondaryNameNode to the directory where NameNode stores data

  1. kill -9 NameNode process
  2. Delete the data stored by NameNode (/opt/module/hadoop-3.1.3/data/tmp/dfs/name)
 rm -rf /opt/module/hadoop-3.1.3/data/dfs/name/*
  1. Copy the data in the SecondaryNameNode to the original NameNode storage data directory
scp -r pbh@hadoop104:/opt/module/hadoop-3.1.3/data/dfs/namesecondary/* ./nam
e/
  1. Restart NameNode
[pbh@hadoop102 hadoop-3.1.3]$ hdfs --daemon start namenode

Method 2: Use the -importCheckpoint option to start the NameNode daemon process to copy the data in the SecondaryNameNode to the NameNode directory

  1. Modify hdfs-site.xml in
<property>
 <name>dfs.namenode.checkpoint.period</name>
 <value>120</value>
</property>
<property>
 <name>dfs.namenode.name.dir</name>
 <value>/opt/module/hadoop-3.1.3/data/dfs/name</value>
</property>
  1. kill -9 NameNode process
  2. Delete the data stored by NameNode (/opt/module/hadoop-3.1.3/data/dfs/name)
rm -rf /opt/module/hadoop-3.1.3/data/dfs/name/*
  1. If the SecondaryNameNode is not on the same host node as the NameNode, you need to copy the directory where the SecondaryNameNode stores data to the same directory where the NameNode stores data, and delete the in_use.lock file
[pbh@hadoop102 dfs]$ scp -r pbh@hadoop104:/opt/module/hadoop-3.1.3/data/dfs/namesecondary ./
[pbh@hadoop102 namesecondary]$ rm -rf in_use.lock
[pbh@hadoop102 dfs]$ pwd 
/opt/module/hadoop-3.1.3/data/dfs
[pbh@hadoop102 dfs]$ ls
data name namesecondary
  1. Import checkpoint data (wait for a while ctrl+c to end)
[pbh@hadoop102 hadoop-3.1.3]$ bin/hdfs namenode -importCheckpoint
  1. Start the NameNode
[pbh@hadoop102 hadoop-3.1.3]$ hdfs --daemon start namenode

Guess you like

Origin blog.csdn.net/meng_xin_true/article/details/126039318