更新时间:2020-07-29。如果hadoop下载链接失效,则需要自行去hadoop官网找下链接
hadoop3.2.1安装
1.下载
https://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/hadoop-3.2.1/hadoop-3.2.1.tar.gz
2.解压
tar -zxvf hadoop-3.2.1.tar.gz
3.重命名
mv hadoop-3.2.1 hadoop
4.添加JAVA_HOME至环境变量
4.1 首先找到JAVA_HOME,执行下面命令,其中有一项是java_home
java -XshowSettings:properties -version
4.2 添加至环境变量
vim /etc/bashrc
# 然后在profile的最下面加一句:
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.252.b09-3.el8_2.x86_64/jre
# 保存退出vim,执行以下命令使环境变量立即生效
source /etc/bashrc
5.hadoop添加至环境变量
# vim /etc/bashrc文件,加入如下两行
export HADOOP_HOME=/usr/share/hadoop
export PATH=$PATH:$HADOOP_HOME/bin
6.测试hadoop。如果显示版本号,则证明成功运行。
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 /usr/share/hadoop/share/hadoop/common/hadoop-common-3.2.1.jar
hdfs配置(伪分布式)
1.创建hadoop用户(专门为hadoop准备的用户),以下操作在root用户下执行
#创建hadoop用户
useradd -m hadoop -s /bin/bash
#修改密码
passwd hadoop
#切换至hadoop用户
su hadoop
#设置ssh免密登录(ssh免密登录自身,如果不设置,启动DFS会报错)
ssh-keygen -t rsa
#将自己生成的公钥加入自己的授权,这样自己就可以免密登录自己
cd ~/.ssh
cat id_rsa.pub >> authorized_keys
chmod 600 authorized_keys # 防止其他用户看到
2.配置core-site.xml
vim /usr/share/hadoop/etc/hadoop/core-site.xml
#加入如下配置(其中使用hadoop代替了ip地址,后续需要在hosts文件内加入对应的ip)
#(存文件的路径最好写到hadoop用户的家目录下,避免权限问题)
<configuration>
<property>
<name>hadoop.tmp.dir</name>
<value>file:/home/hadoop/tmp</value>
<description>Abase for other temporary directories.</description>
</property>
<property>
<name>fs.defaultFS</name>
<value>hdfs://hadoop:9000</value>
</property>
</configuration>
3.配置hdfs-site.xml
vim /usr/share/hadoop/etc/hadoop/hdfs-site.xml
#加入如下配置
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/home/hadoop/tmp/dfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/home/hadoop/tmp/dfs/data</value>
</property>
</configuration>
4.配置yarn-site,xml
vim /usr/share/hadoop/etc/hadoop/yarn-site.xml
#加入如下配置
<configuration>
<property>
<name>yarn.nodemanager.aux-services</name>
<value>mapreduce_shuffle</value>
</property>
<property>
<name>yarn.resourcemanager.hostname</name>
<value>hadoop</value>
</property>
</configuration>
5.配置mapred-site.xml
vim /usr/share/hadoop/etc/hadoop/mapred-site.xml
#加入如下配置
<configuration>
<property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
</configuration>
6.修改hosts文件
su root
vim /etc/hosts
#最下面加入
0.0.0.0 hadoop
7.格式化HDFS系统
su hadoop
/usr/share/hadoop/bin/hdfs namenode -format
8.启动hadoop-DFS
/usr/share/hadoop/sbin/start-dfs.sh
#hadoop: namenode is running as process 25242. Stop it first.
#Starting datanodes
#localhost: datanode is running as process 25402. Stop it first.
#Starting secondary namenodes [hadoop]
#hadoop: secondarynamenode is running as process 25607. Stop it first.
/usr/share/hadoop/sbin/start-yarn.sh
#Starting resourcemanager
#Starting nodemanagers
9.浏览器访问web页面(Centos注意关闭防火墙)
http://<hadoop ip>:9870 #dfs
http://<hadoop ip>:8088 #yarn
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。