1、在namenode节点的/opt/module/hadoop-2.8.2/etc/hadoop目录下创建dfs.hosts.exclude文件
[victor@node1 hadoop]$ cd /opt/module/hadoop-2.8.2/etc/hadoop
[victor@node1 hadoop]$ pwd
/opt/module/hadoop-2.8.2/etc/hadoop
[victor@node1 hadoop]$ touch dfs.hosts.exclude
[victor@node1 hadoop]$ vi dfs.hosts.exclude
//添加如下主机名称(要退役的节点)
node4
//尖叫提示:一般在执行命令的主节点上添加即可,建议分发
2、在namenode的hdfs-site.xml配置文件中增加dfs.hosts.exclude属性
<property>
<name>dfs.hosts.exclude</name>
<value>/opt/module/hadoop-2.8.2/etc/hadoop/dfs.hosts.exclude</value>
</property>
//尖叫提示:是否分发和dfs.hosts.exclude 文件同步即可
3、刷新namenode、刷新resourcemanager
[victor@node1 hadoop-2.8.2]$ bin/hdfs dfsadmin -refreshNodes
Refresh nodes successful
[victor@node1 hadoop-2.8.2]$ bin/yarn rmadmin -refreshNodes
4、检查web浏览器,退役节点的状态为decommission in progress(退役中),说明数据节点正在复制块到其他节点。
http://node1:50070
5、等待退役节点状态为decommissioned(所有块已经复制完成),停止该节点及节点资源管理器。注意:如果副本数是3,服役的节点小于等于3,是不能退役成功的,需要修改副本数后才能退役。
退役节点上关闭进程
[victor@node4 hadoop-2.8.2]$ sbin/hadoop-daemon.sh stop datanode
stopping datanode
[victor@node4 hadoop-2.8.2]$ sbin/yarn-daemon.sh stop nodemanager
stopping nodemanager
6、从include文件中删除退役节点,再运行刷新节点的命令
(1)从namenode的dfs.hosts文件中删除退役节点node4 (没有此文件,这一小步骤不操作)
node1
node2
node3
尖叫提示:分发
(2)刷新namenode,刷新resourcemanager
[victor@node1 hadoop-2.8.2]$ bin/hdfs dfsadmin -refreshNodes
Refresh nodes successful
[victor@node1 hadoop-2.8.2]$ bin/yarn rmadmin -refreshNodes
INFO client.RMProxy: Connecting to ResourceManager at node2/192.168.1.103:8033
//尖叫提示:分发
(3) 查看状态
[victor@node1 hadoop-2.8.2]$ hdfs dfsadmin -report
7、从namenode的slave文件中删除退役节点node4,修改后分发
node1
node2
node3
//尖叫提示:分发
8、如果数据不均衡,可以用命令实现集群的再平衡
[victor@node1 hadoop-2.8.2]$ sbin/start-balancer.sh
starting balancer, logging to /opt/module/hadoop-2.8.2/logs/hadoop-victor-balancer-node1.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved