Neal's Space
  • Introduction
  • Algorithm
    • 数学基础
    • Normal
      • 一致性哈希分布
      • A star 寻路
      • 蓄水池抽样 Reservoir Sampling
    • Machine Learning
      • k-近邻算法
      • k-平均演算法
      • kd-Tree算法
      • TF-IDF 特征加权
      • 机器学习模型评价
      • 数据的归一化和标准化
      • 线性回归 - "模型之母"
      • 逻辑回归 - "出场率最高算法"
      • 决策树
  • Programming Language
    • Java
      • Lombok
      • 多数据源分页查询拼接订单
      • 集群 分布式 微服务
      • 反射
      • JAVA类加载器
      • JVM内存
      • Garbage Collection(JVM的垃圾回收机制)
      • Synchronized
      • Java跨域访问
    • Scala
      • Scala使用
  • MySQL
    • MySQL事务
    • MySQL插入多条数据时遇到的问题
    • MySQL经典50题
  • Linux
    • Linux
      • Vim
      • Ubuntu换源
      • Linux内存
    • Docker
      • Docker
      • Docker容器
      • Docker镜像
      • Docker创建本地镜像
  • Data
    • DataWarehouse
      • Sqoop
      • 多维计算
    • Hadoop
      • Hadoop
        • Docker运行Hadoop
      • Hdfs
        • HDFS块丢失过多导致进入安全模式
        • NameNode内存解析
        • HDFS的Router-Based Federation
    • Hive
      • Hive安装配置
      • Hive使用DDL
      • Hive引擎Tez
      • Sqoop与Hive出现的问题
      • Hive与Hook
    • Flume
    • Hbase
      • Hbase安装配置
      • Hbase的Bloom Filters
    • Spark
      • Spark基础
      • Spark SQL
      • Spark Streaming
      • Spark On Yarn
      • Tuning Spark 数据序列化和内存调整
      • Tuning Spark Job
    • Kafka
      • Kafka文件存储
      • 偏移量提交 与 分区再平衡
    • Flink
      • Flink遇到的坑
Powered by GitBook
On this page
  • 安全模式
  • HDFS的进入与退出
  • 解决问题

Was this helpful?

  1. Data
  2. Hadoop
  3. Hdfs

HDFS块丢失过多导致进入安全模式

我的测试机器有次意外关机没关hadoop,出现了以下日志:

  ......
Name node is in safe mode.

The reported blocks 632758 needs additional 5114 blocks to reach the threshold 0.9990 of total blocks 638510.

The number of live datanodes 3 has reached the minimum number 0.

Safe mode will be turned off automatically once the thresholds have been reached.
  ......

上面日志大意是,namenode正在安全模式中,接收到的datanode块数量(632758)不足总块数量(638510)的99.90%,活动数据块3的数量已经达到最小的数量0,安全模式将会打开,并在恢复到设置的阀值时自动关闭。

阀值的定义,在 hdfs 的配置文件 hdfs-site.xml 中有以下两个属性:

<property>
  <name>dfs.namenode.safemode.threshold-pct</name>
  <value>0.999f</value>
  <description>
    Specifies the percentage of blocks that should satisfy 
    the minimal replication requirement defined by dfs.namenode.replication.min.
    Values less than or equal to 0 mean not to wait for any particular
    percentage of blocks before exiting safemode.
    Values greater than 1 will make safe mode permanent.
  </description>
</property>

<property>
  <name>dfs.namenode.safemode.min.datanodes</name>
  <value>0</value>
  <description>
    Specifies the number of datanodes that must be considered alive
    before the name node exits safemode.
    Values less than or equal to 0 mean not to take the number of live
    datanodes into account when deciding whether to remain in safe mode
    during startup.
    Values greater than the number of datanodes in the cluster
    will make safe mode permanent.
  </description>
</property>

一般是因磁盘空间不足,内存不足,系统掉电等其他原因导致dataNode datablock丢失

安全模式

  • 查看文件系统的文件

  • 不可以改变文件系统的命名空间

    • 不可以创建文件夹

    • 不可以上传文件

    • 不可以删除文件

正常的HDFS系统Safemode是关闭的

HDFS刚开启namenode时会进入安全模式,HDFS的namenode等待dataNode向其发送块报告,当namenode统计总模块和发送过来的块报告中的统计信息达到99.999%的时候,表示不存在块的丢失,此时安全模式才会退出。

可以在Hadoop的WebUI界面中看到

HDFS的进入与退出

Usage: hdfs dfsadmin
Note: Administrative commands can only be run as the HDFS superuser.
    [-report [-live] [-dead] [-decommissioning] [-enteringmaintenance] [-inmaintenance]]
    [-safemode <enter | leave | get | wait>]
......

使用-safemode enter/leave进入或离开安全模式

使用-safemode get查看安全模式

解决问题

执行命令退出安全模式:

hadoop dfsadmin -safemode leave

1.执行健康检查,删除损坏掉的block。

hdfs fsck / -files
hdfs fsck / -delete

注意: 这种方式会出现数据丢失,损坏的block会被删掉

2.排查问题

检测缺失块

hdfs fsck -list-corruptfileblocks
hdfs fsck / | egrep -v '^\.+$' | grep -v eplica

查看上面某一个文件的情况

hdfs fsck /path/to/corrupt/file -locations -blocks -files

接下来。。想办法修复这个文件。

根据集群的文件信息进行修复

PreviousHdfsNextNameNode内存解析

Last updated 5 years ago

Was this helpful?