HDFS重启集群导致数据损坏,使用fsck命令修复过程
作者:尹正杰
版权声明:原创作品,谢绝转载!否则将追究法律责任。
我们先看一组输出
[root@flume112 ~]# hdfs fsck /user/kuaikan/report_new////
Connecting to namenode via http://calculation111.aggrx:50070
FSCK started by root (auth:SIMPLE) from /10.1.2.112 for path /user/kuaikan/report_new//// at Sat May :: CST
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................Status: HEALTHY
Total size: B (Total open files size: B)
Total dirs:
Total files:
Total symlinks: (Files currently being written: )
Total blocks (validated): (avg. block size B) (Total open file blocks (not validated): ) #注意,这个26没有进行验证,说明有26个存在问题!
Minimally replicated blocks: (100.0 %)
Over-replicated blocks: (0.0 %)
Under-replicated blocks: (0.0 %)
Mis-replicated blocks: (0.0 %)
Default replication factor:
Average block replication: 3.0
Corrupt blocks:
Missing replicas: (0.0 %)
Number of data-nodes:
Number of racks:
FSCK ended at Sat May :: CST in milliseconds The filesystem under path '/user/kuaikan/report_new/2019/05/23/' is HEALTHY
[root@flume112 ~]#
官方关于fsck命令有对应的解释,我们查看更详细的信息,官方链接:https://hadoop.apache.org/docs/r2.9.1/hadoop-project-dist/hadoop-hdfs/HDFSCommands.html#fsck。
[root@flume112 ~]# hdfs fsck /user/kuaikan/report_new//// -openforwrite
Connecting to namenode via http://calculation111.aggrx:50070
FSCK started by root (auth:SIMPLE) from /10.1.2.112 for path /user/kuaikan/report_new//// at Sat May :: CST
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
................................................/user/kuaikan/report_new////report.log.----45.10---160.1558554302405.txt bytes, block(s), OPENFORWRITE: ../user/kuaikan/report_new////report.log.----45.10---248.1558554301696.txt bytes, block(s), OPENFORWRITE: ....../user/kuaikan/report_new////report.log.----45.10---71.1558554301576.txt bytes, block(s), OPENFORWRITE: .........................................
/user/kuaikan/report_new////report.log.----55.10---208.1558554901562.txt bytes, block(s), OPENFORWRITE: .../user/kuaikan/report_new////report.log.----55.10---248.1558554901949.txt bytes, block(s), OPENFORWRITE: ...../user/kuaikan/report_new////report.log.----55.10---233.1558554901647.txt bytes, block(s), OPENFORWRITE: .........................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
................................................................/user/kuaikan/report_new////report.log.----30.10---208.1558575001741.txt bytes, block(s), OPENFORWRITE: ...................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
......................./user/kuaikan/report_new////report.log.----55.10---93.1558587301545.txt bytes, block(s), OPENFORWRITE: ........../user/kuaikan/report_new////report.log.----55.10---88.1558587301803.txt bytes, block(s), OPENFORWRITE: .........................../user/kuaikan/report_new////report.log.----01.10---88.1558587709627.txt bytes, block(s), OPENFORWRITE: .....................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
.........................................................................../user/kuaikan/report_new////report.log.----45.10---35.1558601101874.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---40.1558601102383.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---46.1558601101876.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---58.1558601102255.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---93.1558601102225.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---38.1558601101874.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---208.1558601101557.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---160.1558601101782.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---33.1558601102283.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---150.1558601101668.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---248.1558601101427.txt bytes, block(s), OPENFORWRITE: ./user/kuaikan/report_new////report.log.----45.10---226.1558601101904.txt bytes, block(s), OPENFORWRITE: ./user/kuaikan/report_new////report.log.----45.10---96.1558601101582.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---88.1558601101302.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---233.1558601101531.txt bytes, block(s), OPENFORWRITE: /user/kuaikan/report_new////report.log.----45.10---71.1558601101720.txt bytes, block(s), OPENFORWRITE: .......
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
....................................................................................................
..............................................................Status: HEALTHY
Total size: B
Total dirs:
Total files:
Total symlinks:
Total blocks (validated): (avg. block size B)
Minimally replicated blocks: (99.50153 %)
Over-replicated blocks: (0.0 %)
Under-replicated blocks: (0.0 %)
Mis-replicated blocks: (0.0 %)
Default replication factor:
Average block replication: 2.985046
Corrupt blocks:
Missing replicas: (0.0 %)
Number of data-nodes:
Number of racks:
FSCK ended at Sat May :: CST in milliseconds The filesystem under path '/user/kuaikan/report_new/2019/05/23/' is HEALTHY
[root@flume112 ~]#
[root@flume112 ~]# hdfs fsck /user/kuaikan/report_new/2019/05/23/ -openforwrite
找到损坏的文件后,我们手动进行回复,注意,我们输入的必须是一个文件,并不是一个目录哟!
[root@calculation111 ~]# hdfs debug recoverLease -path /user/kuaikan/report_new////report.log.----45.10---71.1558554301576.txt -retries
recoverLease returned false.
Retrying in ms...
Retry #
recoverLease SUCCEEDED on /user/kuaikan/report_new////report.log.----45.10---71.1558554301576.txt
[root@calculation111 ~]#