在不停止集群的情况下添加和删除节点
[slaves.xml]
//仅仅是控制集群操作,hadoop启动的时候会根据这个文件里面的地址,启动所有数据节点
管理节点的服役与退役,需要配置hdfs-site.xml和yarn-site.xml
这两个属性是由hadoop-daemon调用的
属性中的文件路径必须是名称节点上的(在namenode节点上创建include和exclude文件)
配置[hdfs-site.xml]
<property>
<!-- 决定哪些数据节点(DN)可以连接到名称节点 -->
<name>dfs.hosts</name>
<value></value>
<description>Names a file that contains a list of hosts that are
permitted to connect to the namenode. The full pathname of the file
must be specified. If the value is empty, all hosts are
permitted.</description>
</property>
<property>
<!-- 决定哪些数据节点(DN)不可以连接到名称节点 -->
<name>dfs.hosts.exclude</name>
<value></value>
<description>Names a file that contains a list of hosts that are
not permitted to connect to the namenode. The full pathname of the
file must be specified. If the value is empty, no hosts are
excluded.</description>
</property>
配置[yarn-site.xml]
<property>
<!-- 决定哪些节点管理器(NM)可以连接到名称节点 -->
<description>Path to file with nodes to include.</description>
<name>yarn.resourcemanager.nodes.include-path</name>
<value></value>
</property>
<property>
<!-- 决定哪些节点管理器(NM)不可以连接到名称节点 -->
<description>Path to file with nodes to exclude.</description>
<name>yarn.resourcemanager.nodes.exclude-path</name>
<value></value>
</property>
当include文件和exclude文件都存在的时候,优先级问题
include exclude 是否允许连接名称节点
NO NO NO
NO YES NO
c.将dfs.hosts文件路径配置到hive-site.xml中的dfs.hosts属性中
d.节点管理器同上,配置yarn-site.xml的yarn.resourcemanager.nodes.include-path
YES NO YES
YES YES YES(节点为退役状态)
服役新节点
1.添加新节点地址到Include文件中
a.在hadoop/etc/hadoop/文件夹下新建dfs.hosts文件
b.添加节点网络地址到dfs.hosts文件中
c.将dfs.hosts文件路径配置到hive-site.xml中的dfs.hosts属性中
d.节点管理器同上,配置yarn-site.xml的yarn.resourcemanager.nodes.include-path
2.刷新名称节点(NN)
$>hdfs dfsamin -refreshNodes
3.刷新资源管理器(RM)
$>yarn rmadmin -refreshNodes
4.更新slaves文件
5.启动新的节点
#连接到新添加的节点上,启动datanode和nodemanager
$>ssh newnode
$>hadoop-daemon.sh start datanode
$>yarn-daemon.sh start nodemanager
6.登录webui查看是否连接
7.实现集群再平衡(集群数据均衡,此步骤也可以不操作)
$>start-balancer.sh
退役旧节点
1.添加要退役的节点地址到exclude文件中,注意不要更新include文件
a.在hadoop/etc/hadoop/文件夹下新建dfs.hosts.exclude文件
b.添加要退役的节点网络地址到dfs.hosts文件中
c.配置dfs.hosts.exclude
d.配置yarn.resourcemanager.nodes.exclude-path
2.刷新名称节点(NN)
$>hdfs dfsamin -refreshNodes
3.刷新资源管理器(RM)
$>yarn rmadmin -refreshNodes
4.查看webui,退役节点的状态为 decommission in progress ,正在复制block到其他节点
5.当节点状态变为decommissioned,停止退役节点
#登录到要退役的节点上 停止DN和NM
$>ssh newnode
$>hadoop-daemon.sh stop datanode
$>yarn-daemon.sh stop nodemanager
6.将节点从include文件中删除,再刷新节点
a.删除include文件中的退役节点
b.$>hdfs dfsamin -refreshNodes
c.$>yarn rmadmin -refreshNodes
7.从slaves文件中删除退役节点