| | 1 | |
| | 2 | {{{ |
| | 3 | #!html |
| | 4 | <div style="text-align: center; color:#151B8D"><big style="font-weight: bold;"><big><big> |
| | 5 | ITRI HBase 進階課程 |
| | 6 | </big></big></big></div> <div style="text-align: center; color:#7E2217"><big style="font-weight: bold;"><big> |
| | 7 | 1. Streaming |
| | 8 | </big></big></div> |
| | 9 | }}} |
| | 10 | |
| | 11 | [wiki:waue/2011/0426 回課程大綱 << ] Stream 範例 |
| | 12 | |
| | 13 | |
| | 14 | == Hadoop Streaming with commands == |
| | 15 | |
| | 16 | * 範例一:使用 cat 當 mapper,使用 wc 當 reducer |
| | 17 | {{{ |
| | 18 | hadoop@lucid:~$ cd /opt/hadoop |
| | 19 | hadoop@lucid:/opt/hadoop$ bin/start-all.sh |
| | 20 | hadoop@lucid:/opt/hadoop$ bin/hadoop fs -put conf input |
| | 21 | hadoop@lucid:/opt/hadoop$ bin/hadoop jar ./contrib/streaming/hadoop-0.20.2-streaming.jar -input input -output output -mapper /bin/cat -reducer /usr/bin/wc |
| | 22 | }}} |
| | 23 | * 範例二:使用 Bash Shell Script 當 Mapper 與 Reducer |
| | 24 | {{{ |
| | 25 | hadoop@lucid:/opt/hadoop$ echo "sed -e \"s/ /\n/g\" | grep ." > streamingMapper.sh |
| | 26 | hadoop@lucid:/opt/hadoop$ echo "uniq -c | awk '{print \$2 \"\t\" \$1}'" > streamingReducer.sh |
| | 27 | hadoop@lucid:/opt/hadoop$ chmod a+x streamingMapper.sh |
| | 28 | hadoop@lucid:/opt/hadoop$ chmod a+x streamingReducer.sh |
| | 29 | hadoop@lucid:/opt/hadoop$ bin/hadoop fs -rmr input output |
| | 30 | hadoop@lucid:/opt/hadoop$ bin/hadoop fs -put conf input |
| | 31 | hadoop@lucid:/opt/hadoop$ bin/hadoop jar ./contrib/streaming/hadoop-0.20.2-streaming.jar -input input -output output -mapper streamingMapper.sh -reducer streamingReducer.sh -file streamingMapper.sh -file streamingReducer.sh |
| | 32 | }}} |