Mac上にHadoopを試しに触ってみるための環境を構築する手順


## インストール
### brewでインストール

```console
brew install hadoop
```

### 確認

```console
which hadoop

(結果)
/usr/local/bin/hadoop
```

### 実行してみる

* ワードカウントをやってみる。ファイルを用意。

``` console
mkdir -p /Users/Shared/Workspace.d/Hadoop/test
cd /Users/Shared/Workspace.d/Hadoop/test

mkdir input

echo 'a a b b b c b c' > input/a.txt
echo 'ab a b b c c c'  > input/b.txt
```

* 処理実行

``` console
hadoop jar /usr/local/opt/hadoop/libexec/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount input output

(結果)

16/07/30 00:49:54 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
16/07/30 00:49:55 INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs.metrics.session-id
16/07/30 00:49:55 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
16/07/30 00:49:55 INFO input.FileInputFormat: Total input paths to process : 2
16/07/30 00:49:55 INFO mapreduce.JobSubmitter: number of splits:2
16/07/30 00:49:55 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_local1757251676_0001
16/07/30 00:49:55 INFO mapreduce.Job: The url to track the job: http://localhost:8080/
16/07/30 00:49:55 INFO mapreduce.Job: Running job: job_local1757251676_0001
16/07/30 00:49:55 INFO mapred.LocalJobRunner: OutputCommitter set in config null
16/07/30 00:49:55 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
16/07/30 00:49:55 INFO mapred.LocalJobRunner: OutputCommitter is org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter
16/07/30 00:49:56 INFO mapred.LocalJobRunner: Waiting for map tasks
16/07/30 00:49:56 INFO mapred.LocalJobRunner: Starting task: attempt_local1757251676_0001_m_000000_0
16/07/30 00:49:56 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
16/07/30 00:49:56 INFO util.ProcfsBasedProcessTree: ProcfsBasedProcessTree currently is supported only on Linux.
16/07/30 00:49:56 INFO mapred.Task:  Using ResourceCalculatorProcessTree : null
16/07/30 00:49:56 INFO mapred.MapTask: Processing split: file:/Users/Shared/Workspace.d/Hadoop/test/input/a.txt:0+16
16/07/30 00:49:56 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584)
16/07/30 00:49:56 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100
16/07/30 00:49:56 INFO mapred.MapTask: soft limit at 83886080
16/07/30 00:49:56 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600
16/07/30 00:49:56 INFO mapred.MapTask: kvstart = 26214396; length = 6553600
16/07/30 00:49:56 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer
16/07/30 00:49:56 INFO mapred.LocalJobRunner:
16/07/30 00:49:56 INFO mapred.MapTask: Starting flush of map output
16/07/30 00:49:56 INFO mapred.MapTask: Spilling map output
16/07/30 00:49:56 INFO mapred.MapTask: bufstart = 0; bufend = 48; bufvoid = 104857600
16/07/30 00:49:56 INFO mapred.MapTask: kvstart = 26214396(104857584); kvend = 26214368(104857472); length = 29/6553600
16/07/30 00:49:56 INFO mapred.MapTask: Finished spill 0
16/07/30 00:49:56 INFO mapred.Task: Task:attempt_local1757251676_0001_m_000000_0 is done. And is in the process of committing
16/07/30 00:49:56 INFO mapred.LocalJobRunner: map
16/07/30 00:49:56 INFO mapred.Task: Task 'attempt_local1757251676_0001_m_000000_0' done.
16/07/30 00:49:56 INFO mapred.LocalJobRunner: Finishing task: attempt_local1757251676_0001_m_000000_0
16/07/30 00:49:56 INFO mapred.LocalJobRunner: Starting task: attempt_local1757251676_0001_m_000001_0
16/07/30 00:49:56 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
16/07/30 00:49:56 INFO util.ProcfsBasedProcessTree: ProcfsBasedProcessTree currently is supported only on Linux.
16/07/30 00:49:56 INFO mapred.Task:  Using ResourceCalculatorProcessTree : null
16/07/30 00:49:56 INFO mapred.MapTask: Processing split: file:/Users/Shared/Workspace.d/Hadoop/test/input/b.txt:0+15
16/07/30 00:49:56 INFO mapred.MapTask: (EQUATOR) 0 kvi 26214396(104857584)
16/07/30 00:49:56 INFO mapred.MapTask: mapreduce.task.io.sort.mb: 100
16/07/30 00:49:56 INFO mapred.MapTask: soft limit at 83886080
16/07/30 00:49:56 INFO mapred.MapTask: bufstart = 0; bufvoid = 104857600
16/07/30 00:49:56 INFO mapred.MapTask: kvstart = 26214396; length = 6553600
16/07/30 00:49:56 INFO mapred.MapTask: Map output collector class = org.apache.hadoop.mapred.MapTask$MapOutputBuffer
16/07/30 00:49:56 INFO mapred.LocalJobRunner:
16/07/30 00:49:56 INFO mapred.MapTask: Starting flush of map output
16/07/30 00:49:56 INFO mapred.MapTask: Spilling map output
16/07/30 00:49:56 INFO mapred.MapTask: bufstart = 0; bufend = 43; bufvoid = 104857600
16/07/30 00:49:56 INFO mapred.MapTask: kvstart = 26214396(104857584); kvend = 26214372(104857488); length = 25/6553600
16/07/30 00:49:56 INFO mapred.MapTask: Finished spill 0
16/07/30 00:49:56 INFO mapred.Task: Task:attempt_local1757251676_0001_m_000001_0 is done. And is in the process of committing
16/07/30 00:49:56 INFO mapred.LocalJobRunner: map
16/07/30 00:49:56 INFO mapred.Task: Task 'attempt_local1757251676_0001_m_000001_0' done.
16/07/30 00:49:56 INFO mapred.LocalJobRunner: Finishing task: attempt_local1757251676_0001_m_000001_0
16/07/30 00:49:56 INFO mapred.LocalJobRunner: map task executor complete.
16/07/30 00:49:56 INFO mapred.LocalJobRunner: Waiting for reduce tasks
16/07/30 00:49:56 INFO mapred.LocalJobRunner: Starting task: attempt_local1757251676_0001_r_000000_0
16/07/30 00:49:56 INFO output.FileOutputCommitter: File Output Committer Algorithm version is 1
16/07/30 00:49:56 INFO util.ProcfsBasedProcessTree: ProcfsBasedProcessTree currently is supported only on Linux.
16/07/30 00:49:56 INFO mapred.Task:  Using ResourceCalculatorProcessTree : null
16/07/30 00:49:56 INFO mapred.ReduceTask: Using ShuffleConsumerPlugin: org.apache.hadoop.mapreduce.task.reduce.Shuffle@5ca3d4c1
16/07/30 00:49:56 INFO reduce.MergeManagerImpl: MergerManager: memoryLimit=334338464, maxSingleShuffleLimit=83584616, mergeThreshold=220663392, ioSortFactor=10, memToMemMergeOutputsThreshold=10
16/07/30 00:49:56 INFO reduce.EventFetcher: attempt_local1757251676_0001_r_000000_0 Thread started: EventFetcher for fetching Map Completion Events
16/07/30 00:49:56 INFO reduce.LocalFetcher: localfetcher#1 about to shuffle output of map attempt_local1757251676_0001_m_000001_0 decomp: 35 len: 39 to MEMORY
16/07/30 00:49:56 INFO reduce.InMemoryMapOutput: Read 35 bytes from map-output for attempt_local1757251676_0001_m_000001_0
16/07/30 00:49:56 INFO reduce.MergeManagerImpl: closeInMemoryFile -> map-output of size: 35, inMemoryMapOutputs.size() -> 1, commitMemory -> 0, usedMemory ->35
16/07/30 00:49:56 INFO reduce.LocalFetcher: localfetcher#1 about to shuffle output of map attempt_local1757251676_0001_m_000000_0 decomp: 26 len: 30 to MEMORY
16/07/30 00:49:56 INFO reduce.InMemoryMapOutput: Read 26 bytes from map-output for attempt_local1757251676_0001_m_000000_0
16/07/30 00:49:56 INFO reduce.MergeManagerImpl: closeInMemoryFile -> map-output of size: 26, inMemoryMapOutputs.size() -> 2, commitMemory -> 35, usedMemory ->61
16/07/30 00:49:56 INFO reduce.EventFetcher: EventFetcher is interrupted.. Returning
16/07/30 00:49:56 INFO mapred.LocalJobRunner: 2 / 2 copied.
16/07/30 00:49:56 INFO reduce.MergeManagerImpl: finalMerge called with 2 in-memory map-outputs and 0 on-disk map-outputs
16/07/30 00:49:56 INFO mapred.Merger: Merging 2 sorted segments
16/07/30 00:49:56 INFO mapred.Merger: Down to the last merge-pass, with 2 segments left of total size: 53 bytes
16/07/30 00:49:56 INFO reduce.MergeManagerImpl: Merged 2 segments, 61 bytes to disk to satisfy reduce memory limit
16/07/30 00:49:56 INFO reduce.MergeManagerImpl: Merging 1 files, 63 bytes from disk
16/07/30 00:49:56 INFO reduce.MergeManagerImpl: Merging 0 segments, 0 bytes from memory into reduce
16/07/30 00:49:56 INFO mapred.Merger: Merging 1 sorted segments
16/07/30 00:49:56 INFO mapred.Merger: Down to the last merge-pass, with 1 segments left of total size: 55 bytes
16/07/30 00:49:56 INFO mapred.LocalJobRunner: 2 / 2 copied.
16/07/30 00:49:56 INFO Configuration.deprecation: mapred.skip.on is deprecated. Instead, use mapreduce.job.skiprecords
16/07/30 00:49:56 INFO mapred.Task: Task:attempt_local1757251676_0001_r_000000_0 is done. And is in the process of committing
16/07/30 00:49:56 INFO mapred.LocalJobRunner: 2 / 2 copied.
16/07/30 00:49:56 INFO mapred.Task: Task attempt_local1757251676_0001_r_000000_0 is allowed to commit now
16/07/30 00:49:56 INFO output.FileOutputCommitter: Saved output of task 'attempt_local1757251676_0001_r_000000_0' to file:/Users/Shared/Workspace.d/Hadoop/test/output/_temporary/0/task_local1757251676_0001_r_000000
16/07/30 00:49:56 INFO mapred.LocalJobRunner: reduce > reduce
16/07/30 00:49:56 INFO mapred.Task: Task 'attempt_local1757251676_0001_r_000000_0' done.
16/07/30 00:49:56 INFO mapred.LocalJobRunner: Finishing task: attempt_local1757251676_0001_r_000000_0
16/07/30 00:49:56 INFO mapred.LocalJobRunner: reduce task executor complete.
16/07/30 00:49:56 INFO mapreduce.Job: Job job_local1757251676_0001 running in uber mode : false
16/07/30 00:49:56 INFO mapreduce.Job:  map 100% reduce 100%
16/07/30 00:49:57 INFO mapreduce.Job: Job job_local1757251676_0001 completed successfully
16/07/30 00:49:57 INFO mapreduce.Job: Counters: 30
	File System Counters
		FILE: Number of bytes read=822011
		FILE: Number of bytes written=1676439
		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=2
		Map output records=15
		Map output bytes=91
		Map output materialized bytes=69
		Input split bytes=238
		Combine input records=15
		Combine output records=7
		Reduce input groups=4
		Reduce shuffle bytes=69
		Reduce input records=7
		Reduce output records=4
		Spilled Records=14
		Shuffled Maps =2
		Failed Shuffles=0
		Merged Map outputs=2
		GC time elapsed (ms)=0
		Total committed heap usage (bytes)=1016070144
	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=31
	File Output Format Counters
		Bytes Written=29
```

* 処理結果

```console
tree

.
├── input
│   ├── a.txt
│   └── b.txt
└── output
    ├── _SUCCESS
    └── part-r-00000

2 directories, 4 files
```

```console
cat output/part-r-00000

a	3
ab	1
b	6
c	5
```