Hadoop入门---(wordcount)统计单词出现的次数

wordcount

1、创建输入文件目录

在hadoop安装目录下创建wcinput目录,如我的安装目录是:/opt/module/hadoop-2.7.7

[root@hadoop101 hadoop-2.7.7]# pwd
/opt/module/hadoop-2.7.7
[root@hadoop101 hadoop-2.7.7]# 
[root@hadoop101 hadoop-2.7.7]# 
[root@hadoop101 hadoop-2.7.7]# mkdir wcinput

2、创建数据源

[root@hadoop101 wcinput]# pwd
/opt/module/hadoop-2.7.7/wcinput
[root@hadoop101 wcinput]# 
[root@hadoop101 wcinput]# 
[root@hadoop101 wcinput]# touch wc.input

3、输入一些数据

[root@hadoop101 wcinput]# cat wc.input 
zhangsan lisi wangwu zhaosi
hh
shendu
zhenghui
aiyou
shendu
zhenghui
[root@hadoop101 wcinput]# 
[root@hadoop101 wcinput]# 

统计数据

hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.7.jar wordcount wcinput/ wcoutput

[root@hadoop101 ~]# cd /opt/module/hadoop-2.7.7/
[root@hadoop101 hadoop-2.7.7]# 
[root@hadoop101 hadoop-2.7.7]# hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.7.jar wordcount wcinput/ wcoutput
19/10/03 12:46:22 INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs.metrics.session-id
19/10/03 12:46:22 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
19/10/03 12:46:23 INFO input.FileInputFormat: Total input paths to process : 1
19/10/03 12:46:23 INFO mapreduce.JobSubmitter: number of splits:1
19/10/03 12:46:23 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_local1891222959_0001
19/10/03 12:46:23 INFO mapreduce.Job: The url to track the job: http://localhost:8080/
19/10/03 12:46:23 INFO mapreduce.Job: Running job: job_local1891222959_0001
19/10/03 12:46:23 INFO mapred.LocalJobRunner: OutputCommitter set in config null
19/10/03 12:46:23 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
19/10/03 12:46:23 INFO mapred.LocalJobRunner: OutputCommitter is org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter
19/10/03 12:46:23 INFO mapred.LocalJobRunner: Waiting for map tasks
19/10/03 12:46:23 INFO mapred.LocalJobRunner: Starting task: attempt_local1891222959_0001_m_000000_0
19/10/03 12:46:23 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
19/10/03 12:46:23 INFO mapred.Task:  Using ResourceCalculatorProcessTree : [ ]
19/10/03 12:46:23 INFO mapred.MapTask: Processing split: file:/opt/module/hadoop-2.7.7/wcinput/wc.input:0+69
19/10/03 12:46:23 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584)
19/10/03 12:46:23 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100
19/10/03 12:46:23 INFO mapred.MapTask: soft limit at 83886080
19/10/03 12:46:23 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600
19/10/03 12:46:23 INFO mapred.MapTask: kvstart = 26214396; length = 6553600
19/10/03 12:46:23 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer
19/10/03 12:46:23 INFO mapred.LocalJobRunner: 
19/10/03 12:46:23 INFO mapred.MapTask: Starting flush of map output
19/10/03 12:46:23 INFO mapred.MapTask: Spilling map output
19/10/03 12:46:23 INFO mapred.MapTask: bufstart = 0; bufend = 109; bufvoid = 104857600
19/10/03 12:46:23 INFO mapred.MapTask: kvstart = 26214396(104857584); kvend = 26214360(104857440); length = 37/6553600
19/10/03 12:46:23 INFO mapred.MapTask: Finished spill 0
19/10/03 12:46:23 INFO mapred.Task: Task:attempt_local1891222959_0001_m_000000_0 is done. And is in the process of committing
19/10/03 12:46:23 INFO mapred.LocalJobRunner: map
19/10/03 12:46:23 INFO mapred.Task: Task 'attempt_local1891222959_0001_m_000000_0' done.
19/10/03 12:46:23 INFO mapred.Task: Final Counters for attempt_local1891222959_0001_m_000000_0: Counters: 18
        File System Counters
                FILE: Number of bytes read=296278
                FILE: Number of bytes written=589524
                FILE: Number of read operations=0
                FILE: Number of large read operations=0
                FILE: Number of write operations=0
        Map-Reduce Framework
                Map input records=7
                Map output records=10
                Map output bytes=109
                Map output materialized bytes=107
                Input split bytes=111
                Combine input records=10
                Combine output records=8
                Spilled Records=8
                Failed Shuffles=0
                Merged Map outputs=0
                GC time elapsed (ms)=0
                Total committed heap usage (bytes)=197132288
        File Input Format Counters 
                Bytes Read=69
19/10/03 12:46:23 INFO mapred.LocalJobRunner: Finishing task: attempt_local1891222959_0001_m_000000_0
19/10/03 12:46:23 INFO mapred.LocalJobRunner: map task executor complete.
19/10/03 12:46:23 INFO mapred.LocalJobRunner: Waiting for reduce tasks
19/10/03 12:46:23 INFO mapred.LocalJobRunner: Starting task: attempt_local1891222959_0001_r_000000_0
19/10/03 12:46:23 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
19/10/03 12:46:23 INFO mapred.Task:  Using ResourceCalculatorProcessTree : [ ]
19/10/03 12:46:23 INFO mapred.ReduceTask: Using ShuffleConsumerPlugin: org.apache.hadoop.mapreduce.task.reduce.Shuffle@c5d1342
19/10/03 12:46:23 INFO reduce.MergeManagerImpl: MergerManager: memoryLimit=334338464, maxSingleShuffleLimit=83584616, mergeThreshold=220663392, ioSortFactor=10, memToMemMergeOutputsThreshold=10
19/10/03 12:46:23 INFO reduce.EventFetcher: attempt_local1891222959_0001_r_000000_0 Thread started: EventFetcher for fetching Map Completion Events
19/10/03 12:46:23 INFO reduce.LocalFetcher: localfetcher#1 about to shuffle output of map attempt_local1891222959_0001_m_000000_0 decomp: 103 len: 107 to MEMORY
19/10/03 12:46:23 INFO reduce.InMemoryMapOutput: Read 103 bytes from map-output for attempt_local1891222959_0001_m_000000_0
19/10/03 12:46:23 INFO reduce.MergeManagerImpl: closeInMemoryFile -> map-output of size: 103, inMemoryMapOutputs.size() -> 1, commitMemory -> 0, usedMemory ->103
19/10/03 12:46:23 INFO reduce.EventFetcher: EventFetcher is interrupted.. Returning
19/10/03 12:46:23 INFO mapred.LocalJobRunner: 1 / 1 copied.
19/10/03 12:46:23 INFO reduce.MergeManagerImpl: finalMerge called with 1 in-memory map-outputs and 0 on-disk map-outputs
19/10/03 12:46:23 INFO mapred.Merger: Merging 1 sorted segments
19/10/03 12:46:23 INFO mapred.Merger: Down to the last merge-pass, with 1 segments left of total size: 95 bytes
19/10/03 12:46:23 INFO reduce.MergeManagerImpl: Merged 1 segments, 103 bytes to disk to satisfy reduce memory limit
19/10/03 12:46:23 INFO reduce.MergeManagerImpl: Merging 1 files, 107 bytes from disk
19/10/03 12:46:23 INFO reduce.MergeManagerImpl: Merging 0 segments, 0 bytes from memory into reduce
19/10/03 12:46:23 INFO mapred.Merger: Merging 1 sorted segments
19/10/03 12:46:23 INFO mapred.Merger: Down to the last merge-pass, with 1 segments left of total size: 95 bytes
19/10/03 12:46:23 INFO mapred.LocalJobRunner: 1 / 1 copied.
19/10/03 12:46:23 INFO Configuration.deprecation: mapred.skip.on is deprecated. Instead, use mapreduce.job.skiprecords
19/10/03 12:46:23 INFO mapred.Task: Task:attempt_local1891222959_0001_r_000000_0 is done. And is in the process of committing
19/10/03 12:46:23 INFO mapred.LocalJobRunner: 1 / 1 copied.
19/10/03 12:46:23 INFO mapred.Task: Task attempt_local1891222959_0001_r_000000_0 is allowed to commit now
19/10/03 12:46:23 INFO output.FileOutputCommitter: Saved output of task 'attempt_local1891222959_0001_r_000000_0' to file:/opt/module/hadoop-2.7.7/wcoutput/_temporary/0/task_local1891222959_0001_r_000000
19/10/03 12:46:23 INFO mapred.LocalJobRunner: reduce > reduce
19/10/03 12:46:23 INFO mapred.Task: Task 'attempt_local1891222959_0001_r_000000_0' done.
19/10/03 12:46:23 INFO mapred.Task: Final Counters for attempt_local1891222959_0001_r_000000_0: Counters: 24
        File System Counters
                FILE: Number of bytes read=296524
                FILE: Number of bytes written=589712
                FILE: Number of read operations=0
                FILE: Number of large read operations=0
                FILE: Number of write operations=0
        Map-Reduce Framework
                Combine input records=0
                Combine output records=0
                Reduce input groups=8
                Reduce shuffle bytes=107
                Reduce input records=8
                Reduce output records=8
                Spilled Records=8
                Shuffled Maps =1
                Failed Shuffles=0
                Merged Map outputs=1
                GC time elapsed (ms)=0
                Total committed heap usage (bytes)=197132288
        Shuffle Errors
                BAD_ID=0
                CONNECTION=0
                IO_ERROR=0
                WRONG_LENGTH=0
                WRONG_MAP=0
                WRONG_REDUCE=0
        File Output Format Counters 
                Bytes Written=81
19/10/03 12:46:23 INFO mapred.LocalJobRunner: Finishing task: attempt_local1891222959_0001_r_000000_0
19/10/03 12:46:23 INFO mapred.LocalJobRunner: reduce task executor complete.
19/10/03 12:46:24 INFO mapreduce.Job: Job job_local1891222959_0001 running in uber mode : false
19/10/03 12:46:24 INFO mapreduce.Job:  map 100% reduce 100%
19/10/03 12:46:24 INFO mapreduce.Job: Job job_local1891222959_0001 completed successfully
19/10/03 12:46:24 INFO mapreduce.Job: Counters: 30
        File System Counters
                FILE: Number of bytes read=592802
                FILE: Number of bytes written=1179236
                FILE: Number of read operations=0
                FILE: Number of large read operations=0
                FILE: Number of write operations=0
        Map-Reduce Framework
                Map input records=7
                Map output records=10
                Map output bytes=109
                Map output materialized bytes=107
                Input split bytes=111
                Combine input records=10
                Combine output records=8
                Reduce input groups=8
                Reduce shuffle bytes=107
                Reduce input records=8
                Reduce output records=8
                Spilled Records=16
                Shuffled Maps =1
                Failed Shuffles=0
                Merged Map outputs=1
                GC time elapsed (ms)=0
                Total committed heap usage (bytes)=394264576
        Shuffle Errors
                BAD_ID=0
                CONNECTION=0
                IO_ERROR=0
                WRONG_LENGTH=0
                WRONG_MAP=0
                WRONG_REDUCE=0
        File Input Format Counters 
                Bytes Read=69
        File Output Format Counters 
                Bytes Written=81
[root@hadoop101 hadoop-2.7.7]# 

查看统计结果

[root@hadoop101 hadoop-2.7.7]# cat wcoutput/part-r-00000 
aiyou   1
hh      1
lisi    1
shendu  2
wangwu  1
zhangsan        1
zhaosi  1
zhenghui        2
[root@hadoop101 hadoop-2.7.7]# 
[root@hadoop101 hadoop-2.7.7]# 
发布了79 篇原创文章 · 获赞 70 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_17623363/article/details/101986398