当前位置:   article > 正文

Hadoop完全分布式搭建教程(完整版)_hadoop完全分布式搭建步骤

hadoop完全分布式搭建步骤
  1. 分别创建三个节点 master slave1 slave2

  1. 在master节点下安装jdk

  1. # 解压
  2. [root@master /]# tar -zxvf /opt/software/jdk-8u212-linux-x64.tar.gz -C /opt/module/
  3. # 修改安装包名为 java
  4. [root@master /]# mv /opt/module/jdk1.8.0—212/ /opt/module/java
  5. # 配置环境变量并使其生效
  6. [root@master /]# vi /etc/profile
  7. # java
  8. export JAVA_HOME=/opt/module/java
  9. export PATH=$PATH:$JAVA_HOME/bin
  10. # 验证是否成功
  11. [root@master /]# source /etc/profile
  12. [root@master /]# java -version
  13. [root@master /]# javac
  1. 配置免密登录

  1. # 配置映射环境
  2. [root@master /]# vi /etc/host
  3. # 添加三个节点的IP映射
  4. 192.168.100.4 master
  5. 192.168.100.2 slave1
  6. 192.168.100.3 slave2
  7. # 创建密钥 (三个节点都要创建)
  8. [root@master /]# ssh-keygen -t rsa -P ''
  9. # 将公钥传输给master slave1 slave2
  10. [root@master /]# ssh-copy-id root@master
  11. [root@master /]# ssh-copy-id root@slave1
  12. [root@master /]# ssh-copy-id root@slave2
  13. # 将Java安装文件传送给slave1 slave2
  14. [root@master /]# scp -r /opt/module/java/ root@slave1:/opt/module/
  15. [root@master /]# scp -r /opt/module/java/ root@slave2:/opt/module/
  1. Hadoop安装与配置

  1. # 解压Hadoop到指定文件中
  2. [root@master /]# tar -zxvf /opt/software/hadoop-3.1.3.tar.gz -C /opt/module/
  3. # 修改Hadoop名称
  4. [root@master /]# mv /opt/module/hadoop-3.1.3/ /opt/module/hadoop
  5. # 配置环境变量
  6. #hadoop
  7. export HADOOP_HOME=/opt/module/hadoop
  8. export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
  • 切换到Hadoop的etc\hadoop目录下并进行相关配置

1.配置workers文件
  1. # 配置workers 文件
  2. [root@master /]# vi workers
  3. master
  4. slave1
  5. slave2
2.配置Hadoop-env.sh文件
  1. # 配置Hadoop-env.sh文件
  2. export JAVA_HOME=/opt/module/java
  3. export HADOOP_PERFIX=/opt/module/hadoop
  4. export HADOOP_OPTS="-Djava.library.path=$HADOOP_PERFIX/lib:$HADOOP_PERFIX/lib/native"
  5. export HDFS_NAMENODE_USER=root
  6. export HDFS_DATANODE_USER=root
  7. export HDFS_SECONDARYNAMENODE_USER=root
  8. export YARN_RESOURCEMANAGER_USER=root
  9. export YARN_NODEMANAGER_USER=root
3. 配置core-site.xml 文件
  1. <!-- 配置core-site.xml 文件 -->
  2. [root@master hadoop]# vi core-site.xml
  3. <configuration>
  4. <property>
  5. <name>fs.defaultFS</name>
  6. <value>hdfs://master:9000</value>
  7. </property>
  8. <property>
  9. <name>hadoop.tmp.dir</name>
  10. <value>/opt/module/hadoop/tmp</value>
  11. </property>
  12. </configuration>
4.配置mapred-site.xml 文件
  1. <!--配置mapred-site.xml 文件-->
  2. <configuration>
  3. <property>
  4. <name>mapreduce.framework.name</name>
  5. <value>yarn</value>
  6. </property>
  7. <property>
  8. <name>mapreduce.jobhistory.address</name>
  9. <value>master:10020</value>
  10. </property>
  11. <property>
  12. <name>mapreduce.jobhistory.webapp.address</name>
  13. <value>master:19888</value>
  14. </property>
  15. </configuration>
5. 配置hdfs-site.xml文件
  1. <!--配置hdfs-site.xml文件-->
  2. <configuration>
  3. <property>
  4. <name>dfs.namenode.name.dir</name>
  5. <value>/opt/module/hadoop/dfs/name</value>
  6. </property>
  7. <property>
  8. <name>dfs.datanode.data.dir</name>
  9. <value>/opt/module/hadoop/dfs/data</value>
  10. </property>
  11. <property>
  12. <name>dfs.replication</name>
  13. <value>3</value>
  14. </property>
  15. </configuration>
6. 配置yarn-site.xml 文件
  1. <!--配置yarn-site.xml 文件-->
  2. <configuration>
  3. <property>
  4. <name>yarn.nodemanager.aux-services</name>
  5. <value>mapreduce_shuffle</value>
  6. </property>
  7. <property>
  8. <name>yarn.resourcemanager.hostname</name>
  9. <value>master</value>
  10. </property>
  11. </configuration>
  1. 创建相关目录并分发

  1. # 创建
  2. [root@master hadoop]# mkdir -p /opt/module/hadoop/dfs/name
  3. [root@master hadoop]# mkdir -p /opt/module/hadoop/dfs/data
  4. [root@master hadoop]# mkdir -p /opt/module/hadoop/tmp
  5. #分发
  6. [root@master hadoop]# scp -r /opt/module/hadoop/ root@slave1:/opt/module/
  7. [root@master hadoop]# scp -r /opt/module/hadoop/ root@slave2:/opt/module/
  8. #同步环境
  9. [root@master hadoop]# scp /etc/profile root@slave1:/etc
  10. [root@master hadoop]# scp /etc/profile root@slave2:/etc
  11. # 生效环境(三台都要)
  12. [root@master hadoop]# source /etc/profile
  1. Hadoop集群启动

  1. # 初始化namenode
  2. [root@master hadoop]# hdfs namenode -format
  3. # 启动hdfs
  4. [root@master /]# start-dfs.sh
  5. # 启动yarn
  6. [root@master /]# start-yarn.sh
  1. 验证

  1. # jps查看三个节点进程
  2. # master
  3. [root@master /]# jps
  4. 2833 Jps
  5. 1509 NameNode
  6. 1654 DataNode
  7. 2262 ResourceManager
  8. 1898 SecondaryNameNode
  9. 2429 NodeManager
  10. # slave1
  11. [root@slave1 /]# jps
  12. 642 NodeManager
  13. 787 Jps
  14. 511 DataNode
  15. # slave2
  16. [root@slave1 /]# jps
  17. 642 NodeManager
  18. 787 Jps
  19. 511 DataNode
  20. #端口验证
  21. HDFS :9870
  22. YARN :8088
  1. 端口测试

  1. master:9870查看

ii. master:8088查看

  1. mapreduce测试

  1. [root@master /]# vi a.txt
  2. [root@master /]# hadoop fs -put ~/a.txt /input
  3. # 进入到jar包测试文件目录下
  4. [root@master /]# cd /opt/module/hadoop/share/hadoop/mapreduce/
  5. # 测试mapreduce
  6. [root@master mapreduce]# hadoop jar hadoop-mapreduce-examples-3.1.3.jar wordcount /input/a.txt /output
  7. # 测试结果
  8. Map-Reduce Framework
  9. Map input records=3
  10. Map output records=6
  11. Map output bytes=59
  12. Map output materialized bytes=53
  13. Input split bytes=95
  14. Combine input records=6
  15. Combine output records=4
  16. Reduce input groups=4
  17. Reduce shuffle bytes=53
  18. Reduce input records=4
  19. Reduce output records=4
  20. Spilled Records=8
  21. Shuffled Maps =1
  22. Failed Shuffles=0
  23. Merged Map outputs=1
  24. GC time elapsed (ms)=172
  25. CPU time spent (ms)=1580
  26. Physical memory (bytes) snapshot=664891392
  27. Virtual memory (bytes) snapshot=5363101696
  28. Total committed heap usage (bytes)=745537536
  29. Peak Map Physical memory (bytes)=382193664
  30. Peak Map Virtual memory (bytes)=2678300672
  31. Peak Reduce Physical memory (bytes)=282697728
  32. Peak Reduce Virtual memory (bytes)=2684801024
  33. Shuffle Errors
  34. BAD_ID=0
  35. CONNECTION=0
  36. IO_ERROR=0
  37. WRONG_LENGTH=0
  38. WRONG_MAP=0
  39. WRONG_REDUCE=0
  40. File Input Format Counters
  41. Bytes Read=35
  42. File Output Format Counters
  43. Bytes Written=31
  44. [root@master mapreduce]# hadoop fs -ls /output
  45. Found 2 items
  46. -rw-r--r-- 3 root supergroup 0 2023-03-19 18:02 /output/_SUCCESS
  47. -rw-r--r-- 3 root supergroup 31 2023-03-19 18:02 /output/part-r-00000
  48. [root@master mapreduce]# hadoop fs -cat /output/part-r-00000
  49. 2023-03-19 18:03:45,508 INFO sasl.SaslDataTransferClient: SASL encryption trust check: localHostTrusted = false, remoteHostTrusted = false
  50. EOPE 1
  51. HADOOP 1
  52. HELLO 3
  53. JAVA 1
  1. 注意:如果出现一下问题:

  1. Last 4096 bytes of prelaunch.err :
  2. Last 4096 bytes of stderr :
  3. Error: Could not find or load main class org.apache.hadoop.mapreduce.v2.app.MRAppMaster
  4. Please check whether your etc/hadoop/mapred-site.xml contains the below configuration:
  5. <property>
  6. <name>yarn.app.mapreduce.am.env</name>
  7. <value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
  8. </property>
  9. <property>
  10. <name>mapreduce.map.env</name>
  11. <value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
  12. </property>
  13. <property>
  14. <name>mapreduce.reduce.env</name>
  15. <value>HADOOP_MAPRED_HOME=${full path of your hadoop distribution directory}</value>
  16. </property>
  1. 解决方法:

  1. <!-- 输入以下命令回车-->
  2. [root@master mapreduce]# hadoop classpath
  3. //将生成的这堆代码添加至yarn-site.xml中
  4. /opt/module/hadoop/etc/hadoop:/opt/module/hadoop/share/hadoop/common/lib/*:/opt/module/hadoop/share/hadoop/common/*:/opt/module/hadoop/share/hadoop/hdfs:/opt/module/hadoop/share/hadoop/hdfs/lib/*:/opt/module/hadoop/share/hadoop/hdfs/*:/opt/module/hadoop/share/hadoop/mapreduce/lib/*:/opt/module/hadoop/share/hadoop/mapreduce/*:/opt/module/hadoop/share/hadoop/yarn:/opt/module/hadoop/share/hadoop/yarn/lib/*:/opt/module/hadoop/share/hadoop/yarn/*
  5. [root@master hadoop]# vi yarn-site.xml //添加至最后
  6. <property>
  7. <name>yarn.application.classpath</name>
  8. <value>/opt/module/hadoop/etc/hadoop:/opt/module/hadoop/share/hadoop/common/lib/*:/opt/module/hadoop/share/hadoop/common/*:/opt/module/hadoop/share/hadoop/hdfs:/opt/module/hadoop/share/hadoop/hdfs/lib/*:/opt/module/hadoop/share/hadoop/hdfs/*:/opt/module/hadoop/share/hadoop/mapreduce/lib/*:/opt/module/hadoop/share/hadoop/mapreduce/*:/opt/module/hadoop/share/hadoop/yarn:/opt/module/hadoop/share/hadoop/yarn/lib/*:/opt/module/hadoop/share/hadoop/yarn/*
  9. </value>
  10. </property>

《恭喜您搭建成功!》

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/419309
推荐阅读
相关标签
  

闽ICP备14008679号