经过本教程您能够学习到:node
前面咱们学习了namenode的工做机制,接下来咱们看看工做节点datanode的工做机制,以下图所示:安全
(1)一个数据块在datanode上以文件形式存储在磁盘上,包括两个文件,一个是数据自己,一个是元数据包括数据块的长度,块数据的校验和,以及时间戳。网络
(2)DataNode启动后向namenode注册,经过后,周期性(1小时)的向namenode上报全部的块信息。ide
(3)心跳是每3秒一次,心跳返回结果带有namenode给该datanode的命令如复制块数据到另外一台机器,或删除某个数据块。若是超过10分钟没有收到某个datanode的心跳,则认为该节点不可用。oop
(4)集群运行中能够安全加入和退出一些机器。学习
datanode进程死亡或者网络故障形成datanode没法与namenode通讯,namenode不会当即把该节点断定为死亡,要通过一段时间,这段时间暂称做超时时长。ui
HDFS默认的超时时长为10分钟+30秒。若是定义超时时间为timeout,则超时时长的计算公式为:this
timeout = 2 * dfs.namenode.heartbeat.recheck-interval + 10 * dfs.heartbeat.interval。
默认的dfs.namenode.heartbeat.recheck-interval大小为5分钟,dfs.heartbeat.interval默认为3秒。咱们能够查看其默认配置:spa
<property> <name>dfs.namenode.heartbeat.recheck-interval</name> <value>300000</value> <description> This time decides the interval to check for expired datanodes. With this value and dfs.heartbeat.interval, the interval of deciding the datanode is stale or not is also calculated. The unit of this configuration is millisecond. </description> </property> <property> <name>dfs.heartbeat.interval</name> <value>3</value> <description>Determines datanode heartbeat interval in seconds.</description> </property>
须要注意的是hdfs-site.xml 配置文件中的heartbeat.recheck.interval的单位为毫秒,dfs.heartbeat.interval的单位为秒。code
关于数据校验的相关知识,能够参考一些其余的资料,这是一门很值得学习的学科。
和namenode不一样的是,datanode的存储目录是初始阶段自动建立的,不须要额外格式化。
一、在/opt/module/hadoop-2.7.2/data/tmp/dfs/data/current这个目录下查看版本号
[root@h135 current]# pwd /opt/module/hadoop-2.7.2/data/tmp/dfs/data/current [root@h135 current]# cat VERSION #Sun Jan 06 03:09:44 CST 2019 storageID=DS-dac42eb2-3c51-4489-9d89-b88f3a70a604 clusterID=CID-5b84c9ed-504a-4885-9e26-b9e99eefaf21 cTime=0 datanodeUuid=c36a1e36-33fd-4074-b13a-ba1e632762bd storageType=DATA_NODE layoutVersion=-56
二、在这里深层次进入,还有一个current,这个目录下查看该数据块的版本号
[root@h135 current]# pwd /opt/module/hadoop-2.7.2/data/tmp/dfs/data/current/BP-2054658932-192.168.102.133-1546499444184/current [root@h135 current]# cat VERSION #Sun Jan 06 03:09:44 CST 2019 namespaceID=1140718114 cTime=0 blockpoolID=BP-2054658932-192.168.102.133-1546499444184 layoutVersion=-56