NameNode故障后,可以采用如下两种方法恢复数据。
方法一:将SecondaryNameNode中数据拷贝到NameNode存储数据的目录;
- kill -9 NameNode进程
- 删除NameNode存储的数据(/opt/module/hadoop-2.7.2/data/tmp/dfs/name)
[atguigu@hadoop003 hadoop-2.7.2]$ rm -rf /opt/module/hadoop-2.7.2/data/tmp/dfs/name/* - 拷贝SecondaryNameNode中数据到原NameNode存储数据目录
[atguigu@hadoop003 dfs]$ scp -r atguigu@hadoop005:/opt/module/hadoop-2.7.2/data/tmp/dfs/namesecondary/* ./name/ - 重新启动NameNode
[atguigu@hadoop003 hadoop-2.7.2]$ sbin/hadoop-daemon.sh start namenode
方法二:使用-importCheckpoint选项启动NameNode守护进程,从而将SecondaryNameNode中数据拷贝到NameNode目录中。
- 修改hdfs-site.xml中的
<property>
<name>dfs.namenode.checkpoint.period</name>
<value>120</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>/opt/module/hadoop-2.7.2/data/tmp/dfs/name</value>
</property>
- kill -9 NameNode进程
- 删除NameNode存储的数据(/opt/module/hadoop-2.7.2/data/tmp/dfs/name)
[atguigu@hadoop003 hadoop-2.7.2]$ rm -rf /opt/module/hadoop-2.7.2/data/tmp/dfs/name/* - 如果SecondaryNameNode不和NameNode在一个主机节点上,需要将SecondaryNameNode存储数据的目录拷贝到NameNode存储数据的平级目录,并删除in_use.lock文件
[atguigu@hadoop003 dfs]$ scp -r atguigu@hadoop005:/opt/module/hadoop-2.7.2/data/tmp/dfs/namesecondary ./
[atguigu@hadoop003 namesecondary]$ rm -rf in_use.lock
[atguigu@hadoop003 dfs]$ pwd
/opt/module/hadoop-2.7.2/data/tmp/dfs
[atguigu@hadoop003 dfs]$ ls
data name namesecondary
5. 导入检查点数据(等待一会ctrl+c结束掉)
[atguigu@hadoop003 hadoop-2.7.2]$ bin/hdfs namenode -importCheckpoint
6. 启动NameNode
[atguigu@hadoop003 hadoop-2.7.2]$ sbin/hadoop-daemon.sh start namenode