Changes between Version 3 and Version 4 of NCTU110329/Lab4
- Timestamp:
- Apr 19, 2011, 9:57:33 AM (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
NCTU110329/Lab4
v3 v4 10 10 }}} 11 11 12 * 以下練習,請連線至 hadoop.nchc.org.tw 操作。 12 {{{ 13 #!text 14 以下練習,請連線至 hadoop.nchc.org.tw 操作。底下的 hXXXX 等於您的用戶名稱。 15 }}} 13 16 14 17 == Content 1: HDFS Shell 基本操作 == … … 20 23 {{{ 21 24 ~$ hadoop fs -ls 25 Found 1 items 26 drwxr-xr-x - hXXXX supergroup 0 2010-01-24 17:23 /user/hXXXX/tmp 22 27 ~$ hadoop fs -lsr 28 drwxr-xr-x - hXXXX supergroup 0 2010-01-24 17:23 /user/hXXXX/tmp 23 29 }}} 24 30 … … 29 35 30 36 {{{ 31 ~$ hadoop fs -put conf input37 ~$ hadoop fs -put /etc/hadoop/conf input 32 38 }}} 33 39 … … 36 42 {{{ 37 43 ~$ hadoop fs -ls 44 Found 2 items 45 drwxr-xr-x - hXXXX supergroup 0 2011-04-19 09:16 /user/hXXXX/input 46 drwxr-xr-x - hXXXX supergroup 0 2010-01-24 17:23 /user/hXXXX/tmp 38 47 ~$ hadoop fs -ls input 48 Found 25 items 49 -rw-r--r-- 2 hXXXX supergroup 321 2011-04-19 09:16 /user/hXXXX/input/README 50 -rw-r--r-- 2 hXXXX supergroup 3936 2011-04-19 09:16 /user/hXXXX/input/capacity-scheduler.xml 51 -rw-r--r-- 2 hXXXX supergroup 196 2011-04-19 09:16 /user/hXXXX/input/commons-logging.properties 52 (.... skip ....) 39 53 }}} 40 54 … … 49 63 50 64 * 檢查 Check 51 52 65 {{{ 53 66 ~$ ls -al | grep fromHDFS 67 drwxr-xr-x 2 hXXXX hXXXX 4096 2011-04-19 09:18 fromHDFS 54 68 ~$ ls -al fromHDFS 69 總計 160 70 drwxr-xr-x 2 hXXXX hXXXX 4096 2011-04-19 09:18 . 71 drwx--x--x 3 hXXXX hXXXX 4096 2011-04-19 09:18 .. 72 -rw-r--r-- 1 hXXXX hXXXX 3936 2011-04-19 09:18 capacity-scheduler.xml 73 -rw-r--r-- 1 hXXXX hXXXX 196 2011-04-19 09:18 commons-logging.properties 74 -rw-r--r-- 1 hXXXX hXXXX 535 2011-04-19 09:18 configuration.xsl 75 (.... skip ....) 76 ~$ diff /etc/hadoop/conf fromHDFS/ 55 77 }}} 56 78 … … 59 81 60 82 {{{ 61 ~$ hadoop fs -ls input 83 ~$ hadoop fs -ls input/masters 84 Found 1 items 85 -rw-r--r-- 2 hXXXX supergroup 10 2011-04-19 09:16 /user/hXXXX/input/masters 62 86 ~$ hadoop fs -rm input/masters 87 Deleted hdfs://hadoop.nchc.org.tw/user/hXXXX/input/masters 63 88 }}} 64 89 … … 67 92 68 93 {{{ 69 ~$ hadoop fs -ls input 94 ~$ hadoop fs -ls input/slaves 95 Found 1 items 96 -rw-r--r-- 2 hXXXX supergroup 10 2011-04-19 09:16 /user/hXXXX/input/slaves 70 97 ~$ hadoop fs -cat input/slaves 98 localhost 71 99 }}} 72 100 … … 75 103 76 104 {{{ 77 hXXXX@ vPro:~$ hadoop fs105 hXXXX@hadoop:~$ hadoop fs 78 106 79 107 Usage: java FsShell … … 133 161 {{{ 134 162 $ hadoop fs -ls input 135 Found 4items136 -rw-r--r-- 2 hXXXX supergroup 115045564 2009-04-02 11:51 /user/hXXXX/input/1.txt137 -rw-r--r-- 2 hXXXX supergroup 987864 2009-04-02 11:51 /user/hXXXX/input/2.txt138 -rw-r--r-- 2 hXXXX supergroup 1573048 2009-04-02 11:51 /user/hXXXX/input/3.txt139 -rw-r--r-- 2 hXXXX supergroup 25844527 2009-04-02 11:51 /user/hXXXX/input/4.txt 163 Found 25 items 164 -rw-r--r-- 2 hXXXX supergroup 321 2011-04-19 09:16 /user/hXXXX/input/README 165 -rw-r--r-- 2 hXXXX supergroup 3936 2011-04-19 09:16 /user/hXXXX/input/capacity-scheduler.xml 166 -rw-r--r-- 2 hXXXX supergroup 196 2011-04-19 09:16 /user/hXXXX/input/commons-logging.properties 167 (.... skip ....) 140 168 }}} 141 169 * 完整的路徑則是 '''hdfs://node:port/path''' 如:[[BR]]Or you have to give a __''absolute path''__, such as '''hdfs://node:port/path''' 142 170 {{{ 143 $ hadoop fs -ls hdfs://hadoop.nchc.org.tw :9000/user/hXXXX/input144 Found 4items145 -rw-r--r-- 2 hXXXX supergroup 115045564 2009-04-02 11:51 /user/hXXXX/input/1.txt146 -rw-r--r-- 2 hXXXX supergroup 987864 2009-04-02 11:51 /user/hXXXX/input/2.txt147 -rw-r--r-- 2 hXXXX supergroup 1573048 2009-04-02 11:51 /user/hXXXX/input/3.txt148 -rw-r--r-- 2 hXXXX supergroup 25844527 2009-04-02 11:51 /user/hXXXX/input/4.txt 171 $ hadoop fs -ls hdfs://hadoop.nchc.org.tw/user/hXXXX/input 172 Found 25 items 173 -rw-r--r-- 2 hXXXX supergroup 321 2011-04-19 09:16 /user/hXXXX/input/README 174 -rw-r--r-- 2 hXXXX supergroup 3936 2011-04-19 09:16 /user/hXXXX/input/capacity-scheduler.xml 175 -rw-r--r-- 2 hXXXX supergroup 196 2011-04-19 09:16 /user/hXXXX/input/commons-logging.properties 176 (.... skip ....) 149 177 }}} 150 178 … … 153 181 * 將路徑指定文件的內容輸出到 STDOUT [[BR]] Print given file content to STDOUT 154 182 {{{ 155 $ hadoop fs -cat quota/hadoop-env.sh183 $ hadoop fs -cat input/hadoop-env.sh 156 184 }}} 157 185 158 === 186 === -chgrp === 159 187 160 188 * 改變文件所屬的組 [[BR]] Change '''owner group''' of given file or folder 161 189 {{{ 162 $ hadoop fs -chgrp -R hXXXX own 190 $ hadoop fs -ls 191 Found 2 items 192 drwxr-xr-x - hXXXX supergroup 0 2011-04-19 09:16 /user/hXXXX/input 193 drwxr-xr-x - hXXXX supergroup 0 2010-01-24 17:23 /user/hXXXX/tmp 194 $ hadoop fs -chgrp -R ${USER} input 195 $ hadoop fs -ls 196 Found 2 items 197 drwxr-xr-x - hXXXX hXXXX 0 2011-04-19 09:21 /user/hXXXX/input 198 drwxr-xr-x - hXXXX supergroup 0 2010-01-24 17:23 /user/hXXXX/tmp 163 199 }}} 164 200 … … 167 203 * 改變文件的權限 [[BR]] Change '''read and write permission''' of given file or folder 168 204 {{{ 169 $ hadoop fs -chmod -R 755 own 205 $ hadoop fs -ls 206 Found 2 items 207 drwxr-xr-x - hXXXX hXXXX 0 2011-04-19 09:21 /user/hXXXX/input 208 drwxr-xr-x - hXXXX supergroup 0 2010-01-24 17:23 /user/hXXXX/tmp 209 $ hadoop fs -chmod -R 755 input 210 $ hadoop fs -ls 211 Found 2 items 212 drwxrwxrwx - hXXXX hXXXX 0 2011-04-19 09:21 /user/hXXXX/input 213 drwxr-xr-x - hXXXX supergroup 0 2010-01-24 17:23 /user/hXXXX/tmp 170 214 }}} 171 215 … … 174 218 * 改變文件的擁有者 [[BR]] Change '''owner''' of given file or folder 175 219 {{{ 176 $ hadoop fs -chown -R hXXXX own 220 $ hadoop fs -chown -R ${USER} input 221 }}} 222 * 注意:因為在 hadoop.nchc.org.tw 上您沒有管理者權限,因此若要改成其他使用者時,會看到類似以下的錯誤訊息: 223 * Note: Since you don't have the super user permission, you will see error message as following: 224 {{{ 225 $ hadoop fs -chown -R h1000 input 226 chown: changing ownership of 'hdfs://hadoop.nchc.org.tw/user/hXXXX/input':org.apache.hadoop.security.AccessControlException: Non-super user cannot change owner. 177 227 }}} 178 228 … … 181 231 * 從 local 放檔案到 hdfs [[BR]] Both commands will copy given file or folder from local to HDFS 182 232 {{{ 183 $ hadoop fs - put inputdfs_input233 $ hadoop fs -copyFromLocal /etc/hadoop/conf dfs_input 184 234 }}} 185 235 … … 188 238 * 把hdfs上得檔案下載到 local [[BR]] Both commands will copy given file or folder from HDFS to local 189 239 {{{ 190 $ hadoop fs - getdfs_input input1240 $ hadoop fs -copyToLocal dfs_input input1 191 241 }}} 192 242 … … 195 245 * 將文件從 hdfs 原本路徑複製到 hdfs 目標路徑 [[BR]] Copy given file or folder from HDFS source path to HDFS target path 196 246 {{{ 197 $ hadoop fs -cp own hXXXX247 $ hadoop fs -cp input input1 198 248 }}} 199 249 … … 203 253 {{{ 204 254 $ hadoop fs -du input 205 206 Found 4 items 207 115045564 hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/1.txt 208 987864 hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/2.txt 209 1573048 hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/3.txt 210 25844527 hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/4.txt 211 }}} 255 Found 24 items 256 321 hdfs://hadoop.nchc.org.tw/user/hXXXX/input/README 257 3936 hdfs://hadoop.nchc.org.tw/user/hXXXX/input/capacity-scheduler.xml 258 196 hdfs://hadoop.nchc.org.tw/user/hXXXX/input/commons-logging.properties 259 ( .... skip .... ) 260 }}} 261 212 262 === -dus === 213 263 … … 215 265 {{{ 216 266 $ hadoop fs -dus input 217 218 hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input 143451003 267 hdfs://hadoop.nchc.org.tw/user/hXXXX/input 84218 219 268 }}} 220 269 … … 233 282 }}} 234 283 {{{ 284 $ mkdir -p in1 235 285 $ echo "this is one; " >> in1/input 236 286 $ echo "this is two; " >> in1/input2 … … 239 289 $ cat ./merge.txt 240 290 }}} 241 242 == -ls === 291 * 您應該會看到類似底下的結果:[[BR]]You should see results like this: 292 {{{ 293 this is one; 294 this is two; 295 }}} 296 297 === -ls === 243 298 244 299 * 列出文件或目錄的資訊 [[BR]] List files and folders … … 247 302 {{{ 248 303 $ hadoop fs -ls 304 Found 5 items 305 drwxr-xr-x - hXXXX supergroup 0 2011-04-19 09:32 /user/hXXXX/dfs_input 306 drwxr-xr-x - hXXXX supergroup 0 2011-04-19 09:34 /user/hXXXX/in1 307 drwxrwxrwx - hXXXX hXXXX 0 2011-04-19 09:21 /user/hXXXX/input 308 drwxr-xr-x - hXXXX supergroup 0 2011-04-19 09:33 /user/hXXXX/input1 309 drwxr-xr-x - hXXXX supergroup 0 2010-01-24 17:23 /user/hXXXX/tmp 249 310 }}} 250 311 … … 253 314 * ls 命令的遞迴版本 [[BR]] list files and folders with recursive 254 315 {{{ 255 $ hadoop fs -lsr / 316 $ hadoop fs -lsr in1 317 -rw-r--r-- 2 hXXXX supergroup 14 2011-04-19 09:34 /user/hXXXX/in1/input 318 -rw-r--r-- 2 hXXXX supergroup 14 2011-04-19 09:34 /user/hXXXX/in1/input2 256 319 }}} 257 320 … … 282 345 {{{ 283 346 $ hadoop fs -rm in1/input 347 Deleted hdfs://hadoop.nchc.org.tw/user/hXXXX/in1/input 284 348 }}} 285 349 === -rmr === … … 287 351 * 遞迴刪除資料夾(包含在內的所有檔案) [[BR]] Remove given files and folders with recursive 288 352 {{{ 289 $ hadoop fs -rmr in1 353 $ hadoop fs -rmr a b c dfs_input in3 input input1 354 Deleted hdfs://hadoop.nchc.org.tw/user/hXXXX/a 355 Deleted hdfs://hadoop.nchc.org.tw/user/hXXXX/b 356 Deleted hdfs://hadoop.nchc.org.tw/user/hXXXX/c 357 Deleted hdfs://hadoop.nchc.org.tw/user/hXXXX/dfs_input 358 Deleted hdfs://hadoop.nchc.org.tw/user/hXXXX/in3 359 Deleted hdfs://hadoop.nchc.org.tw/user/hXXXX/input 360 Deleted hdfs://hadoop.nchc.org.tw/user/hXXXX/input1 290 361 }}} 291 362 … … 297 368 }}} 298 369 {{{ 299 $ hadoop fs -setrep -w 2 -R input 300 Replication 2 set: hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/1.txt 301 Replication 2 set: hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/2.txt 302 Replication 2 set: hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/3.txt 303 Replication 2 set: hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/4.txt 304 Waiting for hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/1.txt ... done 305 Waiting for hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/2.txt ... done 306 Waiting for hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/3.txt ... done 307 Waiting for hdfs://hadoop.nchc.org.tw:9000/user/hXXXX/input/4.txt ... done 370 $ hadoop fs -setrep -w 2 -R in1 371 Replication 2 set: hdfs://hadoop.nchc.org.tw/user/hXXXX/in1/input2 372 Waiting for hdfs://hadoop.nchc.org.tw/user/hXXXX/in1/input2 ... done 308 373 }}} 309 374 … … 312 377 * 印出時間資訊 [[BR]] Print Status of time stamp of folder 313 378 {{{ 314 $ hadoop fs -stat in put315 20 09-04-02 03:51:29379 $ hadoop fs -stat in1 380 2011-04-19 09:34:49 316 381 }}} 317 382 === -tail === … … 324 389 }}} 325 390 {{{ 326 $ hadoop fs -tail input/1.txt 391 $ hadoop fs -tail in1/input2 392 this is two; 327 393 }}} 328 394 … … 337 403 338 404 {{{ 339 $ hadoop fs -test -e /user/hXXXX/input/5.txt 340 $ hadoop fs -test -z /user/hXXXX/input/5.txt 341 test: File does not exist: /user/hXXXX/input/5.txt 342 $ hadoop fs -test -d /user/hXXXX/input/5.txt 343 344 test: File does not exist: /user/hXXXX/input/5.txt 345 }}} 346 347 === -text === 348 349 * 將檔案(如壓縮檔, textrecordinputstream)輸出為純文字格式 [[BR]] Display archive file contents into STDOUT 350 {{{ 351 $ hadoop fs -text <src> 352 }}} 353 {{{ 354 $ hadoop fs -text macadr-eth1.txt.gz 355 00:1b:fc:61:75:b1 356 00:1b:fc:58:9c:23 357 }}} 358 * ps : 目前沒支援zip的函式庫 [[BR]] PS. It does not support zip files yet. 359 {{{ 360 $ hadoop fs -text b/a.txt.zip 361 PK 362 ���:��H{ 363 a.txtUT b��Ib��IUx��sssss 364 test 365 PK 366 ���:��H{ 367 ��a.txtUTb��IUxPK@C 368 }}} 369 370 === -touchz === 371 372 * 建立一個空文件 [[BR]] creat an empty file 373 {{{ 374 $ hadoop fs -touchz b/kk 375 $ hadoop fs -test -z b/kk 405 $ hadoop fs -test -e in1/input2 406 $ echo $? 407 0 408 $ hadoop fs -test -z in1/input3 376 409 $ echo $? 377 410 1 378 $ hadoop fs -test -z b/a.txt.zip 411 $ hadoop fs -test -d in1/input2 412 $ echo $? 413 1 414 }}} 415 416 === -text === 417 418 * 將檔案(如壓縮檔, textrecordinputstream)輸出為純文字格式 [[BR]] Display archive file contents into STDOUT 419 {{{ 420 $ hadoop fs -text <src> 421 }}} 422 {{{ 423 $ gzip merge.txt 424 $ hadoop fs -put merge.txt.gz . 425 $ hadoop fs -text merge.txt.gz 426 11/04/19 09:54:16 INFO util.NativeCodeLoader: Loaded the native-hadoop library 427 11/04/19 09:54:16 INFO zlib.ZlibFactory: Successfully loaded & initialized native-zlib library 428 this is one; 429 this is two; 430 }}} 431 * ps : 目前沒支援zip的函式庫 [[BR]] PS. It does not support zip files yet. 432 {{{ 433 $ gunzip merge.txt.gz 434 $ zip merge.zip merge.txt 435 $ hadoop fs -put merge.zip . 436 $ hadoop fs -text merge.zip 437 PK�N�>E73 438 439 merge.txtUT ���Mq��Mux 440 ��+��,V���Tk�(��<�PK 441 �N�>E73 442 ��merge.txtUT���Mux 443 ��PKOY 444 }}} 445 446 === -touchz === 447 448 * 建立一個空文件 [[BR]] creat an empty file 449 {{{ 450 $ hadoop fs -touchz in1/kk 451 $ hadoop fs -test -z in1/kk 379 452 $ echo $? 380 453 0 381 454 }}} 455 456 ---- 457 458 * 您可以用以下指令把以上練習產生的暫存目錄與檔案清除:[[BR]]You can clean up the temporary folders and files using following command: 459 {{{ 460 ~$ hadoop fs -rmr in1 merge.txt.gz merge.zip 461 ~$ rm -rf input1/ fromHDFS/ merge.txt 462 }}}