当我们的hadoop
集群运行了一段时间之后,原有的数据节点的容量已经不能满足我们的存储了,这个时候就需要往集群中增加新的数据节点。此时我们就需要动态的对hdfs集群进行扩容操作(节点服役
)。
(资料图)
2、集群黑白名单在hdfs
集群中是存在黑名单
和白名单
的。
黑名单:
该文件包含不允许
连接到namenode
的主机列表。必须指定文件的完整路径名
。如果该值为空,则表示不排除任何主机。白名单:
该文件包含允许
连接到namenode
的主机列表。必须指定文件的完整路径名
。如果该值为空,则允许所有主机
黑白名单配置
vim hdfs-site.xml
dfs.hosts.exclude /opt/bigdata/hadoop-3.3.4/etc/hadoop/blacklist.hosts dfs.hosts /opt/bigdata/hadoop-3.3.4/etc/hadoop/whitelist.hosts
注意:
第一次配置黑白名单时,需要重启集群才可以生效,之后修改了黑白名单文件,只需要执行 hdfs dfsadmin -refreshNodes
命令即可。
参考此文章的集群搭建
3.2 准备一台新的机器ip地址: 192.168.121.143主机名: hadoop043.2.1 查看新机器的ip3.2.2 修改主机名和host映射[root@appbasic ~]# vim /etc/hostname[root@appbasic ~]# cat /etc/hostnamehadoop04[root@appbasic ~]# vim /etc/hosts[root@appbasic ~]# cat /etc/hosts192.168.121.140 hadoop01192.168.121.141 hadoop02192.168.121.142 hadoop03192.168.121.143 hadoop04[root@appbasic ~]#
3.2.3 配置时间同步hadoop
集群中的各个机器之间的时间最好都保持一致
[root@hadoop04 ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime[root@hadoop04 ~]# yum install ntp已加载插件:fastestmirrorLoading mirror speeds from cached hostfilebase | 3.6 kB 00:00:00extras | 2.9 kB 00:00:00updates | 2.9 kB 00:00:00(1/2): extras/7/aarch64/primary_db | 252 kB 00:00:00(2/2): updates/7/aarch64/primary_db | 3.5 MB 00:00:03软件包 ntp-4.2.6p5-29.el7.centos.2.aarch64 已安装并且是最新版本无须任何处理[root@hadoop04 ~]# systemctl enable ntpd[root@hadoop04 ~]# service ntpd restartRedirecting to /bin/systemctl restart ntpd.service[root@hadoop04 ~]# ntpdate asia.pool.ntp.org29 Mar 21:42:52 ntpdate[1697]: the NTP socket is in use, exiting[root@hadoop04 ~]# /sbin/hwclock --systohc[root@hadoop04 ~]# timedatectl Local time: 三 2023-03-29 21:43:03 CST Universal time: 三 2023-03-29 13:43:03 UTC RTC time: 三 2023-03-29 13:43:03 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: yesNTP synchronized: no RTC in local TZ: no DST active: n/a[root@hadoop04 ~]# timedatectl set-ntp true[root@hadoop04 ~]#
3.2.4 关闭防火墙[root@hadoop04 ~]# systemctl stop firewalldsystemctl stop firewalld[root@hadoop04 ~]# systemctl disable firewalld.serviceRemoved symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.[root@hadoop04 ~]#
3.2.5 新建hadoop部署用户[root@hadoop04 ~]# useradd hadoopdeploy[root@hadoop04 ~]# passwd hadoopdeploy更改用户 hadoopdeploy 的密码 。新的 密码:无效的密码: 密码包含用户名在某些地方重新输入新的 密码:passwd:所有的身份验证令牌已经成功更新。[root@hadoop04 ~]# vim /etc/sudoers[root@hadoop04 ~]# cat /etc/sudoers | grep hadoopdeploy -C 3## Same thing without a password# %wheelALL=(ALL)NOPASSWD: ALLhadoopdeploy ALL=(ALL) NOPASSWD: ALL## Allows members of the users group to mount and unmount the## cdrom as root[root@hadoop04 ~]#
3.2.6 复制hadoop04机器上的/etc/hosts文件到集群的另外3台机器上[root@hadoop04 ~]# scp /etc/hosts root@hadoop01:/etc/hosts[root@hadoop04 ~]# scp /etc/hosts root@hadoop02:/etc/hosts[root@hadoop04 ~]# scp /etc/hosts root@hadoop03:/etc/hosts
3.2.7 配置集群间的免密登录此处配置 namenode(hadoop01)
与hadoop04
之间的免密登录。
[hadoopdeploy@hadoop01 ~]$ ssh-copy-id hadoop04/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/hadoopdeploy/.ssh/id_rsa.pub"The authenticity of host "hadoop04 (192.168.121.143)" can"t be established.ECDSA key fingerprint is SHA256:4GL0zHVCdSl3czA0wqcuLT60lUljyEq3DqwPFxNwYsE.ECDSA key fingerprint is MD5:3e:42:a6:50:0d:fb:f0:41:a8:0d:fb:cc:fd:20:2c:c8.Are you sure you want to continue connecting (yes/no)? yes/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keyshadoopdeploy@hadoop04"s password:Number of key(s) added: 1Now try logging into the machine, with: "ssh "hadoop04""and check to make sure that only the key(s) you wanted were added.[hadoopdeploy@hadoop01 ~]$
3.2.8将 namenode上的hadoop复制到hadoop04上[root@hadoop04 ~]# sudo mkdir /opt/bigdatamkdir: cannot create directory ‘/opt/bigdata’: No such file or directory[root@hadoop04 ~]# sudo mkdir -p /opt/bigdata[root@hadoop04 ~]# sudo chown -R hadoopdeploy:hadoopdeploy /opt/bigdata/[root@hadoop04 ~]# su - hadoopdeployLast login: Wed Mar 29 22:19:54 CST 2023 on pts/0[hadoopdeploy@hadoop04 ~]$ scp -r hadoopdeploy@hadoop01:/opt/bigdata/hadoop-3.3.4/ /opt/bigdata/[hadoopdeploy@hadoop04 hadoop]$ rm -rvf /opt/bigdata/hadoop-3.3.4/data/* rm -rvf /opt/bigdata/hadoop-3.3.4/logs/*
注意
目录的创建用户、执行scp命令的用户
注意:
如果hadoop-3.3.4
目录下存在我们之前配置的数据目录,则需要删除,否则启动这个节点的时候会有问题。日志目录也相应的删除
配置这个文件是为了方便集群的一键启动。
[hadoopdeploy@hadoop04 hadoop]$ vim /opt/bigdata/hadoop-3.3.4/etc/hadoop/workers[hadoopdeploy@hadoop04 hadoop]$ cat /opt/bigdata/hadoop-3.3.4/etc/hadoop/workershadoop01hadoop02hadoop03hadoop04[hadoopdeploy@hadoop04 hadoop]$
注意:
将这个workers
文件分发到集群的各个机器上。
[hadoopdeploy@hadoop04 hadoop]$ scp /opt/bigdata/hadoop-3.3.4/etc/hadoop/workers hadoopdeploy@hadoop01:/opt/bigdata/hadoop-3.3.4/etc/hadoop/workers[hadoopdeploy@hadoop04 hadoop]$ scp /opt/bigdata/hadoop-3.3.4/etc/hadoop/workers hadoopdeploy@hadoop02:/opt/bigdata/hadoop-3.3.4/etc/hadoop/workers[hadoopdeploy@hadoop04 hadoop]$ scp /opt/bigdata/hadoop-3.3.4/etc/hadoop/workers hadoopdeploy@hadoop03:/opt/bigdata/hadoop-3.3.4/etc/hadoop/workers
3.2.10 配置环境变量[hadoopdeploy@hadoop04 hadoop]$ source /etc/profile
[hadoopdeploy@hadoop04 logs]$ hdfs --daemon start datanode[hadoopdeploy@hadoop04 logs]$ jps2278 DataNode2349 Jps[hadoopdeploy@hadoop04 logs]$
注意:
如果我们不想让任意一台机器随便就加入到了我们的集群中,那么我们通过白名单
来控制。
新加入的节点磁盘空间比较大,这个时候我们就可以将别的节点的数据均衡到这个节点中来。
# 设置数据传输带宽[hadoopdeploy@hadoop04 logs]$ hdfs dfsadmin -setBalancerBandwidth 10485760Balancer bandwidth is set to 10485760# 执行banalce[hadoopdeploy@hadoop04 logs]$ hdfs balancer -policy datanode -threshold 5
3.4 集群节点下线3.4.1 编辑dfs.hosts.exclude配置指定的文件注意:
只需要在NameNode
或者ResourceManager
上执行即可。
vim hdfs-site.xml
dfs.hosts.exclude /opt/bigdata/hadoop-3.3.4/etc/hadoop/blacklist.hosts
注意:
这个配置文件如果之间没有配置过,则需要重启集群才生效,如果之前配置过,则在NameNode
或ResourceManager
节点上执行hdfs dfsadmin -refreshNodes
命令即可。
编辑blacklist.hosts
文件,加入需要下线的节点。(NameNode或ResourceManager上操作)
[hadoopdeploy@hadoop01 ~]$ cd /opt/bigdata/hadoop-3.3.4/etc/hadoop/[hadoopdeploy@hadoop01 hadoop]$ vim blacklist.hosts[hadoopdeploy@hadoop01 hadoop]$ cat blacklist.hostshadoop04[hadoopdeploy@hadoop01 hadoop]$ hdfs dfsadmin -refreshNodesRefresh nodes successful[hadoopdeploy@hadoop01 hadoop]$
在hdfs集群上可以看到hadoop04已经下线了
.
节点移除后,可以考虑再次均衡集群中的数据。
注意:
此时可以看到我们的集群中有4台机器,假设我们集群的副本设置为4,那么此时是不可下线节点的,需要修改集群的副本<4。
[hadoopdeploy@hadoop04 logs]$ hdfs --daemon stop datanode[hadoopdeploy@hadoop04 logs]$
3.4.4 清空黑名单里的内容 关键词:
Copyright 2015-2022 人人食品网 版权所有 备案号:粤ICP备18023326号-36 联系邮箱:8557298@qq.com