参考:
Hadoop集群搭建
Hadoop学习之路(四)Hadoop集群搭建和简单应用
Hadoop集群安装配置教程_Hadoop3.1.3_Ubuntu
Ubuntu搭建Hadoop3.2.1详细步骤 (一)SSH公钥链接
如何搭建一个Hadoop集群
master配置
(O) 安装 Ubuntu server 20.04
主机名:master
用户名:hadoop
用户密码:****
密钥登陆:GitHub
(一) 安装 jdk-8u271-linux-x64.tar.gz
创建目录:mkdir /usr/java
解压到目标目录:tar -zxvf jdk-8u271-linux-x64.tar.gz -C /usr/java/
环境变量:sudo vim /etc/profile
#此处的目录是jdk的安装目录
export JAVA_HOME=/usr/java/jdk1.8.0_271
#下面的都一样
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
export JRE_HOME=$JAVA_HOME/jre
测试安装成功与否:java -version
hadoop@master:~$ source /etc/profile
hadoop@master:~$ java -version
java version "1.8.0_271"
Java(TM) SE Runtime Environment (build 1.8.0_271-b09)
Java HotSpot(TM) 64-Bit Server VM (build 25.271-b09, mixed mode)
hadoop@master:~$
查看Java安装位置:which java
hadoop@master:~$ which java
/usr/java/jdk1.8.0_271/bin/java
hadoop@master:~$
(二) 安装 hadoop-3.2.1.tar.gz
解压安装:tar -xzf jdk-8u271-linux-x64.tar.gz
环境变量:sudo vim ./.bashrc
#此处的目录是Hadoop的安装目录
export HADOOP_HOME=/home/hadoop/hadoop-3.2.1
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:
测试是否安装成功:hadoop version
hadoop@master:~$ source ./.bashrc
hadoop@master:~$ hadoop version
Hadoop 3.2.1
Source code repository https://gitbox.apache.org/repos/asf/hadoop.git -r b3cbbb467e22ea829b3808f4b7b01d07e0bf3842
Compiled by rohithsharmaks on 2019-09-10T15:56Z
Compiled with protoc 2.5.0
From source with checksum 776eaf9eee9c0ffc370bcbc1888737
This command was run using /home/hadoop/hadoop-3.2.1/share/hadoop/common/hadoop-common-3.2.1.jar
hadoop@master:~$
(三) 修改hosts文件 & 关闭防火墙
在里面加入(只能有localhost
对应127.0.0.1
,其它127.0.0.1
对应的行删掉)
hadoop@master:~$ sudo vim /etc/hosts
127.0.0.1 localhost
192.168.1.218 master
192.168.1.221 slaves1
192.168.1.222 slaves2
192.168.1.223 slaves3
192.168.1.224 slaves4
关闭服务器的防火墙,并且禁止开机启动,这样就不用在各个服务器上对端口进行控制。
hadoop@master:~$ systemctl stop firewalld.service
hadoop@master:~$ systemctl disable firewalld.service
(四)修改 ./hadoop-3.2.1/etc/hadoop/ 目录下的8个文件
0. hadoop-env.sh & mapred-env.sh &yarn-env.sh
给三个文件都添加JAVA_HOME
export JAVA_HOME=/usr/java/jdk1.8.0_271
1. core-site.xml
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://master:9000</value>
<description>确定 NameNode 所在的服务器(第一台服务器)</description>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/hadoop/data/hadoopdata</value>
</property>
</configuration>
2. hdfs-site.xml
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>/home/hadoop/data/hadoopdata/name</value>
<description>为了保证元数据的安全一般配置多个不同目录</description>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/home/hadoop/data/hadoopdata/data</value>
<description>datanode 的数据存储目录</description>
</property>
<property>
<name>dfs.replication</name>
<value>3</value>
<description>HDFS 的数据块的副本存储个数, 默认是3</description>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>master:9001</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
<property>
<name>dfs.namenode.datanode.registration.ip-hostname-check</name>
<value>false</value>
</property>
<property>
<name>dfs.http.address</name>
<value>0.0.0.0:50070</value>
</property>
</configuration>
3. mapered-site.xml
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>yarn.app.mapreduce.am.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
<name>mapreduce.map.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
<name>mapreduce.reduce.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
</configuration>
4. yarn-site.xml
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.nodemanager.auxservices.mapreduce.shuffle.class</name>
<value>org.apache.hadoop.mapred.ShuffleHandler</value>
</property>
<property>
<name>yarn.log-aggregation-enable</name>
<value>true</value>
</property>
<property>
<name>yarn.log-aggregation.retain-seconds</name>
<value>604800</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>2048</value>
</property>
<property>
<name>yarn.resourcemanager.address</name>
<value>master:8032</value>
</property>
<property>
<name>yarn.resourcemanager.scheduler.address</name>
<value>master:8030</value>
</property>
<property>
<name>yarn.resourcemanager.resource-tracker.address</name>
<value>master:8031</value>
</property>
<property>
<name>yarn.nodemanager.resource.memory-mb</name>
<value>20480</value>
</property>
<property>
<name>yarn.scheduler.minimum-allocation-mb</name>
<value>2048</value>
</property>
<property>
<name>yarn.nodemanager.vmem-pmem-ratio</name>
<value>2.1</value>
</property>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>master</value>
</property>
<property>
<name>yarn.application.classpath</name><!--这里的值在终端中调用: hadoop classpath 将获得的值替换掉value部分 -->
<value>/home/wy/hadoop-3.2.1/etc/hadoop:/home/wy/hadoop-3.2.1/share/hadoop/common/lib/*:/home/wy/hadoop-3.2.1/share/hadoop/common/*:/home/wy/hadoop-3.2.1/share/hadoop/hdfs:/home/wy/hadoop-3.2.1/share/hadoop/hdfs/lib/*:/home/wy/hadoop-3.2.1/share/hadoop/hdfs/*:/home/wy/hadoop-3.2.1/share/hadoop/mapreduce/lib/*:/home/wy/hadoop-3.2.1/share/hadoop/mapreduce/*:/home/wy/hadoop-3.2.1/share/hadoop/yarn:/home/wy/hadoop-3.2.1/share/hadoop/yarn/lib/*:/home/wy/hadoop-3.2.1/share/hadoop/yarn/*</value>
</property>
</configuration>
5. worker
master
slaves1
slaves2
slaves3
slaves4
slave配置
将master机复制你想要的数量,然后:
(一)修改主机名
sudo vim /etc/hostname
是slave1,主机名就改为slave1;
是slave2,主机名就改为slave2;
等等
(二)设置静态ip
sudo vi /etc/netplan/00-installer-config.yaml
设置成,和之前配置一样的ip
network:
ethernets:
enp0s3:
addresses: [192.168.1.221/24]
gateway4: 192.168.1.1
nameservers:
addresses: [4.2.2.2, 8.8.8.8]
version: 2
注意对应关系如下:
192.168.1.221 slaves1
192.168.1.222 slaves2
192.168.1.223 slaves3
192.168.1.224 slaves4
(三)修改 ./hadoop-3.2.1/etc/hadoop/ 目录下的2个文件
1. hdfs-site.xml
和master的区别只有一点点:slaves2
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>/home/hadoop/data/hadoopdata/name</value>
<description>为了保证元数据的安全一般配置多个不同目录</description>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>/home/hadoop/data/hadoopdata/data</value>
<description>datanode 的数据存储目录</description>
</property>
<property>
<name>dfs.replication</name>
<value>3</value>
<description>HDFS 的数据块的副本存储个数, 默认是3</description>
</property>
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>slaves2:9001</value>
</property>
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
<property>
<name>dfs.namenode.datanode.registration.ip-hostname-check</name>
<value>false</value>
</property>
<property>
<name>dfs.http.address</name>
<value>0.0.0.0:50070</value>
</property>
</configuration>
2. mapered-site.xml
和master的区别,多了一个property
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
<property>
<name>yarn.app.mapreduce.am.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
<name>mapreduce.map.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
<name>mapreduce.reduce.env</name>
<value>HADOOP_MAPRED_HOME=${HADOOP_HOME}</value>
</property>
<property>
<name>mapreduce.jobhistory.address</name>
<value>master:10020</value>
<name>mapreduce.jobhistory.webapp.address</name>
<value>master:19888</value>
</property>
</configuration>
启动
master机
格式化
hadoop namenode -format
启动集群
start-all.sh
查看是否启动
jps
hadoop@master:~$ jps
19920 DataNode
20962 NodeManager
20626 SecondaryNameNode
20792 ResourceManager
23129 Jps
20266 NameNode
slave机
查看是否启动
jps
hadoop@slaves4:~$ jps
11485 NodeManager
11181 DataNode
11599 Jps
在浏览器中查看
关闭集群
stop-all.sh
中间的坑
因为我参考了多个方法,所以搭建时难免有上次的logs,dfs文件残留,一定要记得删掉。
比如,我遇到的Hadoop启动的时候,发现Datanode启动不了,解决办法
相关工具
虚拟机:VMware ESXi
SSH:Termius
文件传输:Transmit