hadoop 2.7.3本地环境运行官方wordcount

基本环境:

系统:win7

虚机环境:virtualBox

虚机:centos 7

hadoop版本:2.7.3

本次先以独立模式(本地模式)来运行。

参考:

1 hadoop 安装

java环境

<code>yum install java-1.8.0-openjdk<br/>
</code>

hadoop下载压缩包并安装

<code>mkdir ~/hadoop/<br/>
cd ~/hadoop/

# http://apache.fayea.com/hadoop/common/hadoop-2.7.3/<br/>
curl http://apache.fayea.com/apache/hadoop/common/hadoop-2.7.3/hadoop-2.7.3.tar.gz -O<br/>
# 如果下载出现中断,则可以使用-C参数继续下载

ls -l<br/>
#-rw-rw-r--. 1 jungle jungle 165297920 Jan  6 13:10 hadoop-2.7.3.tar.gz

curl http://apache.fayea.com/apache/hadoop/common/hadoop-2.7.3/hadoop-2.7.3.tar.gz -C 165297920 -O<br/>
# ** Resuming transfer from byte position 165297920 ……

# download checksum<br/>
curl http://apache.fayea.com/hadoop/core/hadoop-2.7.3/hadoop-2.7.3.tar.gz.mds -O

# check<br/>
cat hadoop-2.7.3.tar.gz.mds

md5sum hadoop-2.7.3.tar.gz<br/>
sha256sum hadoop-2.7.3.tar.gz

tar -zxf hadoop-2.7.3.tar.gz<br/>
mv hadoop-2.7.3 hadoop-local<br/>
</code>

2 配置环境

因为是使用本地模式,需要配置的项非常少,只需要涉及环境变量。

<code># java path<br/>
whereis java<br/>
java: /usr/bin/java /usr/lib/java /etc/java /usr/share/java 

ls -l /usr/bin/java<br/>
lrwxrwxrwx. 1 root root 22 Dec 30 12:26 /usr/bin/java -> /etc/alternatives/java

ls -l /etc/alternatives/java<br/>
lrwxrwxrwx. 1 root root 73 Dec 30 12:26 /etc/alternatives/java -> /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre/bin/java<br/>
</code>

在~/.bashrc中增加如下三行

<code>export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.111-2.b15.el7_3.x86_64/jre<br/>
export HADOOP_INSTALL=/home/jungle/hadoop/hadoop-local<br/>
export PATH=$PATH:$HADOOP_INSTALL/bin:$HADOOP_INSTALL/sbin<br/>
</code>

确认hadoop可用:

<code>hadoop version<br/>
Hadoop 2.7.3<br/>
Subversion https://git-wip-us.apache.org/repos/asf/hadoop.git -r baa91f7c6bc9cb92be5982de4719c1c8af91ccff<br/>
Compiled by root on 2016-08-18T01:41Z<br/>
Compiled with protoc 2.5.0<br/>
From source with checksum 2e4ce5f957ea4db193bce3734ff29ff4<br/>
This command was run using /home/jungle/hadoop/hadoop-local/share/hadoop/common/hadoop-common-2.7.3.jar<br/>
</code>

2 使用linux文件系统做测试

直接使用linux的文件系统做测试,即不使用hadoop fs相关命令。

2.1 wordcount

<code>bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar<br/>
An example program must be given as the first argument.<br/>
Valid program names are:<br/>
  aggregatewordcount: An Aggregate based map/reduce program that counts the words in the input files.<br/>
  aggregatewordhist: An Aggregate based map/reduce program that computes the histogram of the words in the input files.<br/>
  bbp: A map/reduce program that uses Bailey-Borwein-Plouffe to compute exact digits of Pi.<br/>
  dbcount: An example job that count the pageview counts from a database.<br/>
# ...<br/>
  wordcount: A map/reduce program that counts the words in the input files.<br/>
# ...

bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar  wordcount<br/>
# Usage: wordcount <in> [<in>...] <out><br/>
</code>

2.2 准备数据

<code>mkdir -p dataLocal/input/<br/>
cd dataLocal/input/

echo "hello world, I am jungle. bye world" > file1.txt<br/>
echo "hello hadoop. hello jungle. bye hadoop." > file2.txt<br/>
echo "the great software is hadoop." >> file2.txt

</code>

2.3 运行

<code>cd /home/jungle/hadoop/hadoop-local/

hadoop jar /home/jungle/hadoop/hadoop-local/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.3.jar wordcount  dataLocal/input/ dataLocal/outout<br/>
# dataLocal/outout 当前不存在,由程序生成<br/>
echo $?

ls -la dataLocal/outout/<br/>
total 12<br/>
drwxrwxr-x. 2 jungle jungle 84 Jan  6 16:53 .<br/>
drwxrwxr-x. 4 jungle jungle 31 Jan  6 16:53 ..<br/>
-rw-r--r--. 1 jungle jungle 82 Jan  6 16:53 part-r-00000<br/>
-rw-r--r--. 1 jungle jungle 12 Jan  6 16:53 .part-r-00000.crc<br/>
-rw-r--r--. 1 jungle jungle  0 Jan  6 16:53 _SUCCESS<br/>
-rw-r--r--. 1 jungle jungle  8 Jan  6 16:53 ._SUCCESS.crc

# 结果<br/>
cat dataLocal/outout//part-r-00000<br/>
I	1<br/>
am	1<br/>
bye	2<br/>
great	1<br/>
hadoop.	3<br/>
hello	3<br/>
is	1<br/>
jungle.	2<br/>
software	1<br/>
the	1<br/>
world.	2

</code>

2.4 最后是运行日志

通过日志,可以了解运行时的一些常用参数和配置。

<code>17/01/06 16:53:26 INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs.metrics.session-id<br/>
17/01/06 16:53:26 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=<br/>
17/01/06 16:53:26 INFO input.FileInputFormat: Total input paths to process : 2<br/>
17/01/06 16:53:26 INFO mapreduce.JobSubmitter: number of splits:2<br/>
17/01/06 16:53:27 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_local1147390429_0001<br/>
17/01/06 16:53:27 INFO mapreduce.Job: The url to track the job: http://localhost:8080/<br/>
17/01/06 16:53:27 INFO mapreduce.Job: Running job: job_local1147390429_0001<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: OutputCommitter set in config null<br/>
17/01/06 16:53:27 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: OutputCommitter is org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: Waiting for map tasks<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: Starting task: attempt_local1147390429_0001_m_000000_0<br/>
17/01/06 16:53:27 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1<br/>
17/01/06 16:53:27 INFO mapred.Task:  Using ResourceCalculatorProcessTree : [ ]<br/>
17/01/06 16:53:27 INFO mapred.MapTask: Processing split: file:/home/jungle/hadoop/hadoop-local/dataLocal/input/file2.txt:0+70<br/>
17/01/06 16:53:27 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584)<br/>
17/01/06 16:53:27 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100<br/>
17/01/06 16:53:27 INFO mapred.MapTask: soft limit at 83886080<br/>
17/01/06 16:53:27 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600<br/>
17/01/06 16:53:27 INFO mapred.MapTask: kvstart = 26214396; length = 6553600<br/>
17/01/06 16:53:27 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner:<br/>
17/01/06 16:53:27 INFO mapred.MapTask: Starting flush of map output<br/>
17/01/06 16:53:27 INFO mapred.MapTask: Spilling map output<br/>
17/01/06 16:53:27 INFO mapred.MapTask: bufstart = 0; bufend = 114; bufvoid = 104857600<br/>
17/01/06 16:53:27 INFO mapred.MapTask: kvstart = 26214396(104857584); kvend = 26214356(104857424); length = 41/6553600<br/>
17/01/06 16:53:27 INFO mapred.MapTask: Finished spill 0<br/>
17/01/06 16:53:27 INFO mapred.Task: Task:attempt_local1147390429_0001_m_000000_0 is done. And is in the process of committing<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: map<br/>
17/01/06 16:53:27 INFO mapred.Task: Task 'attempt_local1147390429_0001_m_000000_0' done.<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: Finishing task: attempt_local1147390429_0001_m_000000_0<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: Starting task: attempt_local1147390429_0001_m_000001_0<br/>
17/01/06 16:53:27 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1<br/>
17/01/06 16:53:27 INFO mapred.Task:  Using ResourceCalculatorProcessTree : [ ]<br/>
17/01/06 16:53:27 INFO mapred.MapTask: Processing split: file:/home/jungle/hadoop/hadoop-local/dataLocal/input/file1.txt:0+37<br/>
17/01/06 16:53:27 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584)<br/>
17/01/06 16:53:27 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100<br/>
17/01/06 16:53:27 INFO mapred.MapTask: soft limit at 83886080<br/>
17/01/06 16:53:27 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600<br/>
17/01/06 16:53:27 INFO mapred.MapTask: kvstart = 26214396; length = 6553600<br/>
17/01/06 16:53:27 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner:<br/>
17/01/06 16:53:27 INFO mapred.MapTask: Starting flush of map output<br/>
17/01/06 16:53:27 INFO mapred.MapTask: Spilling map output<br/>
17/01/06 16:53:27 INFO mapred.MapTask: bufstart = 0; bufend = 65; bufvoid = 104857600<br/>
17/01/06 16:53:27 INFO mapred.MapTask: kvstart = 26214396(104857584); kvend = 26214372(104857488); length = 25/6553600<br/>
17/01/06 16:53:27 INFO mapred.MapTask: Finished spill 0<br/>
17/01/06 16:53:27 INFO mapred.Task: Task:attempt_local1147390429_0001_m_000001_0 is done. And is in the process of committing<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: map<br/>
17/01/06 16:53:27 INFO mapred.Task: Task 'attempt_local1147390429_0001_m_000001_0' done.<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: Finishing task: attempt_local1147390429_0001_m_000001_0<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: map task executor complete.<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: Waiting for reduce tasks<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: Starting task: attempt_local1147390429_0001_r_000000_0<br/>
17/01/06 16:53:27 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1<br/>
17/01/06 16:53:27 INFO mapred.Task:  Using ResourceCalculatorProcessTree : [ ]<br/>
17/01/06 16:53:27 INFO mapred.ReduceTask: Using ShuffleConsumerPlugin: org.apache.hadoop.mapreduce.task.reduce.Shuffle@2aa26fdb<br/>
17/01/06 16:53:27 INFO reduce.MergeManagerImpl: MergerManager: memoryLimit=363285696, maxSingleShuffleLimit=90821424, mergeThreshold=239768576, ioSortFactor=10, memToMemMergeOutputsThreshold=10<br/>
17/01/06 16:53:27 INFO reduce.EventFetcher: attempt_local1147390429_0001_r_000000_0 Thread started: EventFetcher for fetching Map Completion Events<br/>
17/01/06 16:53:27 INFO reduce.LocalFetcher: localfetcher#1 about to shuffle output of map attempt_local1147390429_0001_m_000000_0 decomp: 98 len: 102 to MEMORY<br/>
17/01/06 16:53:27 INFO reduce.InMemoryMapOutput: Read 98 bytes from map-output for attempt_local1147390429_0001_m_000000_0<br/>
17/01/06 16:53:27 INFO reduce.MergeManagerImpl: closeInMemoryFile -> map-output of size: 98, inMemoryMapOutputs.size() -> 1, commitMemory -> 0, usedMemory ->98<br/>
17/01/06 16:53:27 INFO reduce.LocalFetcher: localfetcher#1 about to shuffle output of map attempt_local1147390429_0001_m_000001_0 decomp: 68 len: 72 to MEMORY

17/01/06 16:53:27 WARN io.ReadaheadPool: Failed readahead on ifile<br/>
EBADF: Bad file descriptor<br/>
	at org.apache.hadoop.io.nativeio.NativeIO$POSIX.posix_fadvise(Native Method)<br/>
	at org.apache.hadoop.io.nativeio.NativeIO$POSIX.posixFadviseIfPossible(NativeIO.java:267)<br/>
	at org.apache.hadoop.io.nativeio.NativeIO$POSIX$CacheManipulator.posixFadviseIfPossible(NativeIO.java:146)<br/>
	at org.apache.hadoop.io.ReadaheadPool$ReadaheadRequestImpl.run(ReadaheadPool.java:206)<br/>
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)<br/>
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)<br/>
	at java.lang.Thread.run(Thread.java:745)

17/01/06 16:53:27 INFO reduce.InMemoryMapOutput: Read 68 bytes from map-output for attempt_local1147390429_0001_m_000001_0<br/>
17/01/06 16:53:27 INFO reduce.MergeManagerImpl: closeInMemoryFile -> map-output of size: 68, inMemoryMapOutputs.size() -> 2, commitMemory -> 98, usedMemory ->166<br/>
17/01/06 16:53:27 INFO reduce.EventFetcher: EventFetcher is interrupted.. Returning

17/01/06 16:53:27 WARN io.ReadaheadPool: Failed readahead on ifile<br/>
EBADF: Bad file descriptor<br/>
	at org.apache.hadoop.io.nativeio.NativeIO$POSIX.posix_fadvise(Native Method)<br/>
	at org.apache.hadoop.io.nativeio.NativeIO$POSIX.posixFadviseIfPossible(NativeIO.java:267)<br/>
	at org.apache.hadoop.io.nativeio.NativeIO$POSIX$CacheManipulator.posixFadviseIfPossible(NativeIO.java:146)<br/>
	at org.apache.hadoop.io.ReadaheadPool$ReadaheadRequestImpl.run(ReadaheadPool.java:206)<br/>
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)<br/>
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)<br/>
	at java.lang.Thread.run(Thread.java:745)

17/01/06 16:53:27 INFO mapred.LocalJobRunner: 2 / 2 copied.<br/>
17/01/06 16:53:27 INFO reduce.MergeManagerImpl: finalMerge called with 2 in-memory map-outputs and 0 on-disk map-outputs<br/>
17/01/06 16:53:27 INFO mapred.Merger: Merging 2 sorted segments<br/>
17/01/06 16:53:27 INFO mapred.Merger: Down to the last merge-pass, with 2 segments left of total size: 156 bytes<br/>
17/01/06 16:53:27 INFO reduce.MergeManagerImpl: Merged 2 segments, 166 bytes to disk to satisfy reduce memory limit<br/>
17/01/06 16:53:27 INFO reduce.MergeManagerImpl: Merging 1 files, 168 bytes from disk<br/>
17/01/06 16:53:27 INFO reduce.MergeManagerImpl: Merging 0 segments, 0 bytes from memory into reduce<br/>
17/01/06 16:53:27 INFO mapred.Merger: Merging 1 sorted segments<br/>
17/01/06 16:53:27 INFO mapred.Merger: Down to the last merge-pass, with 1 segments left of total size: 160 bytes<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: 2 / 2 copied.<br/>
17/01/06 16:53:27 INFO Configuration.deprecation: mapred.skip.on is deprecated. Instead, use mapreduce.job.skiprecords<br/>
17/01/06 16:53:27 INFO mapred.Task: Task:attempt_local1147390429_0001_r_000000_0 is done. And is in the process of committing<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: 2 / 2 copied.<br/>
17/01/06 16:53:27 INFO mapred.Task: Task attempt_local1147390429_0001_r_000000_0 is allowed to commit now<br/>
17/01/06 16:53:27 INFO output.FileOutputCommitter: Saved output of task 'attempt_local1147390429_0001_r_000000_0' to file:/home/jungle/hadoop/hadoop-local/dataLocal/outout/_temporary/0/task_local1147390429_0001_r_000000<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: reduce > reduce<br/>
17/01/06 16:53:27 INFO mapred.Task: Task 'attempt_local1147390429_0001_r_000000_0' done.<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: Finishing task: attempt_local1147390429_0001_r_000000_0<br/>
17/01/06 16:53:27 INFO mapred.LocalJobRunner: reduce task executor complete.<br/>
17/01/06 16:53:28 INFO mapreduce.Job: Job job_local1147390429_0001 running in uber mode : false<br/>
17/01/06 16:53:28 INFO mapreduce.Job:  map 100% reduce 100%<br/>
17/01/06 16:53:28 INFO mapreduce.Job: Job job_local1147390429_0001 completed successfully<br/>
17/01/06 16:53:28 INFO mapreduce.Job: Counters: 30<br/>
	File System Counters<br/>
		FILE: Number of bytes read=889648<br/>
		FILE: Number of bytes written=1748828<br/>
		FILE: Number of read operations=0<br/>
		FILE: Number of large read operations=0<br/>
		FILE: Number of write operations=0<br/>
	Map-Reduce Framework<br/>
		Map input records=3<br/>
		Map output records=18<br/>
		Map output bytes=179<br/>
		Map output materialized bytes=174<br/>
		Input split bytes=256<br/>
		Combine input records=18<br/>
		Combine output records=14<br/>
		Reduce input groups=11<br/>
		Reduce shuffle bytes=174<br/>
		Reduce input records=14<br/>
		Reduce output records=11<br/>
		Spilled Records=28<br/>
		Shuffled Maps =2<br/>
		Failed Shuffles=0<br/>
		Merged Map outputs=2<br/>
		GC time elapsed (ms)=43<br/>
		Total committed heap usage (bytes)=457912320<br/>
	Shuffle Errors<br/>
		BAD_ID=0<br/>
		CONNECTION=0<br/>
		IO_ERROR=0<br/>
		WRONG_LENGTH=0<br/>
		WRONG_MAP=0<br/>
		WRONG_REDUCE=0<br/>
	File Input Format Counters<br/>
		Bytes Read=107<br/>
	File Output Format Counters<br/>
		Bytes Written=94<br/>
</code>