1.DataNode工作机制
1、一个数据块在DataNode上以文件形式存储在磁盘上,包括两个文件,一个是数据本身,一个是元数据包括数据块的长度,数
块数据的校验和以及时间戳
2、DataNode启动后向Namenode注册,通过后,周期性的向Namenode上报所有的块信息
3、心跳是每3秒,心跳返回的结果带有Namenode给给Datanode的命令(复制块数据到另一台机器,或者删除某一个数据块),
如果超过10分钟没有收到某个DataNode的心跳,则认为该节点不可用
4、集群运行中可以安全加入和退出一些机器
2.数据完整性
DataNode节点保证数据完整性的方法。
1)当DataNode读取Block的时候,它会计算CheckSum。
2)如果计算后的CheckSum,与Block创建时值不一样,说明Block已经损坏。
3)Client读取其他DataNode上的Block。
4)DataNode在其文件创建后周期验证CheckSum
3.掉线时限参数设置
需要注意的是hdfs-site.xml 配置文件中的heartbeat.recheck.interval的单位为毫秒,dfs.heartbeat.interval的单位为秒。
<property>
<name>dfs.namenode.heartbeat.recheck-interval</name>
<value>300000</value>
</property>
<property>
<name>dfs.heartbeat.interval</name>
<value>3</value>
</property>
4.服役新数据节点
(1)在hadoop104主机上再克隆一台hadoop105主机
(2)修改IP地址和主机名称
(3)删除原来HDFS文件系统留存的文件(/opt/module/hadoop-2.7.2/data和log)
(4)source一下配置文件
[atguigu@hadoop105 hadoop-2.7.2]$ source /etc/profile
- 1
- 2
- 3
- 4
- 5
(1)单节点直接启动DataNode,即可关联到集群
[atguigu@hadoop109 hadoop-2.7.2]$ sbin/hadoop-daemon.sh start datanode
[atguigu@hadoop109 hadoop-2.7.2]$ sbin/yarn-daemon.sh start nodemanager
(2)在hadoop109上上传文件
[atguigu@hadoop109 hadoop-2.7.2]$ hadoop fs -put /opt/module/hadoop-2.7.2/LICENSE.txt /
(3)如果数据不均衡,可以用命令实现集群的再平衡
[atguigu@hadoop105 sbin]$ ./start-balancer.sh
starting balancer, logging to /opt/module/hadoop-2.7.2/logs/hadoop-atguigu-balancer-hadoop105.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved
5.退役旧数据节点
添加到白名单的主机节点,都允许访问NameNode,不在白名单的主机节点,都会被退出。
配置白名单的具体步骤如下:
(1)在NameNode的/opt/module/hadoop-2.7.2/etc/hadoop目录下创建dfs.hosts文件
[atguigu@hadoop105 hadoop]$ pwd
/opt/module/hadoop-2.7.2/etc/hadoop
[atguigu@hadoop105 hadoop]$ touch dfs.hosts
[atguigu@hadoop105 hadoop]$ vi dfs.hosts
添加如下主机名称(不添加hadoop109)
hadoop105
hadoop106
hadoop107
hadoop108
(2)在NameNode的hdfs-site.xml配置文件中增加dfs.hosts属性
<property>
<name>dfs.hosts</name>
<value>/opt/module/hadoop-2.7.2/etc/hadoop/dfs.hosts</value>
</property>
(3)配置文件分发
[atguigu@hadoop105 hadoop]$ xsync hdfs-site.xml
(4)刷新NameNode
[atguigu@hadoop105 hadoop-2.7.2]$ hdfs dfsadmin -refreshNodes
Refresh nodes successful
(5)更新ResourceManager节点
[atguigu@hadoop105 hadoop-2.7.2]$ yarn rmadmin -refreshNodes
17/06/24 14:17:11 INFO client.RMProxy: Connecting to ResourceManager at hadoop103/192.168.1.103:8033
(6)在web浏览器上查看
(7)如果数据不均衡,可以用命令实现集群的再平衡
[atguigu@hadoop102 sbin]$ ./start-balancer.sh
starting balancer, logging to /opt/module/hadoop-2.7.2/logs/hadoop-atguigu-balancer-hadoop102.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved
在黑名单上面的主机都会被强制退出。
1.在NameNode的/opt/module/hadoop-2.7.2/etc/hadoop目录下创建dfs.hosts.exclude文件
[atguigu@hadoop105 hadoop]$ pwd
/opt/module/hadoop-2.7.2/etc/hadoop
[atguigu@hadoop105 hadoop]$ touch dfs.hosts.exclude
[atguigu@hadoop105 hadoop]$ vi dfs.hosts.exclude
添加如下主机名称(要退役的节点)
hadoop109
2.在NameNode的hdfs-site.xml配置文件中增加dfs.hosts.exclude属性
<property>
<name>dfs.hosts.exclude</name>
<value>/opt/module/hadoop-2.7.2/etc/hadoop/dfs.hosts.exclude</value>
</property>
3.配置文件分发
[atguigu@hadoop105 hadoop]$ xsync hdfs-site.xml
3.刷新NameNode、刷新ResourceManager
[atguigu@hadoop105 hadoop-2.7.2]$ hdfs dfsadmin -refreshNodes
Refresh nodes successful
[atguigu@hadoop105 hadoop-2.7.2]$ yarn rmadmin -refreshNodes
17/06/24 14:55:56 INFO client.RMProxy: Connecting to ResourceManager at hadoop103/192.168.1.103:8033
4. 检查Web浏览器,退役节点的状态为decommission in progress(退役中),说明数据节点正在复制块到其他节点
5. 等待退役节点状态为decommissioned(所有块已经复制完成),停止该节点及节点资源管理器。
注意:如果副本数是3,服役的节点小于等于3,是不能退役成功的,需要修改副本数后才能退役
[atguigu@hadoop109 hadoop-2.7.2]$ sbin/hadoop-daemon.sh stop datanode
stopping datanode
[atguigu@hadoop109 hadoop-2.7.2]$ sbin/yarn-daemon.sh stop nodemanager
stopping nodemanager
6. 如果数据不均衡,可以用命令实现集群的再平衡
[atguigu@hadoop105 hadoop-2.7.2]$ sbin/start-balancer.sh
starting balancer, logging to /opt/module/hadoop-2.7.2/logs/hadoop-atguigu-balancer-hadoop102.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved
注意:不允许白名单和黑名单中同时出现同一个主机名称。
6.Datanode多目录配置
1. DataNode也可以配置成多个目录,每个目录存储的数据不一样。即:数据不是副本
2.具体配置如下
hdfs-site.xml文件
<property>
<name>dfs.datanode.data.dir</name>
<value>file:///${hadoop.tmp.dir}/dfs/data1,file:///${hadoop.tmp.dir}/dfs/data2</value>
</property>