hello world
实验一:
1、准备数据:
[root@fcs current]# cd /home/bml
[root@fcs bml]# ls
hadoop hadoop_tmp
[root@fcs bml]# echo "hello world" > words.txt
[root@fcs bml]# ls
hadoop hadoop_tmp words.txt
[root@fcs bml]# cat words.txt
hello world
2、上传数据
[root@fcs hadoop]# bin/hdfs dfs -ls /
Found 1 items
drwxrwx--- - root supergroup 0 2016-12-01 13:54 /tmp
[root@fcs hadoop]# bin/hdfs dfs -mkdir /test
[root@fcs hadoop]# bin/hdfs dfs -ls /
Found 2 items
drwxr-xr-x - root supergroup 0 2016-12-01 14:17 /test
drwxrwx--- - root supergroup 0 2016-12-01 13:54 /tmp
[root@fcs hadoop]# bin/hdfs dfs -put /home/bml/words.txt /test/
[root@fcs hadoop]# bin/hdfs dfs -ls /test/
或者:
[root@fcs bin]# ./hadoop fs -ls /
Found 1 items
-rw-r--r-- 1 root supergroup 12 2016-12-01 14:18 /test/words.txt
[root@fcs hadoop]# bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar wordcount /test/words.txt /test/out
16/12/01 14:20:07 INFO client.RMProxy: Connecting to ResourceManager at localhost/192.168.48.100:8032
16/12/01 14:20:09 INFO input.FileInputFormat: Total input paths to process : 1
16/12/01 14:20:10 INFO mapreduce.JobSubmitter: number of splits:1
16/12/01 14:20:10 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1480572858840_0002
16/12/01 14:20:12 INFO impl.YarnClientImpl: Submitted application application_1480572858840_0002
16/12/01 14:20:12 INFO mapreduce.Job: The url to track the job: http://localhost:8088/proxy/application_1480572858840_0002/
16/12/01 14:20:12 INFO mapreduce.Job: Running job: job_1480572858840_0002
^C
注意:如果卡在这里不动,需要修改
修改mapred-site.xml
<!-- <property>
<name>mapreduce.framework.name</name>
<value>yarn</value>
</property>
-->
<property>
<name>mapred.job.tracker</name>
<value>hdfs://localhost:9001</value>
</property>
[root@fcs hadoop]#
[root@fcs hadoop]# bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar wordcount /test/words.txt /test/out
16/12/01 14:25:52 INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs.metrics.session-id
16/12/01 14:25:52 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
16/12/01 14:25:53 INFO input.FileInputFormat: Total input paths to process : 1
16/12/01 14:25:54 INFO mapreduce.JobSubmitter: number of splits:1
16/12/01 14:25:54 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_local221915253_0001
16/12/01 14:25:55 INFO mapreduce.Job: The url to track the job: http://localhost:8080/
16/12/01 14:25:55 INFO mapreduce.Job: Running job: job_local221915253_0001
16/12/01 14:25:55 INFO mapred.LocalJobRunner: OutputCommitter set in config null
16/12/01 14:25:55 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
16/12/01 14:25:55 INFO mapred.LocalJobRunner: OutputCommitter is org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter
16/12/01 14:25:55 INFO mapred.LocalJobRunner: Waiting for map tasks
16/12/01 14:25:55 INFO mapred.LocalJobRunner: Starting task: attempt_local221915253_0001_m_000000_0
16/12/01 14:25:55 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
16/12/01 14:25:55 INFO mapred.Task: Using ResourceCalculatorProcessTree : [ ]
16/12/01 14:25:55 INFO mapred.MapTask: Processing split: hdfs://localhost:9000/test/words.txt:0+12
16/12/01 14:25:56 INFO mapreduce.Job: Job job_local221915253_0001 running in uber mode : false
16/12/01 14:25:56 INFO mapreduce.Job: map 0% reduce 0%
16/12/01 14:25:56 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584)
16/12/01 14:25:56 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100
16/12/01 14:25:56 INFO mapred.MapTask: soft limit at 83886080
16/12/01 14:25:56 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600
16/12/01 14:25:56 INFO mapred.MapTask: kvstart = 26214396; length = 6553600
16/12/01 14:25:56 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer
16/12/01 14:25:56 INFO mapred.LocalJobRunner:
16/12/01 14:25:56 INFO mapred.MapTask: Starting flush of map output
16/12/01 14:25:56 INFO mapred.MapTask: Spilling map output
16/12/01 14:25:56 INFO mapred.MapTask: bufstart = 0; bufend = 20; bufvoid = 104857600
16/12/01 14:25:56 INFO mapred.MapTask: kvstart = 26214396(104857584); kvend = 26214392(104857568); length = 5/6553600
16/12/01 14:25:56 INFO mapred.MapTask: Finished spill 0
16/12/01 14:25:56 INFO mapred.Task: Task:attempt_local221915253_0001_m_000000_0 is done. And is in the process of committing
16/12/01 14:25:56 INFO mapred.LocalJobRunner: map
16/12/01 14:25:56 INFO mapred.Task: Task 'attempt_local221915253_0001_m_000000_0' done.
16/12/01 14:25:56 INFO mapred.LocalJobRunner: Finishing task: attempt_local221915253_0001_m_000000_0
16/12/01 14:25:56 INFO mapred.LocalJobRunner: map task executor complete.
16/12/01 14:25:56 INFO mapred.LocalJobRunner: Waiting for reduce tasks
16/12/01 14:25:56 INFO mapred.LocalJobRunner: Starting task: attempt_local221915253_0001_r_000000_0
16/12/01 14:25:56 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
16/12/01 14:25:56 INFO mapred.Task: Using ResourceCalculatorProcessTree : [ ]
16/12/01 14:25:56 INFO mapred.ReduceTask: Using ShuffleConsumerPlugin: org.apache.hadoop.mapreduce.task.reduce.Shuffle@7a62cf96
16/12/01 14:25:56 INFO reduce.MergeManagerImpl: MergerManager: memoryLimit=363285696, maxSingleShuffleLimit=90821424, mergeThreshold=239768576, ioSortFactor=10, memToMemMergeOutputsThreshold=10
16/12/01 14:25:56 INFO reduce.EventFetcher: attempt_local221915253_0001_r_000000_0 Thread started: EventFetcher for fetching Map Completion Events
16/12/01 14:25:56 INFO reduce.LocalFetcher: localfetcher#1 about to shuffle output of map attempt_local221915253_0001_m_000000_0 decomp: 26 len: 30 to MEMORY
16/12/01 14:25:57 INFO reduce.InMemoryMapOutput: Read 26 bytes from map-output for attempt_local221915253_0001_m_000000_0
16/12/01 14:25:57 WARN io.ReadaheadPool: Failed readahead on ifile
EBADF: Bad file descriptor
at org.apache.hadoop.io.nativeio.NativeIO$POSIX.posix_fadvise(Native Method)
at org.apache.hadoop.io.nativeio.NativeIO$POSIX.posixFadviseIfPossible(NativeIO.java:267)
at org.apache.hadoop.io.nativeio.NativeIO$POSIX$CacheManipulator.posixFadviseIfPossible(NativeIO.java:146)
at org.apache.hadoop.io.ReadaheadPool$ReadaheadRequestImpl.run(ReadaheadPool.java:206)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
16/12/01 14:25:57 INFO reduce.MergeManagerImpl: closeInMemoryFile -> map-output of size: 26, inMemoryMapOutputs.size() -> 1, commitMemory -> 0, usedMemory ->26
16/12/01 14:25:57 INFO reduce.EventFetcher: EventFetcher is interrupted.. Returning
16/12/01 14:25:57 INFO mapred.LocalJobRunner: 1 / 1 copied.
16/12/01 14:25:57 INFO reduce.MergeManagerImpl: finalMerge called with 1 in-memory map-outputs and 0 on-disk map-outputs
16/12/01 14:25:57 INFO mapred.Merger: Merging 1 sorted segments
16/12/01 14:25:57 INFO mapred.Merger: Down to the last merge-pass, with 1 segments left of total size: 18 bytes
16/12/01 14:25:57 INFO reduce.MergeManagerImpl: Merged 1 segments, 26 bytes to disk to satisfy reduce memory limit
16/12/01 14:25:57 INFO reduce.MergeManagerImpl: Merging 1 files, 30 bytes from disk
16/12/01 14:25:57 INFO reduce.MergeManagerImpl: Merging 0 segments, 0 bytes from memory into reduce
16/12/01 14:25:57 INFO mapred.Merger: Merging 1 sorted segments
16/12/01 14:25:57 INFO mapred.Merger: Down to the last merge-pass, with 1 segments left of total size: 18 bytes
16/12/01 14:25:57 INFO mapred.LocalJobRunner: 1 / 1 copied.
16/12/01 14:25:57 INFO mapreduce.Job: map 100% reduce 0%
16/12/01 14:25:57 INFO Configuration.deprecation: mapred.skip.on is deprecated. Instead, use mapreduce.job.skiprecords
16/12/01 14:25:57 INFO mapred.Task: Task:attempt_local221915253_0001_r_000000_0 is done. And is in the process of committing
16/12/01 14:25:57 INFO mapred.LocalJobRunner: 1 / 1 copied.
16/12/01 14:25:57 INFO mapred.Task: Task attempt_local221915253_0001_r_000000_0 is allowed to commit now
16/12/01 14:25:57 INFO output.FileOutputCommitter: Saved output of task 'attempt_local221915253_0001_r_000000_0' to hdfs://localhost:9000/test/out/_temporary/0/task_local221915253_0001_r_000000
16/12/01 14:25:57 INFO mapred.LocalJobRunner: reduce > reduce
16/12/01 14:25:57 INFO mapred.Task: Task 'attempt_local221915253_0001_r_000000_0' done.
16/12/01 14:25:57 INFO mapred.LocalJobRunner: Finishing task: attempt_local221915253_0001_r_000000_0
16/12/01 14:25:57 INFO mapred.LocalJobRunner: reduce task executor complete.
16/12/01 14:25:58 INFO mapreduce.Job: map 100% reduce 100%
16/12/01 14:25:58 INFO mapreduce.Job: Job job_local221915253_0001 completed successfully
16/12/01 14:25:58 INFO mapreduce.Job: Counters: 35
File System Counters
FILE: Number of bytes read=592038
FILE: Number of bytes written=1162276
FILE: Number of read operations=0
FILE: Number of large read operations=0
FILE: Number of write operations=0
HDFS: Number of bytes read=24
HDFS: Number of bytes written=16
HDFS: Number of read operations=13
HDFS: Number of large read operations=0
HDFS: Number of write operations=4
Map-Reduce Framework
Map input records=1
Map output records=2
Map output bytes=20
Map output materialized bytes=30
Input split bytes=101
Combine input records=2
Combine output records=2
Reduce input groups=2
Reduce shuffle bytes=30
Reduce input records=2
Reduce output records=2
Spilled Records=4
Shuffled Maps =1
Failed Shuffles=0
Merged Map outputs=1
GC time elapsed (ms)=91
Total committed heap usage (bytes)=270671872
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=12
File Output Format Counters
Bytes Written=16
3、查看结果
[root@fcs hadoop]# bin/hdfs dfs -ls /test
Found 2 items
drwxr-xr-x - root supergroup 0 2016-12-01 14:25 /test/out
-rw-r--r-- 1 root supergroup 12 2016-12-01 14:18 /test/words.txt
[root@fcs hadoop]# bin/hdfs dfs -ls /test/out
Found 2 items
-rw-r--r-- 1 root supergroup 0 2016-12-01 14:25 /test/out/_SUCCESS
-rw-r--r-- 1 root supergroup 16 2016-12-01 14:25 /test/out/part-r-00000
[root@fcs hadoop]# bin/hdfs dfs -cat /test/out/part-r-00000
hello 1
world 1
[root@fcs hadoop]#

浙公网安备 33010602011771号