hadoop常用操作命令

guocun09發表於2017-10-27

dfsadmin命令

report各幾點使用狀態

[hdfs@hd3 ~]$ hadoop dfsadmin -report

DEPRECATED: Use of this script to execute hdfs command is deprecated.

Instead use the hdfs command for it.

 

Configured Capacity: 768761769165 (715.97 GB)

Present Capacity: 739275145216 (688.50 GB)

DFS Remaining: 728906240000 (678.85 GB)

DFS Used: 10368905216 (9.66 GB)

DFS Used%: 1.40%

Under replicated blocks: 0

Blocks with corrupt replicas: 0

Missing blocks: 0

 

-------------------------------------------------

Datanodes available: 4 (4 total, 0 dead)

 

Live datanodes:

Name: 10.202.11.20:50010 (hd1)

Hostname: hd1

Rack: /default

Decommission Status : Normal

Configured Capacity: 137276063744 (127.85 GB)

DFS Used: 3119067136 (2.90 GB)

Non DFS Used: 6016712704 (5.60 GB)

DFS Remaining: 128140283904 (119.34 GB)

DFS Used%: 2.27%

DFS Remaining%: 93.34%

Last contact: Fri Jul 25 11:20:55 CST 2014

 

 

Name: 10.202.11.21:50010 (hd2)

Hostname: hd2

Rack: /default

Decommission Status : Normal

Configured Capacity: 64706464973 (60.26 GB)

DFS Used: 2280718336 (2.12 GB)

Non DFS Used: 2592439501 (2.41 GB)

DFS Remaining: 59833307136 (55.72 GB)

DFS Used%: 3.52%

DFS Remaining%: 92.47%

Last contact: Fri Jul 25 11:20:55 CST 2014

 

Name: 10.202.11.22:50010 (hd3)

Hostname: hd3

Rack: /default

Decommission Status : Normal

Configured Capacity: 226409611264 (210.86 GB)

DFS Used: 2314543104 (2.16 GB)

Non DFS Used: 7515787264 (7.00 GB)

DFS Remaining: 216579280896 (201.71 GB)

DFS Used%: 1.02%

DFS Remaining%: 95.66%

Last contact: Fri Jul 25 11:20:55 CST 2014

 

Name: 10.202.11.23:50010 (hd4)

Hostname: hd4

Rack: /default

Decommission Status : Normal

Configured Capacity: 340369629184 (316.99 GB)

DFS Used: 2654576640 (2.47 GB)

Non DFS Used: 13361684480 (12.44 GB)

DFS Remaining: 324353368064 (302.08 GB)

DFS Used%: 0.78%

DFS Remaining%: 95.29%

Last contact: Fri Jul 25 11:20:55 CST 2014

 

safemode進入和離開安全模式

檢視模式

[hdfs@hd2 ~]$ hadoop dfsadmin -safemode get

DEPRECATED: Use of this script to execute hdfs command is deprecated.

Instead use the hdfs command for it.

 

Safe mode is OFF

進入安全模式

[hdfs@hd2 ~]$ hadoop dfsadmin -safemode enter

DEPRECATED: Use of this script to execute hdfs command is deprecated.

Instead use the hdfs command for it.

 

Safe mode is ON

nodename在啟動時會處在安全模式,用這條命令可確保啟動完成後不離開安全模式。也可以指定dfs.sfaemode.threshold.pct設定>1

 

 

離開安全模式

[hdfs@hd2 ~]$ hadoop dfsadmin -safemode leave

DEPRECATED: Use of this script to execute hdfs command is deprecated.

Instead use the hdfs command for it.

 

Safe mode is OFF

 

在執行某條命令時臨時先退出安全模式,前面寫:

[hdfs@hd2 ~]$ hadoop dfsadmin -safemode wait

 

 

Fsck檢查HDFS檔案監控狀況

檢查某個叢集檔案系統

[hdfs@hd1 ~]$ hadoop fsck /

DEPRECATED: Use of this script to execute hdfs command is deprecated.

Instead use the hdfs command for it.

 

Connecting to namenode via

FSCK started by hdfs (auth:SIMPLE) from /10.202.11.20 for path / at Tue Aug 19 14:35:53 CST 2014

....................................................................................................

....................................................................................................

....................................................................................................

.............................................Status: HEALTHY

 Total size:    5120355488 B

 Total dirs:    176

 Total files:   345

 Total blocks (validated):      364 (avg. block size 14066910 B)

 Minimally replicated blocks:   364 (100.0 %)

 Over-replicated blocks:        0 (0.0 %)

 Under-replicated blocks:       0 (0.0 %)

 Mis-replicated blocks:         0 (0.0 %)

 Default replication factor:    3

 Average block replication:     2.6923077

 Corrupt blocks:                0

 Missing replicas:              0 (0.0 %)

 Number of data-nodes:          4

 Number of racks:               1

FSCK ended at Tue Aug 19 14:35:53 CST 2014 in 86 milliseconds

 

The filesystem under path '/' is HEALTHY

 

 

查詢特定檔案的資料塊和分佈節點

[hdfs@hd2 ~]$ hadoop fsck /user/gc/hdfs_file -files -blocks -racks

DEPRECATED: Use of this script to execute hdfs command is deprecated.

Instead use the hdfs command for it.

 

Connecting to namenode via

FSCK started by hdfs (auth:SIMPLE) from /10.202.11.21 for path /user/gc/hdfs_file at Thu Sep 04 10:15:25 CST 2014

/user/gc/hdfs_file 19 bytes, 1 block(s):  OK

0. BP-2070684995-10.202.11.20-1405329506510:blk_9027993399902156289_85985 len=19 repl=3 [/default/10.202.11.22:50010, /default/10.202.11.20:50010, /default/10.202.11.23:50010]

 

Status: HEALTHY

 Total size:    19 B

 Total dirs:    0

 Total files:   1

 Total blocks (validated):      1 (avg. block size 19 B)

 Minimally replicated blocks:   1 (100.0 %)

 Over-replicated blocks:        0 (0.0 %)

 Under-replicated blocks:       0 (0.0 %)

 Mis-replicated blocks:         0 (0.0 %)

 Default replication factor:    3

 Average block replication:     3.0

 Corrupt blocks:                0

 Missing replicas:              0 (0.0 %)

 Number of data-nodes:          4

 Number of racks:               1

FSCK ended at Thu Sep 04 10:15:25 CST 2014 in 1 milliseconds

 

刪除檔案

hadoop fs –rm –f /user/hive/xx

刪除資料夾

hadoop fs –rmr –f /user/hive/xx

 

copyFromLocal 複製本地檔案到HDFS

[hdfs@SCQHADoopN01 data]$ hadoop fs -copyFromLocal /data/copyToLocal_gc /user/hive/warehouse/test/part-m-00000-gc

[hdfs@SCQHADoopN01 data]$ hadoop fs -cat /user/hive/warehouse/test/part-m-00000-gc

1,abc

1,haha

 

 

copyToLocal 複製hdfs檔案到本地

[hdfs@SCQHADoopN01 data]$ hadoop fs -copyToLocal hdfs://nameservice1/user/hive/warehouse/test/part-m-00000 /data/copyToLocal_gc

[hdfs@SCQHADoopN01 data]$ cd /data/

[hdfs@SCQHADoopN01 data]$ ll

total 16

-rw-r--r-- 1 hdfs hdfs     13 Nov  5 15:47 copyToLocal_gc

-rw-rw-r-- 1 hdfs hdfs     19 Aug 28 14:11 hdfs_file

drwxr-xr-x 3 root root   4096 Aug 28 08:52 mapred

drwx------ 3 hdfs hadoop 4096 Oct 10 14:01 nn

[hdfs@SCQHADoopN01 data]$ more copyToLocal_gc

1,abc

1,haha

 

 

 

 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25583515/viewspace-2146512/,如需轉載,請註明出處,否則將追究法律責任。

相關文章