配置好hosts解析
[root@node1 ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 10.168.1.121 node1 10.168.1.122 node2 10.168.1.123 node3 10.168.1.124 node4
ntp时间同步
ntpdate pool.ntp.org
关闭防火墙,selinux
[root@node4 ~]# sed -i '/SELINUX/s/enforcing/disabled/g' /etc/selinux/config [root@node4 ~]# setenforce 0 [root@node4 ~]# systemctl stop firewalld.service [root@node4 ~]# systemctl disable firewalld.service
配置免秘钥
Node1节点作为Master控制节点,执行如下指令创建公钥和私钥,然后将公钥拷贝至其余节点即可。
[root@node1 ~]# ssh-copy-id -i /root/.ssh/id_rsa.pub root@node4
配置节点JAVA环境
[root@node4 ~]# tar -xvzf jdk1.8.0_131.tar.gz [root@node4 ~]# mkdir -p /usr/java/ [root@node4 ~]# \mv jdk1.8.0_131 /usr/java/ [root@node4 ~]# cat>>/etc/profile<<EOF > export JAVA_HOME=/usr/java/jdk1.8.0_131/ > export HADOOP_HOME=/data/hadoop/ > export JAVA_LIBRARY_PATH=/data/hadoop/lib/native/ > export PATH=\$PATH:\$HADOOP_HOME/bin/:\$JAVA_HOME/bin > EOF [root@node4 ~]# source /etc/profile [root@node4 ~]# java -version java version "1.8.0_131" Java(TM) SE Runtime Environment (build 1.8.0_131-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
hadoop部署
将Node1部署完成的hadoop所有文件、目录同步至node2和node3节点
[root@node1 sbin]# for i in node4;do ssh -l root $i -a "mkdir -p /data/hadoop/" ;done [root@node1 sbin]# for i in node4;do rsync -aP --delete /data/hadoop/ root@$i:/data/hadoop/ ;done [root@node1 sbin]# for i in node4;do ssh -l root $i -a "rm -rf /data/hadoop/data* ";done
添加hadoop新节点
动态添加DataNode和NodeManager节点,查看现有HDFS各节点状态
[root@node1 sbin]# hdfs dfsadmin -report Configured Capacity: 86230695936 (80.31 GB) Present Capacity: 62350409728 (58.07 GB) DFS Remaining: 61576511488 (57.35 GB) DFS Used: 773898240 (738.05 MB) DFS Used%: 1.24% Replicated Blocks: Under replicated blocks: 0 Blocks with corrupt replicas: 0 Missing blocks: 0 Missing blocks (with replication factor 1): 0 Low redundancy blocks with highest priority to recover: 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 Low redundancy blocks with highest priority to recover: 0 Pending deletion blocks: 0 ------------------------------------------------- Live datanodes (3): Name: 10.168.1.121:9866 (node1) Hostname: node1 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 251666432 (240.01 MB) Non DFS Used: 8694652928 (8.10 GB) DFS Remaining: 19797245952 (18.44 GB) DFS Used%: 0.88% DFS Remaining%: 68.88% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 12:32:11 CST 2021 Last Block Report: Sun Jul 04 11:11:59 CST 2021 Num of Blocks: 4 Name: 10.168.1.122:9866 (node2) Hostname: node2 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 267587584 (255.19 MB) Non DFS Used: 7599312896 (7.08 GB) DFS Remaining: 20876664832 (19.44 GB) DFS Used%: 0.93% DFS Remaining%: 72.63% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 12:32:10 CST 2021 Last Block Report: Sun Jul 04 11:11:58 CST 2021 Num of Blocks: 3 Name: 10.168.1.123:9866 (node3) Hostname: node3 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 254644224 (242.85 MB) Non DFS Used: 7586320384 (7.07 GB) DFS Remaining: 20902600704 (19.47 GB) DFS Used%: 0.89% DFS Remaining%: 72.72% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 12:32:10 CST 2021 Last Block Report: Sun Jul 04 11:11:58 CST 2021 Num of Blocks: 3
添加DataNode和NodeManager节点,在所有服务器的Hadoop workers文件中添加node4节点
[root@node1 sbin]# echo node4 >>/data/hadoop/etc/hadoop/workers ;cat /data/hadoop/etc/hadoop/workers node1 node2 node3 node4
新加节点启动
在Node4新增节点服务器上启动:DataNode和NodeManager服务
[root@node4 ~]# hdfs --daemon start datanode [root@node4 ~]# yarn --daemon start nodemanager [root@node4 ~]# jps 11040 Jps 10966 NodeManager 10858 DataNode
刷新Hadoop集群节点信息
[root@node1 sbin]# hdfs dfsadmin -refreshNodes Refresh nodes successful [root@node1 sbin]# /data/hadoop/sbin/start-balancer.sh
再次查看集群的状态,查看HDFS各节点状态
添加DataNode节点后,输出的结果中存在Node4服务器上的DataNode节点。说明添加DataNode节点成功
[root@node1 sbin]# hdfs dfsadmin -report Configured Capacity: 114974261248 (107.08 GB) Present Capacity: 79917965312 (74.43 GB) DFS Remaining: 79144058880 (73.71 GB) DFS Used: 773906432 (738.05 MB) DFS Used%: 0.97% Replicated Blocks: Under replicated blocks: 0 Blocks with corrupt replicas: 0 Missing blocks: 0 Missing blocks (with replication factor 1): 0 Low redundancy blocks with highest priority to recover: 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 Low redundancy blocks with highest priority to recover: 0 Pending deletion blocks: 0 ------------------------------------------------- Live datanodes (4): Name: 10.168.1.121:9866 (node1) Hostname: node1 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 251666432 (240.01 MB) Non DFS Used: 8694775808 (8.10 GB) DFS Remaining: 19797123072 (18.44 GB) DFS Used%: 0.88% DFS Remaining%: 68.87% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 12:40:50 CST 2021 Last Block Report: Sun Jul 04 11:11:59 CST 2021 Num of Blocks: 4 Name: 10.168.1.122:9866 (node2) Hostname: node2 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 267587584 (255.19 MB) Non DFS Used: 7599312896 (7.08 GB) DFS Remaining: 20876664832 (19.44 GB) DFS Used%: 0.93% DFS Remaining%: 72.63% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 12:40:49 CST 2021 Last Block Report: Sun Jul 04 11:11:58 CST 2021 Num of Blocks: 3 Name: 10.168.1.123:9866 (node3) Hostname: node3 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 254644224 (242.85 MB) Non DFS Used: 7586320384 (7.07 GB) DFS Remaining: 20902600704 (19.47 GB) DFS Used%: 0.89% DFS Remaining%: 72.72% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 12:40:49 CST 2021 Last Block Report: Sun Jul 04 11:11:58 CST 2021 Num of Blocks: 3 Name: 10.168.1.124:9866 (node4) Hostname: node4 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 8192 (8 KB) Non DFS Used: 11175886848 (10.41 GB) DFS Remaining: 17567670272 (16.36 GB) DFS Used%: 0.00% DFS Remaining%: 61.12% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 12:40:50 CST 2021 Last Block Report: Sun Jul 04 12:38:11 CST 2021 Num of Blocks: 0
查看/data/hadoop/data_1/current/BP-1809307895-10.168.1.121-1625309798057/current/finalized/subdir0/subdir0 文件夹,看看数据有没有均衡过来。
[root@node4 subdir0]# ll /data/hadoop/data_1/current/BP-1809307895-10.168.1.121-1625309798057/current/finalized/subdir0/subdir0 总用量 0 [root@node4 subdir0]# ls [root@node4 subdir0]# ll /data/hadoop/data_1/current/BP-1809307895-10.168.1.121-1625309798057/current/finalized/subdir0/subdir0 总用量 195240 -rw-r--r--. 1 root root 134217728 7月 4 13:01 blk_1073741825 -rw-r--r--. 1 root root 1048583 7月 4 13:01 blk_1073741825_1001.meta -rw-r--r--. 1 root root 64151137 7月 4 13:01 blk_1073741826 -rw-r--r--. 1 root root 501191 7月 4 13:01 blk_1073741826_1002.meta
如果发现新加的节点上没有数据,可以查看配置文件/data/hadoop/etc/hadoop/hdfs-site.xml
并做以下修改,修改副本数为3
<property> <name>dfs.replication</name> --副本数 <value>3</value> </property>
删除Hadoop节点
在现有Hadoop 4台集群的基础上动态删除Node2服务器上的DataNode与NodeManager节点
删除Node2上DataNode与NodeManager节点,停止DataNode和NodeManager进程
[root@node2 ~]# hdfs --daemon stop datanode [root@node2 ~]# yarn --daemon stop nodemanager [root@node2 ~]# jps 9780 Jps
删除每台服务器上Hadoop的workers文件中的Node2(集群内每台都要操作哦)
[root@node1 sbin]# sed -i '/^node2$/d' /data/hadoop/etc/hadoop/workers ;cat /data/hadoop/etc/hadoop/workers node1 node3 node4
在node1服务器上执行如下命令,刷新Hadoop集群节点
[root@node1 sbin]# hdfs dfsadmin -refreshNodes Refresh nodes successful [root@node1 sbin]# /data/hadoop/sbin/start-balancer.sh
查看HDFS各节点状态
[root@node1 sbin]# hdfs dfsadmin -report Configured Capacity: 114974261248 (107.08 GB) Present Capacity: 79917268994 (74.43 GB) DFS Remaining: 79143354368 (73.71 GB) DFS Used: 773914626 (738.06 MB) DFS Used%: 0.97% Replicated Blocks: Under replicated blocks: 0 Blocks with corrupt replicas: 0 Missing blocks: 0 Missing blocks (with replication factor 1): 0 Low redundancy blocks with highest priority to recover: 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 Low redundancy blocks with highest priority to recover: 0 Pending deletion blocks: 0 ------------------------------------------------- Live datanodes (4): Name: 10.168.1.121:9866 (node1) Hostname: node1 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 251666418 (240.01 MB) Non DFS Used: 8694964238 (8.10 GB) DFS Remaining: 19796934656 (18.44 GB) DFS Used%: 0.88% DFS Remaining%: 68.87% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 12:57:23 CST 2021 Last Block Report: Sun Jul 04 11:11:59 CST 2021 Num of Blocks: 4 Name: 10.168.1.122:9866 (node2) Hostname: node2 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 267587584 (255.19 MB) Non DFS Used: 7599312896 (7.08 GB) DFS Remaining: 20876664832 (19.44 GB) DFS Used%: 0.93% DFS Remaining%: 72.63% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 12:47:22 CST 2021 Last Block Report: Sun Jul 04 11:11:58 CST 2021 Num of Blocks: 3 Name: 10.168.1.123:9866 (node3) Hostname: node3 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 254644224 (242.85 MB) Non DFS Used: 7586443264 (7.07 GB) DFS Remaining: 20902477824 (19.47 GB) DFS Used%: 0.89% DFS Remaining%: 72.72% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 12:57:22 CST 2021 Last Block Report: Sun Jul 04 11:11:58 CST 2021 Num of Blocks: 3 Name: 10.168.1.124:9866 (node4) Hostname: node4 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 16400 (16.02 KB) Non DFS Used: 11176271856 (10.41 GB) DFS Remaining: 17567277056 (16.36 GB) DFS Used%: 0.00% DFS Remaining%: 61.12% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 12:57:23 CST 2021 Last Block Report: Sun Jul 04 12:38:11 CST 2021 Num of Blocks: 0
由于我刚刚查了下状态还是正常的,我改了下我的/data/hadoop/etc/hadoop/hdfs-site.xml,配置文件,内容如下:
heartbeat.recheck.interval 5000
dfs.heartbeat.interval 3
如果heartbeat.recheck.interval设置为5000(毫秒),dfs.heartbeat.interval设置为3(秒,默认),则总的超时时间为40秒。
[root@node1 sbin]# cat /data/hadoop/etc/hadoop/hdfs-site.xml <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <property> <name>dfs.name.dir</name> <value>/data/hadoop/data_name1,/data/hadoop/data_name2</value> </property> <property> <name>dfs.data.dir</name> <value>/data/hadoop/data_1,/data/hadoop/data_2</value> </property> <property> <name>dfs.block.size</name> <value>67108864</value> --修改大小 <description>Block size</description> </property> <property> <name>heartbeat.recheck.interval</name> --修改超时时间 <value>5000</value> </property> <property> <name>dfs.heartbeat.interval</name> --修改副本数 <value>3</value> </property> <property> <name>dfs.replication</name> <value>3</value> </property> </configuration>
再次查看
Live datanodes (3):
Dead datanodes (1):
[root@node1 sbin]# hdfs dfsadmin -report Configured Capacity: 86230695936 (80.31 GB) Present Capacity: 58505794614 (54.49 GB) DFS Remaining: 57731915776 (53.77 GB) DFS Used: 773878838 (738.03 MB) DFS Used%: 1.32% Replicated Blocks: Under replicated blocks: 0 Blocks with corrupt replicas: 0 Missing blocks: 0 Missing blocks (with replication factor 1): 0 Low redundancy blocks with highest priority to recover: 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 Low redundancy blocks with highest priority to recover: 0 Pending deletion blocks: 0 ------------------------------------------------- Live datanodes (3): Name: 10.168.1.121:9866 (node1) Hostname: node1 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 251666432 (240.01 MB) Non DFS Used: 8694841344 (8.10 GB) DFS Remaining: 19797057536 (18.44 GB) DFS Used%: 0.88% DFS Remaining%: 68.87% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 13:03:02 CST 2021 Last Block Report: Sun Jul 04 11:11:59 CST 2021 Num of Blocks: 4 Name: 10.168.1.123:9866 (node3) Hostname: node3 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 254644224 (242.85 MB) Non DFS Used: 7586525184 (7.07 GB) DFS Remaining: 20902395904 (19.47 GB) DFS Used%: 0.89% DFS Remaining%: 72.72% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 13:03:04 CST 2021 Last Block Report: Sun Jul 04 11:11:58 CST 2021 Num of Blocks: 3 Name: 10.168.1.124:9866 (node4) Hostname: node4 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 267568182 (255.17 MB) Non DFS Used: 11443534794 (10.66 GB) DFS Remaining: 17032462336 (15.86 GB) DFS Used%: 0.93% DFS Remaining%: 59.26% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 13:03:02 CST 2021 Last Block Report: Sun Jul 04 12:38:11 CST 2021 Num of Blocks: 3 Dead datanodes (1): Name: 10.168.1.122:9866 (node2) Hostname: node2 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 267587584 (255.19 MB) Non DFS Used: 7599312896 (7.08 GB) DFS Remaining: 20876664832 (19.44 GB) DFS Used%: 0.93% DFS Remaining%: 72.63% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 0 Last contact: Sun Jul 04 12:47:22 CST 2021 Last Block Report: Sun Jul 04 11:11:58 CST 2021 Num of Blocks: 0
动态删除DataNode节点与NodeManager节点,方式二
动态删除DataNode节点与NodeManager节点的另一种方式,这种方式不需要删除workers文件中现有的Node3服务器配置。
在Node1节点上修改hdfs-site.xml文件,适当减小dfs.replication副本数,增加dfs.hosts.exclude配置如下
<property> <name>dfs.replication</name> --副本数 <value>2</value> </property> <property> <name>dfs.hosts.exclude</name> -- <value>/data/hadoop/etc/hadoop/excludes</value> </property>
在node1服务器上的/data/hadoop/etc/hadoop/目录下创建excludes文件,将要删除的Node3服务器节点的主机名或IP地址配置到这个文件中
[root@node1 sbin]# vim /data/hadoop/etc/hadoop/excludes node3
刷新节点,在node1服务器上执行如下命令,刷新Hadoop集群节点
[root@node1 sbin]# hdfs dfsadmin -refreshNodes Refresh nodes successful [root@node1 sbin]# /data/hadoop/sbin/start-balancer.sh
查看节点
[root@node1 sbin]# hdfs dfsadmin -report Configured Capacity: 57487130624 (53.54 GB) Present Capacity: 37086025416 (34.54 GB) DFS Remaining: 36312170496 (33.82 GB) DFS Used: 773854920 (738.01 MB) DFS Used%: 2.09% Replicated Blocks: Under replicated blocks: 0 Blocks with corrupt replicas: 0 Missing blocks: 0 Missing blocks (with replication factor 1): 0 Low redundancy blocks with highest priority to recover: 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 Low redundancy blocks with highest priority to recover: 0 Pending deletion blocks: 0 ------------------------------------------------- Live datanodes (3): Name: 10.168.1.121:9866 (node1) Hostname: node1 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 386932743 (369.01 MB) Non DFS Used: 8837644281 (8.23 GB) DFS Remaining: 19518988288 (18.18 GB) DFS Used%: 1.35% DFS Remaining%: 67.91% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 13:34:45 CST 2021 Last Block Report: Sun Jul 04 13:33:30 CST 2021 Num of Blocks: 5 Name: 10.168.1.123:9866 (node3) Hostname: node3 Decommission Status : Decommissioned Configured Capacity: 28743565312 (26.77 GB) DFS Used: 254644224 (242.85 MB) Non DFS Used: 7587172352 (7.07 GB) DFS Remaining: 20901748736 (19.47 GB) DFS Used%: 0.89% DFS Remaining%: 72.72% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 13:34:44 CST 2021 Last Block Report: Sun Jul 04 13:33:30 CST 2021 Num of Blocks: 3 Name: 10.168.1.124:9866 (node4) Hostname: node4 Decommission Status : Normal Configured Capacity: 28743565312 (26.77 GB) DFS Used: 386922177 (369.00 MB) Non DFS Used: 11563460927 (10.77 GB) DFS Remaining: 16793182208 (15.64 GB) DFS Used%: 1.35% DFS Remaining%: 58.42% Configured Cache Capacity: 0 (0 B) Cache Used: 0 (0 B) Cache Remaining: 0 (0 B) Cache Used%: 100.00% Cache Remaining%: 0.00% Xceivers: 1 Last contact: Sun Jul 04 13:34:44 CST 2021 Last Block Report: Sun Jul 04 13:33:30 CST 2021 Num of Blocks: 5
评论