| 1 | [[PageOutline]] |
| 2 | |
| 3 | ◢ <[wiki:FDC110829/Lab1 實作一]> | <[wiki:FDC110829 回課程大綱]> ▲ | <[wiki:FDC110829/Lab3 實作三]> ◣ |
| 4 | |
| 5 | = 實作二 Lab 2 = |
| 6 | |
| 7 | {{{ |
| 8 | #!html |
| 9 | <div style="text-align: center;"><big style="font-weight: bold;"><big>HDFS Shell操作練習<br/>HDFS Shell in practice</big></big></div> |
| 10 | }}} |
| 11 | |
| 12 | {{{ |
| 13 | #!text |
| 14 | 以下練習,請連線至 hadoop.nchc.org.tw 操作。底下的 hXXXX 等於您的用戶名稱。 |
| 15 | }}} |
| 16 | |
| 17 | == Content 1: HDFS Shell 基本操作 == |
| 18 | == Content 1: Basic HDFS Shell Commands == |
| 19 | |
| 20 | === 1.1 瀏覽你HDFS目錄 === |
| 21 | === 1.1 Browsing Your HDFS Folder === |
| 22 | |
| 23 | {{{ |
| 24 | ~$ hadoop fs -ls |
| 25 | Found 1 items |
| 26 | drwxr-xr-x - hXXXX supergroup 0 2010-01-24 17:23 /user/hXXXX/tmp |
| 27 | ~$ hadoop fs -lsr |
| 28 | drwxr-xr-x - hXXXX supergroup 0 2010-01-24 17:23 /user/hXXXX/tmp |
| 29 | }}} |
| 30 | |
| 31 | === 1.2 上傳資料到 HDFS 目錄 === |
| 32 | === 1.2 Upload Files or Folder to HDFS === |
| 33 | |
| 34 | * 上傳 Upload |
| 35 | |
| 36 | {{{ |
| 37 | ~$ hadoop fs -put /etc/hadoop/conf input |
| 38 | }}} |
| 39 | |
| 40 | * 檢查 Check |
| 41 | |
| 42 | {{{ |
| 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 |
| 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 ....) |
| 53 | }}} |
| 54 | |
| 55 | === 1.3 下載 HDFS 的資料到本地目錄 === |
| 56 | === 1.3 Download HDFS Files or Folder to Local === |
| 57 | |
| 58 | * 下載 Download |
| 59 | |
| 60 | {{{ |
| 61 | ~$ hadoop fs -get input fromHDFS |
| 62 | }}} |
| 63 | |
| 64 | * 檢查 Check |
| 65 | {{{ |
| 66 | ~$ ls -al | grep fromHDFS |
| 67 | drwxr-xr-x 2 hXXXX hXXXX 4096 2011-04-19 09:18 fromHDFS |
| 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/ |
| 77 | }}} |
| 78 | |
| 79 | === 1.4 刪除檔案 === |
| 80 | === 1.4 Remove Files or Folder === |
| 81 | |
| 82 | {{{ |
| 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 |
| 86 | ~$ hadoop fs -rm input/masters |
| 87 | Deleted hdfs://hadoop.nchc.org.tw/user/hXXXX/input/masters |
| 88 | }}} |
| 89 | |
| 90 | === 1.5 直接看檔案 === |
| 91 | === 1.5 Browse Files Directly === |
| 92 | |
| 93 | {{{ |
| 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 |
| 97 | ~$ hadoop fs -cat input/slaves |
| 98 | localhost |
| 99 | }}} |
| 100 | |
| 101 | === 1.6 更多指令操作 === |
| 102 | === 1.6 More Commands -- Help message === |
| 103 | |
| 104 | {{{ |
| 105 | hXXXX@hadoop:~$ hadoop fs |
| 106 | |
| 107 | Usage: java FsShell |
| 108 | [-ls <path>] |
| 109 | [-lsr <path>] |
| 110 | [-du <path>] |
| 111 | [-dus <path>] |
| 112 | [-count[-q] <path>] |
| 113 | [-mv <src> <dst>] |
| 114 | [-cp <src> <dst>] |
| 115 | [-rm <path>] |
| 116 | [-rmr <path>] |
| 117 | [-expunge] |
| 118 | [-put <localsrc> ... <dst>] |
| 119 | [-copyFromLocal <localsrc> ... <dst>] |
| 120 | [-moveFromLocal <localsrc> ... <dst>] |
| 121 | [-get [-ignoreCrc] [-crc] <src> <localdst>] |
| 122 | [-getmerge <src> <localdst> [addnl]] |
| 123 | [-cat <src>] |
| 124 | [-text <src>] |
| 125 | [-copyToLocal [-ignoreCrc] [-crc] <src> <localdst>] |
| 126 | [-moveToLocal [-crc] <src> <localdst>] |
| 127 | [-mkdir <path>] |
| 128 | [-setrep [-R] [-w] <rep> <path/file>] |
| 129 | [-touchz <path>] |
| 130 | [-test -[ezd] <path>] |
| 131 | [-stat [format] <path>] |
| 132 | [-tail [-f] <file>] |
| 133 | [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...] |
| 134 | [-chown [-R] [OWNER][:[GROUP]] PATH...] |
| 135 | [-chgrp [-R] GROUP PATH...] |
| 136 | [-help [cmd]] |
| 137 | |
| 138 | Generic options supported are |
| 139 | -conf <configuration file> specify an application configuration file |
| 140 | -D <property=value> use value for given property |
| 141 | -fs <local|namenode:port> specify a namenode |
| 142 | -jt <local|jobtracker:port> specify a job tracker |
| 143 | -files <comma separated list of files> specify comma separated files to be copied to the map reduce cluster |
| 144 | -libjars <comma separated list of jars> specify comma separated jar files to include in the classpath. |
| 145 | -archives <comma separated list of archives> specify comma separated archives to be unarchived on the compute machines. |
| 146 | The general command line syntax is |
| 147 | hadoop command [genericOptions] [commandOptions] |
| 148 | }}} |
| 149 | |
| 150 | == Content 2: 使用網頁 GUI 瀏覽資訊 == |
| 151 | == Content 2: User Web GUI to browse HDFS == |
| 152 | |
| 153 | * [http://localhost:50030 JobTracker Web Interface] |
| 154 | * [http://localhost:50070 NameNode Web Interface] |
| 155 | |
| 156 | == Content 3: 更多 HDFS Shell 的用法 == |
| 157 | == Content 3: More about HDFS Shell == |
| 158 | |
| 159 | * hadoop fs <args> ,下面則列出 <args> 的用法[[BR]]Following are the examples of hadoop fs related commands. |
| 160 | * 以下操作預設的目錄在 /user/<$username>/ 下[[BR]]By default, your working directory will be at /user/<$username>/. |
| 161 | {{{ |
| 162 | $ hadoop fs -ls input |
| 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 ....) |
| 168 | }}} |
| 169 | * 完整的路徑則是 '''hdfs://node:port/path''' 如:[[BR]]Or you have to give a __''absolute path''__, such as '''hdfs://node:port/path''' |
| 170 | {{{ |
| 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 ....) |
| 177 | }}} |
| 178 | |
| 179 | === -cat === |
| 180 | |
| 181 | * 將路徑指定文件的內容輸出到 STDOUT [[BR]] Print given file content to STDOUT |
| 182 | {{{ |
| 183 | $ hadoop fs -cat input/hadoop-env.sh |
| 184 | }}} |
| 185 | |
| 186 | === -chgrp === |
| 187 | |
| 188 | * 改變文件所屬的組 [[BR]] Change '''owner group''' of given file or folder |
| 189 | {{{ |
| 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 |
| 199 | }}} |
| 200 | |
| 201 | === -chmod === |
| 202 | |
| 203 | * 改變文件的權限 [[BR]] Change '''read and write permission''' of given file or folder |
| 204 | {{{ |
| 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 |
| 214 | }}} |
| 215 | |
| 216 | === -chown === |
| 217 | |
| 218 | * 改變文件的擁有者 [[BR]] Change '''owner''' of given file or folder |
| 219 | {{{ |
| 220 | $ hadoop fs -chown -R ${USER} input |
| 221 | }}} |
| 222 | * 注意:因為在 hadoop.nchc.org.tw 上您沒有管理者權限,因此若要改成其 |