这里安装的是1.8.0_211
版本
各版本的Hadoop安装包下载地址:http://archive.apache.org/dist/hadoop/common/
这里选择2.7.2
。
mkdir /home/hadoop
cd /home/hadoop
wget http://archive.apache.org/dist/hadoop/common/hadoop-2.7.2/hadoop-2.7.2.tar.gz
tar -zxvf hadoop-2.7.2.tar.gz
cd hadoop-2.7.2
vim /etc/profile
# 在最后面增加如下两行代码
export HADOOP_HOME=/home/hadoop/hadoop-2.7.2
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
# 保存退出
source /etc/profile
vim etc/hadopp/hadoop-env.sh
然后修改export JAVA_HOME=${JAVA_HOME}
为export JAVA_HOME=/home/java/jdk1.8.0_211
vim etc/hadopp/yarn-env.sh
然后将# export JAVA_HOME=/home/y/libexec/jdk1.6.0
为export JAVA_HOME=/home/java/jdk1.8.0_211
vim etc/hadoop/mapred-env.sh
然后将# export JAVA_HOME=/home/y/libexec/jdk1.6.0
为export JAVA_HOME=/home/java/jdk1.8.0_211
此模式下都是使用的本地目录
mkdir input
cp etc/hadoop/*.xml input
./bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar grep input output 'dfs[a-z.]+'
cat output/*
# 输出结果
1 dfsadmin
mkdir wcinput
vim wcinput/wc.input
# 下面为文件内容
# a b
# b c
./bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount wcinput wcoutput
cat wcoutput/*
# 输出结果
a 1
b 2
c 1
d 1
<configuration>
<property>
<name>fs.defaultFSname>
<value>hdfs://hostname:9000value>
property>
<property>
<name>hadoop.tmp.dirname>
<value>/home/hadoop/hadoop-2.7.2/data/tmpvalue>
property>
configuration>
<configuration>
<property>
<name>dfs.replicationname>
<value>1value>
property>
configuration>
<configuration>
<property>
<name>yarn.nodemanager.aux-servicesname>
<value>mapreduce_shufflevalue>
property>
<property>
<name>yarn.resourcemanager.hostnamename>
<value>nightwatchvalue>
property>
configuration>
cp mapred-site.xml.template mapred-site.xml
<configuration>
<property>
<name>mapreduce.framework.namename>
<value>yarnvalue>
property>
configuration>
# 格式化namenode,只有首次启动namenode需要
# 如果再次格式话则会导致datanode启动失败,则需要删除/home/hadoop/hadoop-2.7.2/data/tmp/data目录内容
bin/hdfs namenode -format
# 启动namenode
hadoop-daemon.sh start namenode
# 启动datanode
hadoop-daemon.sh start datanode
# 查看启动进程
jps
# 输出结果
2844 Jps
1327 DataNode
1247 NameNode
启动完成之后,可以进入http://hostname:50070/
,查看是否启动成功
# 启动resource manager
yarn-daemon.sh start resourcemanager
# 启动node manager
yarn-daemon.sh start nodemanager
# 查看启动进程
jps
# 输出结果
2012 NodeManager
2844 Jps
1774 ResourceManager
1327 DataNode
1247 NameNode
启动完成之后,可以进入http://hostname:8088/cluster/nodes
,然后点击node
# 将本地文件上传至hdfs根目录下
hadoop fs -put wcinput /
# 查看是否上传成功
hdfs dfs -ls /
# 运行jar包
./bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /wcinput /wcoutput
# 查看运行结果
hdfs dfs -cat /wcoutput/*