Hadoop2.8第一个案例 运行wordcount

1. 查看hadoop中MapReduce路径

[root@master mapreduce]# pwd
/opt/hadoop/hadoop2.8/share/hadoop/mapreduce

2. 创建word.txt,生成数据文件

touch word.txt
echo "hello world" >> word.txt
echo "hello hadoop" >> word.txt
echo "hello hive" >> word.txt

3. 查看文件

[root@master mapreduce]# ls
hadoop-mapreduce-client-app-2.8.5.jar              hadoop-mapreduce-client-shuffle-2.8.5.jar
hadoop-mapreduce-client-common-2.8.5.jar           hadoop-mapreduce-examples-2.8.5.jar
hadoop-mapreduce-client-core-2.8.5.jar             jdiff
hadoop-mapreduce-client-hs-2.8.5.jar               lib
hadoop-mapreduce-client-hs-plugins-2.8.5.jar       lib-examples
hadoop-mapreduce-client-jobclient-2.8.5.jar        sources
hadoop-mapreduce-client-jobclient-2.8.5-tests.jar  word.txt

4. 创建HDFS目录

hdfs dfs -mkdir /work/data/input

5. 将数据文件word.txt上传到HDFS /work/data/input 目录下

hdfs dfs -put ./word.txt /work/data/input

6. 以文本形式读出文件

[root@master mapreduce]# hdfs dfs -text /work/data/input/word.txt
hello world
hello hadoop
hello hive

7. 运行wordcount例子

[root@master mapreduce]# hadoop jar hadoop-mapreduce-examples-2.8.5.jar wordcount /work/data/input /work/data/output

8. 查看结果

[root@master mapreduce]# hdfs dfs -ls /work/data/output
Found 2 items
-rw-r--r--   2 root supergroup          0 2019-03-01 19:36 /work/data/output/_SUCCESS
-rw-r--r--   2 root supergroup         32 2019-03-01 19:36 /work/data/output/part-r-00000

[root@master mapreduce]# hdfs dfs -text /work/data/output/part-r-00000
hadoop	1
hello	3
hive	1
world	1
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值