RedHat 安装Hadoop并运行wordcount例子

Posted LionheartCGJ

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RedHat 安装Hadoop并运行wordcount例子相关的知识,希望对你有一定的参考价值。

1.安装 Red Hat 环境

2.安装JDK

3.下载hadoop2.8.0 

  http://mirrors.tuna.tsinghua.edu.cn/apache/hadoop/common/hadoop-2.8.0/hadoop-2.8.0.tar.gz

 

4.在用户目录下新建hadoop文件夹,并解压hadoop压缩包

  mkdir Hadoop

  tar -zxvf hadoop-2.8.0.tar.gz

5.为hadoop配置JAVA_HOME

[xxx@localhost ~]$ cd hadoop/hadoop-2.8.0/etc/hadoop/
[xxx@localhost hadoop]$ vi hadoop-env.sh 

6.格式化(初始化)HDFS文件系统

[xxx@localhost ~]$ cd hadoop/hadoop-2.8.0/bin
[xxx@localhost bin]$ ./hadoop namenode -format

  (ps:hadoop namenode -format 已经过时 hdfs namenode -format 最新的需要等待较长时间)

7.启动haddop

[xxx@localhost ~]$ cd hadoop/hadoop-2.8.0/sbin/
[xxx@localhost sbin]$ ./start-all.sh

  (ps:现在推荐使用 ./start-hdfs.sh ./start-yarn.sh)

8.jps查看hadoop是否成功启动

9.在hadoop目录里下新建文件夹并新建两个测试文件

[xxx@localhost ~]$ cd hadoop/
[xxx@localhost hadoop]$ mkdir test
[xxx@localhost hadoop]$ cd test/
[xxx@localhost test]$ echo "hello word" > file1.txt
[xxx@localhost test]$ echo "hello hadoop" > file2.txt

10.在hdfs文件系统里新建input文件夹并将测试文件上传

[xxx@localhost ~]$ cd hadoop/hadoop-2.8.0/bin/
[xxx@localhost bin]$ ./hadoop fs -mkdir input
[xxx@localhost bin]$ ./hadoop fs -put ~/hadoop/test/file*.txt input
17/07/06 16:33:34 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
[xxx@localhost bin]$ ./hadoop fs -ls input
17/07/06 16:33:45 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Found 2 items
-rw-r--r--   1 chenguangjin chenguangjin         11 2017-07-06 16:33 input/file1.txt
-rw-r--r--   1 chenguangjin chenguangjin         13 2017-07-06 16:33 input/file2.txt

  (ps:注意此处由WARN,不需要管它,可以成功上传)

11.运行wordcount小例子

[xxx@localhost bin]$ ./hadoop jar ~/hadoop/hadoop-2.8.0/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.8.0.jar  wordcount input output

12.查看结果

[xxx@localhost bin]$ ./hadoop fs -text output/part-r-00000
17/07/06 16:46:02 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
hadoop    1
hello    2
word    1
[xxx@localhost bin]$ 

 

(over怎么样是不是还挺有趣的)

 

以上是关于RedHat 安装Hadoop并运行wordcount例子的主要内容,如果未能解决你的问题,请参考以下文章

Hadoop3.1.3单机版安装Hive3.1.2(Redhat8.0)

Redhat hadoop2.7.2安装笔记

在Redhat8.0上安装Hadoop3.1.3单机版

centos7 yum安装java运行环境,初识hadoop

使用shell脚本的Hadoop流:reducer因错误而失败:没有这样的文件或目录

hadoop+hbase伪分布式之hadoop安装