软件和操作系统版本
Hadoop框架是采用Java语言编写,需要java环境(jvm) JDK版本:JDK8版本 ,本次使用的是 Java: jdk-8u431-linux-x64.tar.gz
Hadoop: hadoop-3.3.6.tar.gz
三台Linux虚拟节点: CentOS-7-x86_64-DVD-2009.iso
通过虚拟机设置共享文件夹将需要的安装包复制到linux虚拟机中。(/opt/software/)
[root@localhost1 software]# ll
total 912972
-rwxrwxrwx. 1 root root 730107476 Dec 23 20:43 hadoop-3.3.6.tar.gz
-rwxrwxrwx. 1 root root 148362647 Dec 23 22:10 jdk-8u431-linux-x64.tar.gz
-rwxrwxrwx. 1 root root 1068 Dec 24 11:29 LICENSE
-rwxrwxrwx. 1 root root 56405224 Dec 24 11:29 VMwareTools-10.3.21-14772444.tar.gz
集群规划
Linux | Localhost1 | Localhost2 | Localhost3 |
HDFS | NameNode、DataNode | DataNode | SecondaryNameNode、DataNode |
YARN | NodeManager | NodeManager, ResourceManager | NodeManager |
安装JDK
tar -zxvf jdk-8u431-linux-x64.tar.gz -C /usr/local/java/
配置环境变量:
vi /etc/profile
# java environment
JAVA_HOME=/usr/local/java/jdk1.8.0_431
JRE_HOME=${JAVA_HOME}/jre
CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
PATH=$PATH:${JAVA_HOME}/bin:${JRE_HOME}/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH
让环境变量生效:
source /etc/profile
安装Hadoop
tar -zxvf hadoop-3.3.6.tar.gz -C /usr/local/applications
添加Hadoop到环境变量
vi /etc/profile
#HADOOP
HADOOP_HOME=/usr/local/applications/hadoop-3.3.6
PATH=$PATH:${HADOOP_HOME}/bin:${HADOOP_HOME}/sbin
export HADOOP_HOME PATH
让环境变量生效:
source /etc/profile
验证hadoop
hadoop version
集群配置
cd /usr/local/applications/hadoop-3.3.6/etc/hadoop/
HDFS集群配置
配置:hadoop-env.sh
export JAVA_HOME=/usr/local/java/jdk1.8.0_431
指定NameNode节点以及数据存储目录(修改core-site.xml)
<!-- 指定HDFS中NameNode的地址 -->
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost1:9000</value>
</property>
<!-- 指定Hadoop运行时产生文件的存储目录 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/usr/local/applications/hadoop-3.3.6/data/tmp</value>
</property>
指定secondarynamenode节点(修改hdfs-site.xml)
<!-- 指定Hadoop辅助名称节点主机配置 -->
<property>
<name>dfs.namenode.secondary.http-address</name>
<value>localhost3:50090</value>
</property>
<!--副本数量 -->
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
指定datanode从节点(修改workers文件,每个节点配置信息占一行)
localhost1
localhost2
localhost3
注意:该文件中添加的内容结尾不允许有空格,文件中不允许有空行。
MapReduce集群配置
指定MapReduce使用的jdk路径(修改mapred-env.sh)
export JAVA_HOME=/usr/local/java/jdk1.8.0_431
指定MapReduce计算框架运行Yarn资源调度框架(修改mapred-site.xml)
<!-- 指定MR运行在Yarn上 -->
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
Yarn集群配置
指定JDK路径
vi yarn-env.sh
export JAVA_HOME=/usr/local/java/jdk1.8.0_431
指定ResourceMnager的master节点信息(修改yarn-site.xml)
<!-- 指定YARN的ResourceManager的地址 -->
<property>
<name>yarn.resourcemanager.hostname</name>
<value>localhost2</value>
</property>
<!-- Reducer获取数据的方式 -->
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
分发配置
远程复制文件夹:将localhost1 配置好的Hadoop 复制到localhost2 和localhost3
scp -r /usr/local/applications/hadoop-3.3.6 root@localhost2:/usr/local/applications/hadoop-3.3.6
scp -r /usr/local/applications/hadoop-3.3.6 root@localhost3:/usr/local/applications/hadoop-3.3.6
配置SSH 密钥登陆
生成Key Pairs
在三台节点分别生成 Key Pairs, 默认名字 id_rsa, 千万不要改。
ssh-keygen -t rsa -C "root@localhost1"
ssh-keygen -t rsa -C "root@localhost2"
ssh-keygen -t rsa -C "root@localhost3"
key pairs 默认生产到 ~/.ssh/
[root@localhost1 .ssh]# ll
total 16
-rw-------. 1 root root 1191 Jan 5 20:22 authorized_keys
-rw-------. 1 root root 1679 Jan 5 20:04 id_rsa
-rw-r--r--. 1 root root 397 Jan 5 20:04 id_rsa.pub
-rw-r--r--. 1 root root 564 Jan 5 10:40 known_hosts
把三个节点的公钥互相发送到每个节点
添加公钥到远程服务器
ssh-copy-id root@localhost2
ssh-copy-id root@localhost3
添加公钥到本地
cat localhost1.pub >> authorized_keys
添加完成以后三个节点都有了所有节点的公钥
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDTmy6v6Xsv4893ofLyMVyct439T4ePv/OfEtpMPtBqLsobyiDV1Ih0H17oxI8Mk4UvZIEgokyLDq8lz8n3v4Vr5RfaCLRvbFEmn7SEzV+tBeRd9tO9rccaSjBT5NfOlFpLecucbA1JP3sS1PgVmyGvD6xE490gD1EGKWDi04fxifwvrEJPxkIRS/FKKik1fB4IRtReKQlAkh/JwE3mvBdNbL0jeOKiB01ofQfV2xoOgooBJSkQNhRqxtPccWuH6GrKK3uTTpPZWZvCoW1vHKOaOH59AGFuRlrO6yobLdQueS/VE8jx7VdlZonICorgQuxUwQsCR9Ys+xKRwcpTtWin root@localhost1
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDdRLWUfYgCZ5KS2yC6BaOtCz/nsnb6EjO8jt6q8o9deen3+/jN/hnqhHFAEPRFGKq4WwPy4awYlo1sqDxgc8GrpzUUUnkIsnERhXp9L0df99X360t9QgNwNiz3ayTa40oAT0Zg1GbftjRH/foJIReEUA1IjGTAphTQYnKwWMsTOXeIqI7A2QeUUQvxVkNWJ/lTO59vCxIA0NJUkgdMgXImfGlb23gtX/RlJ0NCqdoOm83qrNLHcC+iIwOrKpFx9v88qdajiDi+pI1AqWz1fQD6LpIx9OojM9ZPb2VYvCSt4smvCECxH+r3/HOB68+bumynm2w26XQumZA/utpQgJaH root@localhost2
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDAZ36gymNo4jmEkeS9fuwSlZ5mceFPOQcmgKnfSEi4LWzRdg1hmHK3bOzFabnRLaKGZvtK1GBFtZFHF8LAmP4/BXyDAxpU2/kFkWjn+z/Cu4bfAUl98M1Gqj7L3iv360wpGLz/VB65YIBxn88sac4hEZZUSFNMZxbRm2MIdN05YVgN7z84nLph3VNLzfpdfqnn6fLP8Fu6qwd8NaE91M95Lf7xBIdO1k0+/4/RLjTWfnpo4pKw1YM1CgGQEuz0JW6+yNuDyDwtlgNXDZeOni9JBjda/UQckguQMDDFrRzgsFTK9j5tywJQSlE0TDXIqyIUSgiajO6V//XGFP1weVLP root@localhost3
关闭防火墙
三个linux节点都需要关闭防火墙,这个Hadoop集群才能互相访问。
临时关闭
systemctl stop firewalld
永久关闭
systemctl stop firewalld
systemctl disable firewalld
启动集群
1,Namenode执行格式化
hadoop namenode -format
2, 启动HDFS
在namenode 节点执行:
cd /usr/local/applications/hadoop-3.3.6/
sbin/start-dfs.sh
3, 启动YARN
在ResouceManager节点执行:
cd /usr/local/applications/hadoop-3.3.6/
sbin/start-yarn.sh
4, 启动完成后
查看三台节点进程
[root@localhost1 hadoop-3.3.6]# jps
5232 Jps
4775 DataNode
4623 NameNode
5119 NodeManager
[root@localhost2 hadoop-3.3.6]# jps
3001 ResourceManager
3161 NodeManager
3514 Jps
2796 DataNode
[root@localhost3 ~]# jps
2793 DataNode
2907 SecondaryNameNode
3115 Jps
2991 NodeManager
5, web端查看Hdfs界面
http://localhost1:9870/dfshealth.html#tab-overview