Fork me on GitHub

HDFS DataNode 服役和退役

  随着公司业务的增长,数据量越来越大,原有的数据节点的容量已经不能满足存储数据的需求,需要在原有集群基础上动态添加新的数据节点。

环境准备
  1)克隆一台虚拟机
  2)修改ip地址和主机名称
  3)修改xcall和xsync文件,增加新增节点的同步ssh
  4)删除原来HDFS文件系统留存的文件:/opt/module/hadoop-2.7.2/data

服役新节点具体步骤

1.在namenode的/opt/module/hadoop-2.7.2/etc/hadoop目录下创建dfs.hosts文件

1
2
3
4
5
6
7
[liucw@hadoop105 hadoop]$ vi dfs.hosts
添加如下主机名称(包含新服役的节点)
hadoop102
hadoop103
hadoop104
hadoop105

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

1
2
3
4
<property>
<name>dfs.hosts</name>
<value>/opt/module/hadoop-2.7.2/etc/hadoop/dfs.hosts</value>
</property>

3.刷新namenode

1
2
[liucw@hadoop102 hadoop-2.7.2]$ hdfs dfsadmin -refreshNodes
Refresh nodes successful

4.更新resourcemanager节点

1
2
[liucw@hadoop102 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

5.在namenode的slaves文件中增加新主机名称

1
2
3
4
5
增加105 不需要分发
hadoop102
hadoop103
hadoop104
hadoop105

6.单独命令启动新的数据节点和节点管理器

1
2
3
4
5
[liucw@hadoop105 hadoop-2.7.2]$ sbin/hadoop-daemon.sh start datanode
starting datanode, logging to /opt/module/hadoop-2.7.2/logs/hadoop-liucw-datanode-hadoop105.out
[liucw@hadoop105 hadoop-2.7.2]$ sbin/yarn-daemon.sh start nodemanager
starting nodemanager, logging to /opt/module/hadoop-2.7.2/logs/yarn-liucw-nodemanager-hadoop105.out

7.在web浏览器上检查是否ok

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

1
2
3
[liucw@hadoop102 sbin]$ ./start-balancer.sh
starting balancer, logging to /opt/module/hadoop-2.7.2/logs/hadoop-liucw-balancer-hadoop102.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved


退役旧数据节点

1.在namenode下创建dfs.hosts.exclude文件

1
2
3
[liucw@hadoop102 hadoop]$ vi dfs.hosts.exclude
添加如下主机名称(要退役的节点)
hadoop105

2.在namenode配置hdfs-site.xml

1
2
3
4
<property>
<name>dfs.hosts.exclude</name>
<value>/opt/module/hadoop-2.7.2/etc/hadoop/dfs.hosts.exclude</value>
</property>

3.刷新namenode、resourcemanager

1
2
3
4
5
[liucw@hadoop102 hadoop-2.7.2]$ hdfs dfsadmin -refreshNodes
Refresh nodes successful
[liucw@hadoop102 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,是不能退役成功的,需要修改副本数后才能退役。

1
2
3
4
5
[liucw@hadoop105 hadoop-2.7.2]$ sbin/hadoop-daemon.sh stop datanode
stopping datanode
[liucw@hadoop105 hadoop-2.7.2]$ sbin/yarn-daemon.sh stop nodemanager
stopping nodemanager

6.从include文件中删除退役节点,再运行刷新节点的命令
  1)从namenode的dfs.hosts文件中删除退役节点hadoop105

1
2
3
hadoop102
hadoop103
hadoop104

  2)刷新namenode,刷新resourcemanager

1
2
3
4
5
[liucw@hadoop102 hadoop-2.7.2]$ hdfs dfsadmin -refreshNodes
Refresh nodes successful
[liucw@hadoop102 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

7.从namenode的slave文件中删除退役节点hadoop105

1
2
3
hadoop102
hadoop103
hadoop104

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

1
2
3
[liucw@hadoop102 hadoop-2.7.2]$ sbin/start-balancer.sh
starting balancer, logging to /opt/module/hadoop-2.7.2/logs/hadoop-liucw-balancer-hadoop102.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved

-----------------本文结束,感谢您的阅读-----------------