集羣啓動的時候,會首先進入安全模式。
作用: 當系統處於安全模式時會檢查數據塊的完整性(數據塊的副本率)
假設我們設置的副本數(即參數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 離開安全模式