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