在hadoop的mapreduce目录下自带有一个hadoop-mapreduce-examples-2.7.5.jar(官方已经为我们写好了用java实现word count的jar)可以用来测试word count的功能。
- 测试之前先创建用来做词频统计的文件:
[root@hadoop01 ~]# mkdir word_count_input
[root@hadoop01 ~]# cd word_count_input
[root@hadoop01 word_count_input]# vi file1
[root@hadoop01 word_count_input]# cat file1
hello world
welcome to jave world
hadoop mapreduce
[root@hadoop01 word_count_input]# vi file2
[root@hadoop01 word_count_input]# cat file2
java hadoop
hadoop world
hello mapreduce
- 启动hadoop集群
[root@hadoop01 word_count_input]# start-all.sh
- 将这两个文件上传至hdfs
[root@hadoop01 ~]# hdfs dfs -put word_count_input/ /
#这里我将文件上传到了hdfs的根目录