hadoop新增新数据节点和退役数据节点

新增数据节点

0. 需求
随着公司业务的增长,数据量越来越大,原有的数据节点的容量已经不能满足存储数据的需求,需要在原有集群基础上动态添加新的数据节点。
1. 环境准备
(1)在hadoop03主机上再克隆一台hadoop04主机
(2)修改IP地址和主机名称
(3)删除原来HDFS文件系统留存的文件(/hadoop/module/hadoop-2.7.7/data和log)
(4)source一下配置文件

[linyouyi@hadoop04 hadoop-2.7.7]$  source /etc/profile

2. 服役新节点具体步骤
(1)直接启动DataNode,即可关联到集群

[linyouyi@hadoop04 hadoop-2.7.7]$ sbin/hadoop-daemon.sh start datanode
[linyouyi@hadoop04 hadoop-2.7.7]$ sbin/yarn-daemon.sh start nodemanager

(2)在hadoop04上上传文件

[linyouyi@hadoop04 hadoop-2.7.7]$ hadoop fs -put /hadoop/module/hadoop-2.7.7/LICENSE.txt /

(3)如果数据不均衡,可以用命令实现集群的再平衡

[linyouyi@hadoop04 hadoop-2.7.7]$ ./start-balancer.sh
starting balancer, logging to /hadoop/module/hadoop-2.7.7/logs/hadoop-linyouyi-balancer-hadoop01.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved

  (4)浏览器查看datanodes

退役数据节点

添加白名单
添加到白名单的主机节点,都允许访问NameNode,不在白名单的主机节点,都会被退出。
配置白名单的具体步骤如下:
(1)在NameNode的/hadoop/module/hadoop-2.7.7/etc/hadoop目录下创建dfs.hosts文件

[linyouyi@hadoop01 hadoop]$ pwd
/hadoop/module/hadoop-2.7.7/etc/hadoop
[linyouyi@hadoop01 hadoop]$ touch dfs.hosts
[linyouyi@hadoop01 hadoop]$ vi dfs.hosts
#添加如下主机名称(不添加hadoop04)
hadoop01 
hadoop02 
hadoop03 

(2)在NameNode的hdfs-site.xml配置文件中增加dfs.hosts属性

<property>
<name>dfs.hosts</name>
<value>/hadoop/module/hadoop-2.7.7/etc/hadoop/dfs.hosts</value>
</property>

(3)文件分发到各个节点

[linyouyi@hadoop01 hadoop]$ scp hdfs-site.xml linyouyi@hadoop02:/hadoop/module/hadoop-2.7.7/etc/hadoop/
[linyouyi@hadoop01 hadoop]$ scp hdfs-site.xml linyouyi@hadoop03:/hadoop/module/hadoop-2.7.7/etc/hadoop/
[linyouyi@hadoop01 hadoop]$ scp hdfs-site.xml linyouyi@hadoop04:/hadoop/module/hadoop-2.7.7/etc/hadoop/

(4)刷新NameNode

[linyouyi@hadoop01 hadoop-2.7.7]$ hdfs dfsadmin -refreshNodes
Refresh nodes successful

(5)更新ResourceManager节点

[linyouyi@hadoop01 hadoop-2.7.7]$ yarn rmadmin -refreshNodes
17/06/24 14:17:11 INFO client.RMProxy: Connecting to ResourceManager at hadoop02/192.168.1.103:8033

(6)在web浏览器上查看datanodes

(7) 如果数据不均衡,可以用命令实现集群的再平衡

[linyouyi@hadoop01 sbin]$ ./start-balancer.sh
starting balancer, logging to /hadoop/module/hadoop-2.7.7/logs/hadoop-linyouyi-balancer-hadoop01.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved

黑名单退役
在黑名单上面的主机都会被强制退出。
1.在NameNode的/hadoop/module/hadoop-2.7.7/etc/hadoop目录下创建dfs.hosts.exclude文件

[linyouyi@hadoop01 hadoop]$ pwd
/hadoop/module/hadoop-2.7.7/etc/hadoop
[linyouyi@hadoop01 hadoop]$ touch dfs.hosts.exclude
[linyouyi@hadoop01 hadoop]$ vi dfs.hosts.exclude

添加如下主机名称(要退役的节点)
hadoop04
2.在NameNode的hdfs-site.xml配置文件中增加dfs.hosts.exclude属性

<property>
<name>dfs.hosts.exclude</name>
<value>/hadoop/module/hadoop-2.7.7/etc/hadoop/dfs.hosts.exclude</value>
</property>

3.刷新NameNode、刷新ResourceManager

[linyouyi@hadoop01 hadoop-2.7.7]$ hdfs dfsadmin -refreshNodes
Refresh nodes successful

[linyouyi@hadoop01 hadoop-2.7.7]$ yarn rmadmin -refreshNodes
17/06/24 14:55:56 INFO client.RMProxy: Connecting to ResourceManager at hadoop02/172.16.2.103:8033

4. 检查Web浏览器,退役节点的状态为decommission in progress(退役中),说明数据节点正在复制块到其他节点
5. 等待退役节点状态为decommissioned(所有块已经复制完成),停止该节点及节点资源管理器。注意:如果副本数是3,服役的节点小于等于3,是不能退役成功的,需要修改副本数后才能退役

[linyouyi@hadoop04 hadoop-2.7.7]$ sbin/hadoop-daemon.sh stop datanode
stopping datanode
[linyouyi@hadoop04 hadoop-2.7.7]$ sbin/yarn-daemon.sh stop nodemanager

6. 如果数据不均衡,可以用命令实现集群的再平衡

[linyouyi@hadoop01 hadoop-2.7.7]$ sbin/start-balancer.sh 
starting balancer, logging to /hadoop/module/hadoop-2.7.7/logs/hadoop-linyouyi-balancer-hadoop01.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved

注意:不允许白名单和黑名单中同时出现同一个主机名称

posted @ 2019-08-05 11:18  linyouyi  阅读(413)  评论(0编辑  收藏  举报