集群启动的时候,会首先进入安全模式。
作用: 当系统处于安全模式时会检查数据块的完整性(数据块的副本率)
假设我们设置的副本数(即参数dfs.replication)是5,那么在datanode上就应该有5个副本存在,假设只存在3个副本,那么比例就是3/5=0.6。
在配置文件hdfs-default.xml中定义了一个最小的副本的副本率0.999
<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>
我们的副本率0.6明显小于0.99,因此系统会自动的复制副本到其他的dataNode,使得副本率不小于0.999.如果系统中有8个副本,超过我们设定的5个副本,那么系统也会删除多余的3个副本。
不能进行修改文件的操作,但是可以浏览目录结构、查看文件内容的。
在命令行下是可以控制安全模式的进入、退出和查看的。
命令 hdfs dfsadmin -safemode get 查看安全模式状态
命令 hdfs dfsadmin -safemode enter 进入安全模式状态
命令 hdfs dfsadmin -safemode leave 离开安全模式