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