| 1 | {{{ |
| 2 | #!html |
| 3 | <div style="text-align: center;"><big |
| 4 | style="font-weight: bold;"><big><big>實做三、執行 MapReduce 基本運算</big></big></big></div> |
| 5 | }}} |
| 6 | [[PageOutline]] |
| 7 | |
| 8 | = 1 Hadoop運算命令 grep = |
| 9 | |
| 10 | * grep 這個命令是擷取文件裡面特定的字元,在Hadoop example中此指令可以擷取文件中有此指定文字的字串,並作計數統計 |
| 11 | |
| 12 | {{{ |
| 13 | $ cd /opt/hadoop |
| 14 | $ bin/hadoop fs -put conf lab3_input |
| 15 | $ bin/hadoop fs -ls lab3_input |
| 16 | $ bin/hadoop jar hadoop-*-examples.jar grep lab3_input lab3_out1 'dfs[a-z.]+' |
| 17 | |
| 18 | }}} |
| 19 | |
| 20 | 運作的畫面如下: |
| 21 | |
| 22 | {{{ |
| 23 | |
| 24 | 09/03/24 12:33:45 INFO mapred.FileInputFormat: Total input paths to process : 9 |
| 25 | 09/03/24 12:33:45 INFO mapred.FileInputFormat: Total input paths to process : 9 |
| 26 | 09/03/24 12:33:45 INFO mapred.JobClient: Running job: job_200903232025_0003 |
| 27 | 09/03/24 12:33:46 INFO mapred.JobClient: map 0% reduce 0% |
| 28 | 09/03/24 12:33:47 INFO mapred.JobClient: map 10% reduce 0% |
| 29 | 09/03/24 12:33:49 INFO mapred.JobClient: map 20% reduce 0% |
| 30 | 09/03/24 12:33:51 INFO mapred.JobClient: map 30% reduce 0% |
| 31 | 09/03/24 12:33:52 INFO mapred.JobClient: map 40% reduce 0% |
| 32 | 09/03/24 12:33:54 INFO mapred.JobClient: map 50% reduce 0% |
| 33 | 09/03/24 12:33:55 INFO mapred.JobClient: map 60% reduce 0% |
| 34 | 09/03/24 12:33:57 INFO mapred.JobClient: map 70% reduce 0% |
| 35 | 09/03/24 12:33:59 INFO mapred.JobClient: map 80% reduce 0% |
| 36 | 09/03/24 12:34:00 INFO mapred.JobClient: map 90% reduce 0% |
| 37 | 09/03/24 12:34:02 INFO mapred.JobClient: map 100% reduce 0% |
| 38 | 09/03/24 12:34:10 INFO mapred.JobClient: map 100% reduce 10% |
| 39 | 09/03/24 12:34:12 INFO mapred.JobClient: map 100% reduce 13% |
| 40 | 09/03/24 12:34:15 INFO mapred.JobClient: map 100% reduce 20% |
| 41 | 09/03/24 12:34:20 INFO mapred.JobClient: map 100% reduce 23% |
| 42 | 09/03/24 12:34:22 INFO mapred.JobClient: Job complete: job_200903232025_0003 |
| 43 | 09/03/24 12:34:22 INFO mapred.JobClient: Counters: 16 |
| 44 | 09/03/24 12:34:22 INFO mapred.JobClient: File Systems |
| 45 | 09/03/24 12:34:22 INFO mapred.JobClient: HDFS bytes read=48245 |
| 46 | 09/03/24 12:34:22 INFO mapred.JobClient: HDFS bytes written=1907 |
| 47 | 09/03/24 12:34:22 INFO mapred.JobClient: Local bytes read=1549 |
| 48 | 09/03/24 12:34:22 INFO mapred.JobClient: Local bytes written=3584 |
| 49 | 09/03/24 12:34:22 INFO mapred.JobClient: Job Counters |
| 50 | ...... |
| 51 | }}} |
| 52 | |
| 53 | |
| 54 | * 接著查看結果 |
| 55 | |
| 56 | {{{ |
| 57 | $ bin/hadoop fs -ls lab3_out1 |
| 58 | $ bin/hadoop fs -cat lab3_out1/part-00000 |
| 59 | }}} |
| 60 | |
| 61 | 結果如下 |
| 62 | |
| 63 | {{{ |
| 64 | 3 dfs.class |
| 65 | 3 dfs. |
| 66 | 2 dfs.period |
| 67 | 1 dfs.http.address |
| 68 | 1 dfs.balance.bandwidth |
| 69 | 1 dfs.block.size |
| 70 | 1 dfs.blockreport.initial |
| 71 | 1 dfs.blockreport.interval |
| 72 | 1 dfs.client.block.write.retries |
| 73 | 1 dfs.client.buffer.dir |
| 74 | 1 dfs.data.dir |
| 75 | 1 dfs.datanode.address |
| 76 | 1 dfs.datanode.dns.interface |
| 77 | 1 dfs.datanode.dns.nameserver |
| 78 | 1 dfs.datanode.du.pct |
| 79 | 1 dfs.datanode.du.reserved |
| 80 | 1 dfs.datanode.handler.count |
| 81 | 1 dfs.datanode.http.address |
| 82 | 1 dfs.datanode.https.address |
| 83 | 1 dfs.datanode.ipc.address |
| 84 | 1 dfs.default.chunk.view.size |
| 85 | 1 dfs.df.interval |
| 86 | 1 dfs.file |
| 87 | 1 dfs.heartbeat.interval |
| 88 | 1 dfs.hosts |
| 89 | 1 dfs.hosts.exclude |
| 90 | 1 dfs.https.address |
| 91 | 1 dfs.impl |
| 92 | 1 dfs.max.objects |
| 93 | 1 dfs.name.dir |
| 94 | 1 dfs.namenode.decommission.interval |
| 95 | 1 dfs.namenode.decommission.interval. |
| 96 | 1 dfs.namenode.decommission.nodes.per.interval |
| 97 | 1 dfs.namenode.handler.count |
| 98 | 1 dfs.namenode.logging.level |
| 99 | 1 dfs.permissions |
| 100 | 1 dfs.permissions.supergroup |
| 101 | 1 dfs.replication |
| 102 | 1 dfs.replication.consider |
| 103 | 1 dfs.replication.interval |
| 104 | 1 dfs.replication.max |
| 105 | 1 dfs.replication.min |
| 106 | 1 dfs.replication.min. |
| 107 | 1 dfs.safemode.extension |
| 108 | 1 dfs.safemode.threshold.pct |
| 109 | 1 dfs.secondary.http.address |
| 110 | 1 dfs.servers |
| 111 | 1 dfs.web.ugi |
| 112 | 1 dfsmetrics.log |
| 113 | |
| 114 | }}} |
| 115 | |
| 116 | = 2 Hadoop運算命令 WordCount = |
| 117 | |
| 118 | * 如名稱,WordCount會對所有的字作字數統計,並且從a-z作排列 |
| 119 | |
| 120 | {{{ |
| 121 | /opt/hadoop$ bin/hadoop jar hadoop-*-examples.jar wordcount lab3_input lab3_out2 |
| 122 | }}} |
| 123 | |
| 124 | 檢查輸出結果的方法同之前方法 |
| 125 | |
| 126 | {{{ |
| 127 | $ bin/hadoop fs -ls lab3_out2 |
| 128 | $ bin/hadoop fs -cat lab3_out2/part-00000 |
| 129 | }}} |
| 130 | |
| 131 | = 3. 使用網頁Gui瀏覽資訊 = |
| 132 | |
| 133 | * [http://localhost:50030 透過 Map/Reduce Admin 來察看程序運作狀態] |
| 134 | |
| 135 | * [http://localhost:50070 透過 NameNode 察看運算結果] |
| 136 | |
| 137 | = 4. 更多運算命令 = |
| 138 | |
| 139 | 可執行的指令一覽表: |
| 140 | |
| 141 | || aggregatewordcount || An Aggregate based map/reduce program that counts the words in the input files. || |
| 142 | || aggregatewordhist || An Aggregate based map/reduce program that computes the histogram of the words in the input files. || |
| 143 | || grep || A map/reduce program that counts the matches of a regex in the input. || |
| 144 | || join || A job that effects a join over sorted, equally partitioned datasets || |
| 145 | || multifilewc || A job that counts words from several files. || |
| 146 | || pentomino || A map/reduce tile laying program to find solutions to pentomino problems. || |
| 147 | || pi || A map/reduce program that estimates Pi using monte-carlo method. || |
| 148 | || randomtextwriter || A map/reduce program that writes 10GB of random textual data per node. || |
| 149 | || randomwriter || A map/reduce program that writes 10GB of random data per node. || |
| 150 | || sleep || A job that sleeps at each map and reduce task. || |
| 151 | || sort || A map/reduce program that sorts the data written by the random writer. || |
| 152 | || sudoku || A sudoku solver. || |
| 153 | || wordcount || A map/reduce program that counts the words in the input files. || |
| 154 | |
| 155 | 請參考 [http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/examples/package-summary.html org.apache.hadoop.examples] |