roman_日积跬步-终至千里

roman_日积跬步-终至千里

一. 新增节点

1.配置、安装

1.1. 所有节点配置新节点主机映射

在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

 

1.2. 上传安装包

在namenode节点,通过scp上传安装包

scp -r   /home/user/hadoop/hadoop/etc/hadoop/ root@node3:/home/user/hadoop/hadoop/etc/

 

1.3. 配置环境变量

在新节点

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

 

1.4. 配置workers

在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

 

1.5. 清理之前集群的数据目录(如有)

如果不清理可能:

具体数据目录位置在:hdfs-site.xml文件中查看。

    <property>
        <name>dfs.datanode.data.dir</name>
        <value>/opt/data/hdfs/data,/opt/data02/hdfs/data</value>
        <description>If necessary, use these files to control the list of allowable datanodes.
            不允许加入的datanode
        </description>
    </property>

    <property>
        <name>dfs.namenode.name.dir</name>
        <value>/opt/data/hdfs/namenode,/opt/data02/hdfs/namenode</value>
        <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>

 

2. 新增节点启动

对于新添加的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个了。

 

3. 平衡DataNode节点

在namenode节点执行

#对hdfs负载设置均衡,因为默认的数据传输带宽比较低,可以设置为64M  
hdfs dfsadmin -setBalancerBandwidth 67108864 

#默认balancer的threshold为10%,即各个节点与集群总的存储使用率相差不超过10%,我们可将其设置为5%
start-balancer.sh -threshold 5

注意

<property>
  <name>dfs.balance.bandwidthPerSec</name>
  <value>1048576</value>
  <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>

 
 

二. 删除节点

禁止操作:

1. namenode节点操作

1.1. 添加excludes文件

在namenode节点,修改hdfs-site.xml文件

<property>
  <!--dfs.hosts.exclude定义的文件内容为,每个需要下线的机器,一行一个-->
  <name>dfs.hosts.exclude</name>
  <value>xxx/excludes</value>
</property>

namenode上创建并修改excludes文件,添加需要删除节点的IP

 

1.2. 刷新节点

nanenode上刷新节点配置情况:

hadoop dfsadmin -refreshNodes

此时在Web UI上就可以看到该节点变为Decommissioning状态,过一会就变为Dead了。

也可以通过如下命令查看

hadoop dfsadmin -report

 

2. 关闭datanode节点(非必须)

在datanode节点执行:

hdfs --daemon stop datanode

 
 

三. 重新加入删除的节点

 
 
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

08-31 06:56