| | 26 | * 下載 |
| | 27 | {{{ |
| | 28 | /opt/hadoop$ bin/hadoop fs -get input fromHDFS |
| | 29 | }}} |
| | 30 | * 檢查 |
| | 31 | {{{ |
| | 32 | /opt/hadoop$ ls -al | grep fromHDFS |
| | 33 | /opt/hadoop$ ls -al fromHDFS |
| | 34 | }}} |
| | 35 | |
| | 36 | === 1.4 刪除檔案 === |
| | 37 | {{{ |
| | 38 | /opt/hadoop$ bin/hadoop fs -ls input |
| | 39 | /opt/hadoop$ bin/hadoop fs -rm input/masters |
| | 40 | }}} |
| | 41 | === 1.5 直接看檔案 === |
| | 42 | {{{ |
| | 43 | /opt/hadoop$ bin/hadoop fs -ls input |
| | 44 | /opt/hadoop$ bin/hadoop fs -cat input/slaves |
| | 45 | }}} |
| | 46 | |
| | 47 | === 1.6 更多指令操作 === |
| | 48 | {{{ |
| | 49 | hadooper@vPro:/opt/hadoop$ bin/hadoop fs |
| | 50 | |
| | 51 | Usage: java FsShell |
| | 52 | |
| | 53 | [-ls <path>] |
| | 54 | |
| | 55 | [-lsr <path>] |
| | 56 | |
| | 57 | [-du <path>] |
| | 58 | |
| | 59 | [-dus <path>] |
| | 60 | |
| | 61 | [-count[-q] <path>] |
| | 62 | |
| | 63 | [-mv <src> <dst>] |
| | 64 | |
| | 65 | [-cp <src> <dst>] |
| | 66 | |
| | 67 | [-rm <path>] |
| | 68 | |
| | 69 | [-rmr <path>] |
| | 70 | |
| | 71 | [-expunge] |
| | 72 | |
| | 73 | [-put <localsrc> ... <dst>] |
| | 74 | |
| | 75 | [-copyFromLocal <localsrc> ... <dst>] |
| | 76 | |
| | 77 | [-moveFromLocal <localsrc> ... <dst>] |
| | 78 | |
| | 79 | [-get [-ignoreCrc] [-crc] <src> <localdst>] |
| | 80 | |
| | 81 | [-getmerge <src> <localdst> [addnl]] |
| | 82 | |
| | 83 | [-cat <src>] |
| | 84 | |
| | 85 | [-text <src>] |
| | 86 | |
| | 87 | [-copyToLocal [-ignoreCrc] [-crc] <src> <localdst>] |
| | 88 | |
| | 89 | [-moveToLocal [-crc] <src> <localdst>] |
| | 90 | |
| | 91 | [-mkdir <path>] |
| | 92 | |
| | 93 | [-setrep [-R] [-w] <rep> <path/file>] |
| | 94 | |
| | 95 | [-touchz <path>] |
| | 96 | |
| | 97 | [-test -[ezd] <path>] |
| | 98 | |
| | 99 | [-stat [format] <path>] |
| | 100 | |
| | 101 | [-tail [-f] <file>] |
| | 102 | |
| | 103 | [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...] |
| | 104 | |
| | 105 | [-chown [-R] [OWNER][:[GROUP]] PATH...] |
| | 106 | |
| | 107 | [-chgrp [-R] GROUP PATH...] |
| | 108 | |
| | 109 | [-help [cmd]] |
| | 110 | |
| | 111 | |
| | 112 | |
| | 113 | Generic options supported are |
| | 114 | |
| | 115 | -conf <configuration file> specify an application configuration file |
| | 116 | |
| | 117 | -D <property=value> use value for given property |
| | 118 | |
| | 119 | -fs <local|namenode:port> specify a namenode |
| | 120 | |
| | 121 | -jt <local|jobtracker:port> specify a job tracker |
| | 122 | |
| | 123 | -files <comma separated list of files> specify comma separated files to be copied to the map reduce cluster |
| | 124 | |
| | 125 | -libjars <comma separated list of jars> specify comma separated jar files to include in the classpath. |
| | 126 | |
| | 127 | -archives <comma separated list of archives> specify comma separated archives to be unarchived on the compute machines. |
| | 128 | |
| | 129 | |
| | 130 | |
| | 131 | The general command line syntax is |
| | 132 | |
| | 133 | bin/hadoop command [genericOptions] [commandOptions] |
| | 134 | |
| | 135 | |
| | 136 | }}} |
| | 146 | * grep 這個命令是擷取文件裡面特定的字元,在Hadoop example中此指令可以擷取文件中有此指定文字的字串,並作計數統計 |
| | 147 | |
| | 148 | {{{ |
| | 149 | /opt/hadoop$ bin/hadoop jar hadoop-*-examples.jar grep input grep_output 'dfs[a-z.]+' |
| | 150 | }}} |
| | 151 | |
| | 152 | 運作的畫面如下: |
| | 153 | |
| | 154 | {{{ |
| | 155 | 09/03/24 12:33:45 INFO mapred.FileInputFormat: Total input paths to process : 9 |
| | 156 | |
| | 157 | 09/03/24 12:33:45 INFO mapred.FileInputFormat: Total input paths to process : 9 |
| | 158 | |
| | 159 | 09/03/24 12:33:45 INFO mapred.JobClient: Running job: job_200903232025_0003 |
| | 160 | |
| | 161 | 09/03/24 12:33:46 INFO mapred.JobClient: map 0% reduce 0% |
| | 162 | |
| | 163 | 09/03/24 12:33:47 INFO mapred.JobClient: map 10% reduce 0% |
| | 164 | |
| | 165 | 09/03/24 12:33:49 INFO mapred.JobClient: map 20% reduce 0% |
| | 166 | |
| | 167 | 09/03/24 12:33:51 INFO mapred.JobClient: map 30% reduce 0% |
| | 168 | |
| | 169 | 09/03/24 12:33:52 INFO mapred.JobClient: map 40% reduce 0% |
| | 170 | |
| | 171 | 09/03/24 12:33:54 INFO mapred.JobClient: map 50% reduce 0% |
| | 172 | |
| | 173 | 09/03/24 12:33:55 INFO mapred.JobClient: map 60% reduce 0% |
| | 174 | |
| | 175 | 09/03/24 12:33:57 INFO mapred.JobClient: map 70% reduce 0% |
| | 176 | |
| | 177 | 09/03/24 12:33:59 INFO mapred.JobClient: map 80% reduce 0% |
| | 178 | |
| | 179 | 09/03/24 12:34:00 INFO mapred.JobClient: map 90% reduce 0% |
| | 180 | |
| | 181 | 09/03/24 12:34:02 INFO mapred.JobClient: map 100% reduce 0% |
| | 182 | |
| | 183 | 09/03/24 12:34:10 INFO mapred.JobClient: map 100% reduce 10% |
| | 184 | |
| | 185 | 09/03/24 12:34:12 INFO mapred.JobClient: map 100% reduce 13% |
| | 186 | |
| | 187 | 09/03/24 12:34:15 INFO mapred.JobClient: map 100% reduce 20% |
| | 188 | |
| | 189 | 09/03/24 12:34:20 INFO mapred.JobClient: map 100% reduce 23% |
| | 190 | |
| | 191 | 09/03/24 12:34:22 INFO mapred.JobClient: Job complete: job_200903232025_0003 |
| | 192 | |
| | 193 | 09/03/24 12:34:22 INFO mapred.JobClient: Counters: 16 |
| | 194 | |
| | 195 | 09/03/24 12:34:22 INFO mapred.JobClient: File Systems |
| | 196 | |
| | 197 | 09/03/24 12:34:22 INFO mapred.JobClient: HDFS bytes read=48245 |
| | 198 | |
| | 199 | 09/03/24 12:34:22 INFO mapred.JobClient: HDFS bytes written=1907 |
| | 200 | |
| | 201 | 09/03/24 12:34:22 INFO mapred.JobClient: Local bytes read=1549 |
| | 202 | |
| | 203 | 09/03/24 12:34:22 INFO mapred.JobClient: Local bytes written=3584 |
| | 204 | |
| | 205 | 09/03/24 12:34:22 INFO mapred.JobClient: Job Counters |
| | 206 | |
| | 207 | ...... |
| | 208 | }}} |
| | 209 | |
| | 210 | * 接著查看結果 |
| | 211 | {{{ |
| | 212 | /opt/hadoop$ bin/hadoop fs -ls grep_output |
| | 213 | /opt/hadoop$ bin/hadoop fs -cat grep_output/part-00000 |
| | 214 | }}} |
| | 215 | 結果如下 |
| | 216 | {{{ |
| | 217 | |
| | 218 | 3 dfs.class |
| | 219 | |
| | 220 | 3 dfs. |
| | 221 | |
| | 222 | 2 dfs.period |
| | 223 | |
| | 224 | 1 dfs.http.address |
| | 225 | |
| | 226 | 1 dfs.balance.bandwidth |
| | 227 | |
| | 228 | 1 dfs.block.size |
| | 229 | |
| | 230 | 1 dfs.blockreport.initial |
| | 231 | |
| | 232 | 1 dfs.blockreport.interval |
| | 233 | |
| | 234 | 1 dfs.client.block.write.retries |
| | 235 | |
| | 236 | 1 dfs.client.buffer.dir |
| | 237 | |
| | 238 | 1 dfs.data.dir |
| | 239 | |
| | 240 | 1 dfs.datanode.address |
| | 241 | |
| | 242 | 1 dfs.datanode.dns.interface |
| | 243 | |
| | 244 | 1 dfs.datanode.dns.nameserver |
| | 245 | |
| | 246 | 1 dfs.datanode.du.pct |
| | 247 | |
| | 248 | 1 dfs.datanode.du.reserved |
| | 249 | |
| | 250 | 1 dfs.datanode.handler.count |
| | 251 | |
| | 252 | 1 dfs.datanode.http.address |
| | 253 | |
| | 254 | 1 dfs.datanode.https.address |
| | 255 | |
| | 256 | 1 dfs.datanode.ipc.address |
| | 257 | |
| | 258 | 1 dfs.default.chunk.view.size |
| | 259 | |
| | 260 | 1 dfs.df.interval |
| | 261 | |
| | 262 | 1 dfs.file |
| | 263 | |
| | 264 | 1 dfs.heartbeat.interval |
| | 265 | |
| | 266 | 1 dfs.hosts |
| | 267 | |
| | 268 | 1 dfs.hosts.exclude |
| | 269 | |
| | 270 | 1 dfs.https.address |
| | 271 | |
| | 272 | 1 dfs.impl |
| | 273 | |
| | 274 | 1 dfs.max.objects |
| | 275 | |
| | 276 | 1 dfs.name.dir |
| | 277 | |
| | 278 | 1 dfs.namenode.decommission.interval |
| | 279 | |
| | 280 | 1 dfs.namenode.decommission.interval. |
| | 281 | |
| | 282 | 1 dfs.namenode.decommission.nodes.per.interval |
| | 283 | |
| | 284 | 1 dfs.namenode.handler.count |
| | 285 | |
| | 286 | 1 dfs.namenode.logging.level |
| | 287 | |
| | 288 | 1 dfs.permissions |
| | 289 | |
| | 290 | 1 dfs.permissions.supergroup |
| | 291 | |
| | 292 | 1 dfs.replication |
| | 293 | |
| | 294 | 1 dfs.replication.consider |
| | 295 | |
| | 296 | 1 dfs.replication.interval |
| | 297 | |
| | 298 | 1 dfs.replication.max |
| | 299 | |
| | 300 | 1 dfs.replication.min |
| | 301 | |
| | 302 | 1 dfs.replication.min. |
| | 303 | |
| | 304 | 1 dfs.safemode.extension |
| | 305 | |
| | 306 | 1 dfs.safemode.threshold.pct |
| | 307 | |
| | 308 | 1 dfs.secondary.http.address |
| | 309 | |
| | 310 | 1 dfs.servers |
| | 311 | |
| | 312 | 1 dfs.web.ugi |
| | 313 | |
| | 314 | 1 dfsmetrics.log |
| | 315 | |
| | 316 | |
| | 317 | }}} |
| 44 | | |
| 45 | | |
| 46 | | |
| 47 | | == Content 3. 使用網頁Gui瀏覽訊息 == |
| 48 | | |
| 49 | | |
| 50 | | == 練習 == |
| 51 | | |
| 52 | | |
| | 347 | |
| | 348 | {{{ |
| | 349 | #!html |
| | 350 | <html lang="zh-tw"><head> |
| | 351 | |
| | 352 | <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>a.html</title> |
| | 353 | |
| | 354 | </head><body> |
| | 355 | <br> |
| | 356 | |
| | 357 | <p> |
| | 358 | </p><table summary="" border="1" cellpadding="3" cellspacing="0" width="100%"> |
| | 359 | <tbody><tr class="TableHeadingColor" bgcolor="#ccccff"> |
| | 360 | <th colspan="2" align="left"><font size="+2"> |
| | 361 | <b>Class Summary</b></font></th> |
| | 362 | </tr> |
| | 363 | <tr class="TableRowColor" bgcolor="white"> |
| | 364 | |
| | 365 | <td width="15%"><b><a href="http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/examples/AggregateWordCount.html" title="class in org.apache.hadoop.examples">AggregateWordCount</a></b></td> |
| | 366 | <td>This is an example Aggregated Hadoop Map/Reduce application. It |
| | 367 | reads the text input files, breaks each line into words and counts |
| | 368 | them. The output is a locally sorted list of words and the count of how |
| | 369 | often they occurred. To run: bin/hadoop jar hadoop-*-examples.jar |
| | 370 | aggregatewordcount in-dir out-dir numOfReducers textinputformat </td> |
| | 371 | </tr> |
| | 372 | <tr class="TableRowColor" bgcolor="white"> |
| | 373 | <td width="15%"><b><a href="http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/examples/AggregateWordHistogram.html" title="class in org.apache.hadoop.examples">AggregateWordHistogram</a></b></td> |
| | 374 | <td>This is an example Aggregated Hadoop Map/Reduce application. |
| | 375 | Computes the histogram of the words in the input texts. To run: |
| | 376 | bin/hadoop jar hadoop-*-examples.jar aggregatewordhist in-dir out-dir |
| | 377 | numOfReducers textinputformat </td> |
| | 378 | </tr> |
| | 379 | <tr class="TableRowColor" bgcolor="white"> |
| | 380 | <td width="15%"><b><a href="http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/examples/ExampleDriver.html" title="class in org.apache.hadoop.examples">ExampleDriver</a></b></td> |
| | 381 | <td>A description of an example program based on its class and a human-readable description.</td> |
| | 382 | </tr> |
| | 383 | |
| | 384 | <tr class="TableRowColor" bgcolor="white"> |
| | 385 | <td width="15%"><b><a href="http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/examples/Grep.html" title="class in org.apache.hadoop.examples">Grep</a></b></td> |
| | 386 | <td> </td> |
| | 387 | </tr> |
| | 388 | <tr class="TableRowColor" bgcolor="white"> |
| | 389 | <td width="15%"><b><a href="http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/examples/Join.html" title="class in org.apache.hadoop.examples">Join</a></b></td> |
| | 390 | <td>This is the trivial map/reduce program that does absolutely nothing |
| | 391 | other than use the framework to fragment and sort the input values. To |
| | 392 | run: bin/hadoop jar build/hadoop-examples.jar join [-m maps] [-r |
| | 393 | reduces] [-inFormat input format class] [-outFormat output format |
| | 394 | class] [-outKey output key class] [-outValue output value class] |
| | 395 | [-joinOp <inner |outer|override="">] [in-dir]* in-dir out-dir</inner></td> |
| | 396 | </tr> |
| | 397 | <tr class="TableRowColor" bgcolor="white"> |
| | 398 | <td width="15%"><b><a href="http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/examples/RandomTextWriter.html" title="class in org.apache.hadoop.examples">RandomTextWriter</a></b></td> |
| | 399 | <td>This program uses map/reduce to just run a distributed job where |
| | 400 | there is |
| | 401 | no interaction between the tasks and each task writes a large unsorted |
| | 402 | random sequence of words.To run: bin/hadoop jar |
| | 403 | hadoop-${version}-examples.jar randomtextwriter [-outFormat output |
| | 404 | format class] output</td> |
| | 405 | |
| | 406 | </tr> |
| | 407 | <tr class="TableRowColor" bgcolor="white"> |
| | 408 | <td width="15%"><b><a href="http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/examples/RandomWriter.html" title="class in org.apache.hadoop.examples">RandomWriter</a></b></td> |
| | 409 | <td>This program uses map/reduce to just run a distributed job where |
| | 410 | there is |
| | 411 | no interaction between the tasks and each task write a large unsorted |
| | 412 | random binary sequence file of BytesWritable.To run: bin/hadoop jar |
| | 413 | hadoop-${version}-examples.jar randomwriter [-outFormat output format |
| | 414 | class] output</td> |
| | 415 | </tr> |
| | 416 | <tr class="TableRowColor" bgcolor="white"> |
| | 417 | <td width="15%"><b><a href="http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/examples/Sort.html" title="class in org.apache.hadoop.examples">Sort<K,V></a></b></td> |
| | 418 | <td>This is the trivial map/reduce program that does absolutely nothing |
| | 419 | other than use the framework to fragment and sort the input values.To |
| | 420 | run: bin/hadoop jar build/hadoop-examples.jar sort [-m maps] [-r |
| | 421 | reduces] [-inFormat input format class] [-outFormat output format |
| | 422 | class] [-outKey output key class] [-outValue output value class] |
| | 423 | [-totalOrder pcnt num samples max splits] in-dir out-dir</td> |
| | 424 | </tr> |
| | 425 | <tr class="TableRowColor" bgcolor="white"> |
| | 426 | <td width="15%"><b><a href="http://hadoop.apache.org/core/docs/current/api/org/apache/hadoop/examples/WordCount.html" title="class in org.apache.hadoop.examples">WordCount</a></b></td> |
| | 427 | |
| | 428 | <td>This is an example Hadoop Map/Reduce application.</td> |
| | 429 | </tr> |
| | 430 | </tbody></table> |
| | 431 | </body></html> |
| | 432 | }}} |
| | 433 | |
| | 434 | === 2.4 練習 === |
| | 435 | |
| | 436 | |
| | 437 | == Content 3. 使用網頁Gui瀏覽資訊 == |
| | 438 | |
| | 439 | * [http://localhost:50030 Map/Reduce Administration] |
| | 440 | * [http://localhost:50070 NameNode ] |
| | 441 | |
| | 442 | === 3.1 練習 === |
| | 443 | |
| | 444 | * 用網頁秀出你在 wordcount練習的輸出結果 |
| | 445 | |