一、服役新数据节点
1、需求
随着公司业务的增长,数据量越来越大,原有的数据节点的容量已经不能满足存储数据的需求,需要在原有集群基础上动态添加新的数据节点。
2、环境准备
(1) 在 hadoop153 主机上再克隆一台 hadoop154 主机
(2) 修改 hadoop153 的ip地址和主机名称
(3) 修改 root 与 test 用户的 xsync 分发脚本,可以分发到 hadoop154 上
(4) 在 hadoop151 上修改主机名与ip映射,并用 root 用户分发
(5) 配置 NameNode 与 ResourceManager 这两台机器可以 ssh 登录 hadoop154
(6) 删除原来HDFS文件系统留存的文件(/opt/module/hadoop-2.7.2/data 和 log)
3、添加白名单
(1) 在 NameNode 的 /opt/module/hadoop-2.7.2/etc/hadoop 目录下创建 dfs.hosts 文件
添加到白名单的主机节点,都允许访问NameNode,不在白名单的主机节点,都会被退出
[test@hadoop151 hadoop]$ touch dfs.hosts
[test@hadoop151 hadoop]$ vim dfs.hosts
[test@hadoop151 hadoop]$ cat dfs.hosts
hadoop151
hadoop152
hadoop153
hadoop154
(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) 配置文件分发
[test@hadoop151 hadoop]$ xsync hdfs-site.xml
fname=hdfs-site.xml
pdir=/opt/module/hadoop-2.7.2/etc/hadoop
------------------- hadoop151 --------------
sending incremental file list
sent 36 bytes received 12 bytes 96.00 bytes/sec
total size is 1468 speedup is 30.58
------------------- hadoop152 --------------
sending incremental file list
hdfs-site.xml
sent 87 bytes received 49 bytes 272.00 bytes/sec
total size is 1468 speedup is 10.79
------------------- hadoop153 --------------
sending incremental file list
hdfs-site.xml
sent 87 bytes received 49 bytes 90.67 bytes/sec
total size is 1468 speedup is 10.79
------------------- hadoop154 --------------
sending incremental file list
hdfs-site.xml
sent 851 bytes received 43 bytes 1788.00 bytes/sec
total size is 1468 speedup is 1.64
(4) 刷新 NameNode
在 NameNode 节点上 hadoop151 执行如下命令:
[test@hadoop151 hadoop]$ hdfs dfsadmin -refreshNodes
Refresh nodes successful
(5) 刷新 ResourceManager
在 ResourceManager 节点 hadoop152 执行如下命令:
[test@hadoop152 ~]$ yarn rmadmin -refreshNodes
20/02/04 13:48:19 INFO client.RMProxy: Connecting to ResourceManager at hadoop152/192.168.1.152:8033
(6) 在 hadoop154 上单点启动 datanode 与 nodemanager
[test@hadoop154 hadoop-2.7.2]$ hadoop-daemon.sh start datanode
starting datanode, logging to /opt/module/hadoop-2.7.2/logs/hadoop-test-datanode-hadoop154.out
[test@hadoop154 hadoop-2.7.2]$ yarn-daemon.sh start nodemanager
starting nodemanager, logging to /opt/module/hadoop-2.7.2/logs/yarn-test-nodemanager-hadoop154.out
(7) web端查看
(8) 如果数据不均衡,可以用命令实现集群的再平衡
[test@hadoop151 hadoop]$ start-balancer.sh
starting balancer, logging to /opt/module/hadoop-2.7.2/logs/hadoop-test-balancer-hadoop151.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved
二、退役数据节点
采用黑名单退役的方式,在黑名单上面的所有主机都会被强制退出。
1、在 NameNode 上创建 dfs.hosts.exclude 文件
添加要退役的主机节点名称
[test@hadoop151 hadoop]$ pwd
/opt/module/hadoop-2.7.2/etc/hadoop
[test@hadoop151 hadoop]$ touch dfs.hosts,exclude
[test@hadoop151 hadoop]$ cat dfs.hosts.exclude
hadoop154
2、修改 hdfs-site.xml 并分发
<property>
<name>dfs.hosts.exclude</name>
<value>/opt/module/hadoop-2.7.2/etc/hadoop/dfs.hosts.exclude</value>
</property>
[test@hadoop151 hadoop]$ xsync hdfs-site.xml
fname=hdfs-site.xml
pdir=/opt/module/hadoop-2.7.2/etc/hadoop
------------------- hadoop151 --------------
sending incremental file list
sent 36 bytes received 12 bytes 32.00 bytes/sec
total size is 1626 speedup is 33.88
------------------- hadoop152 --------------
sending incremental file list
hdfs-site.xml
sent 313 bytes received 49 bytes 724.00 bytes/sec
total size is 1626 speedup is 4.49
------------------- hadoop153 --------------
sending incremental file list
hdfs-site.xml
sent 313 bytes received 49 bytes 724.00 bytes/sec
total size is 1626 speedup is 4.49
------------------- hadoop154 --------------
sending incremental file list
hdfs-site.xml
sent 313 bytes received 49 bytes 724.00 bytes/sec
total size is 1626 speedup is 4.49
3、刷新 NameNode、刷新 ResourceManager
[test@hadoop151 hadoop]$ hdfs dfsadmin -refreshNodes
Refresh nodes successful
[test@hadoop152 ~]$ yarn rmadmin -refreshNodes
20/02/04 14:52:23 INFO client.RMProxy: Connecting to ResourceManager at hadoop152/192.168.1.152:8033
4、检查Web浏览器,退役节点的状态为decommission in progress(退役中),说明数据节点正在复制块到其他节点
5、等待退役节点状态为 decommissioned(所有块已经复制完成),停止该节点及节点资源管理器。这里要注意:如果副本数是3,服役的节点小于等于3,是不能退役成功的,需要修改副本数后才能退役
6、如果数据不均衡,可以用命令实现集群的再平衡
[test@hadoop151 hadoop]$ start-balancer.sh
starting balancer, logging to /opt/module/hadoop-2.7.2/logs/hadoop-test-balancer-hadoop151.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved
注:不允许白名单和黑名单中同时出现同一个主机名称。