在namenode节点:
vi /etc/hosts
增加 新增节点IP node3
# 复制到其他DataNode节点
scp /etc/hosts node1:/etc/hosts
scp /etc/hosts node2:/etc/hosts
scp /etc/hosts node3:/etc/hosts
在namenode节点,通过scp上传安装包
scp -r /home/user/hadoop/hadoop/etc/hadoop/ root@node3:/home/user/hadoop/hadoop/etc/
在新节点
export HADOOP_HOME=/home/user/hadoop/hadoop-3.0.3
export HADOOP_CONF_DIR=/home/user/hadoop/hadoop-3.0.3/etc/hadoop
export PATH=$PATH:$HADOOP_HOME/bin
在namenode节点下的/home/taiyi/hadoop/hadoop/etc/hadoop/workers
填写新增节点主机名
vi workers
node1
node2
node3
发送到各节点
scp /home/user/hadoop/hadoop-3.0.3/etc/hadoop/workers root@node3:/home/user/hadoop/hadoop-3.0.3/etc/hadoop
scp /home/user/hadoop/hadoop-3.0.3/etc/hadoop/workers root@node3:/home/user/hadoop/hadoop-3.0.3/etc/hadoop
如果不清理可能:
- 会出现clusterid不一致的报错
- 新节点与被复制节点的datanodeUuid一样(位置:…/current/VERSION文件)这样会导致,被复制节点和新节点的冲突。
具体数据目录位置在:hdfs-site.xml文件中查看。
<property>
<name>dfs.datanode.data.dirname>
<value>/opt/data/hdfs/data,/opt/data02/hdfs/datavalue>
<description>If necessary, use these files to control the list of allowable datanodes.
不允许加入的datanode
description>
property>
<property>
<name>dfs.namenode.name.dirname>
<value>/opt/data/hdfs/namenode,/opt/data02/hdfs/namenodevalue>
<description>If this is a comma-delimited list of directories then the name table is replicated in all of the
directories, for redundancy.
Path on the local filesystem where the NameNode stores the namespace and transactions logs persistently.
用于保存Namenode的namespace和事务日志的路径
description>
property>
对于新添加的DataNode、nodemanger,在新节点启动
hdfs --daemon start datanode
yarn --daemon start nodemanager
在namenode节点刷新新启动的节点
hdfs dfsadmin -refreshNodes
也可在页面查看:namenodeip:9870
查看集群情况
hdfs dfsadmin -report
Configured Capacity: 24593821065216 (22.37 TB)
Present Capacity: 23916454670336 (21.75 TB)
DFS Remaining: 23885509402624 (21.72 TB)
DFS Used: 30945267712 (28.82 GB)
DFS Used%: 0.13%
Replicated Blocks:
Under replicated blocks: 54
Blocks with corrupt replicas: 0
Missing blocks: 0
Missing blocks (with replication factor 1): 0
Pending deletion blocks: 0
Erasure Coded Block Groups:
Low redundancy block groups: 0
Block groups with corrupt internal blocks: 0
Missing block groups: 0
Pending deletion blocks: 0
-------------------------------------------------
Live datanodes (3):
yarn节点
yarn node -list
2023-08-29 18:20:42,615 INFO client.RMProxy: Connecting to ResourceManager at /node1:8832
Total Nodes:3
Node-Id Node-State Node-Http-Address Number-of-Running-Containers
node3.xxxxxxxxxxxxxxxxxxxxxxx.net:34003 RUNNING
node3.xxxxxxxxxxxxxxxxxxxxxxx.net:8042 0
node1xxxxxxxxxxxxxxxxxxxxxxxx.net:45637 RUNNING
node1.xxxxxxxxxxxxxxxxxxxxxxxxxx.:8042 0
node2.xxxxxxxxxxxxxxxxxxxxxxxxxxx:39647 RUNNING
node2.xxxxxxxxxxxxxxxxxxxxxxxxxxxx:8042 0
看到之前的两个节点,现在是3个了。
在namenode节点执行
#对hdfs负载设置均衡,因为默认的数据传输带宽比较低,可以设置为64M
hdfs dfsadmin -setBalancerBandwidth 67108864
#默认balancer的threshold为10%,即各个节点与集群总的存储使用率相差不超过10%,我们可将其设置为5%
start-balancer.sh -threshold 5
注意
1)如果不balance,那么cluster会把新的数据都存放在新的node上,这样会降低mapred的工作效率
2)设置平衡阈值,默认是10%,值越低各节点越平衡,但消耗时间也更长
3)设置balance的带宽,默认只有1M/s
<property>
<name>dfs.balance.bandwidthPerSecname>
<value>1048576value>
<description>
Specifies the maximum amount of bandwidth that each datanode
can utilize for the balancing purpose in term of
the number of bytes per second.
description>
property>
禁止操作:
在worker节点通过:
hdfs --daemon stop datanode
命令关掉datanode,这会使hdfs中出现missing block。
在namenode节点,修改hdfs-site.xml文件
<property>
<!--dfs.hosts.exclude定义的文件内容为,每个需要下线的机器,一行一个-->
<name>dfs.hosts.exclude</name>
<value>xxx/excludes</value>
</property>
namenode上创建并修改excludes文件,添加需要删除节点的IP
nanenode上刷新节点配置情况:
hadoop dfsadmin -refreshNodes
此时在Web UI上就可以看到该节点变为Decommissioning状态,过一会就变为Dead了。
也可以通过如下命令查看
hadoop dfsadmin -report
在datanode节点执行:
hdfs --daemon stop datanode
1.在namenode的excludes文件中删除相应节点IP
2.在datanodenode节点上重启datanode进程:hadoop-daemon.sh start datanode
3.在namenode上刷新节点配置情况:hadoop dfsadmin -refreshNodes
yarn的删除节点操作类似,在yarn-site.xml配置下
yarn.resourcemanager.nodes.exclude-path
参考:
https://www.cnblogs.com/xinfang520/p/10131756.html
https://www.tutorialspoint.com/hadoop/hadoop_multi_node_cluster.htm