hadoop 管理命令dfsadmin
hadoop 管理命令dfsadmin
dfsadmin 命令用于管理HDFS集群,这些命令常用于管理员。
1. (Safemode)安全模式
| 动作 | 命令 | 
| 把集群切换到安全模式 | bin/hdfs dfsadmin -safemode [enter/get/leave] | 
| 数据节点状态列表 | bin/hadoop dfsadmin -report | 
| 添加或删除数据节点 | bin/hadoop dfsadmin -refreshNodes | 
| 打印网络拓扑 | bin/hadoop dfsadmin -printTopology | 
| 官当网站 | http://hadoop.apache.org/docs/r2.8.3/hadoop-project-dist/hadoop-hdfs/HDFSCommands.html#dfsadmin | 
- 
[hadoop@master bin]$ ./hdfs dfsadmin -safemode enter #进入安全模式
- 
Safe mode is ON
- 
- 
[hadoop@master bin]$ ./hdfs dfsadmin -safemode get #获取当前状态
- 
Safe mode is ON
- 
- 
[hadoop@master bin]$ ./hdfs dfsadmin -safemode leave #离开safemode状态
- 
Safe mode is OFF
- 
[hadoop@master bin]$
- 
- 
hadoop启动时,会处于一种特殊的状态称做安全模式,这种模式下,数据块的复制是不能发生的,主节点会收到各数据节点的心跳(Heartbeat)和块报告(Blockreport)信息。块报告信息包含该数据节点包含的块信息,每一个数据块都有一个最小被副本数,当一个块最小副本数与NN记录的相符合时就被认为是安全的复制,在配置一个安全副本百分数与NN相符后(再加30s)(意思就是副本数*N%后与NN记录的相符就认为是安全,N可配置),NN就退出Safemode状态。之后(safemode 时是不能发生数据复制的)如果列表中仍然有少数的副本数比已备份少,NN将会把这些块复制到其他数据节点。
根据上面说明:
1.Safemode 主要是校验数据节点的块信息。
2.safemode 不能发生块复制(Replication )。
3.hadoop 的维护工作是在模式下进行的。
Safemode状态时创建目录报错:
Cannot create directory /hxw. Name node is in safe mode. It was turned on manually. Use "hdfs dfsadmin -safemode leave" to turn safe mode off.2.集群信息状态报告
以及集群资源占用情况,以及各数据节点信息。
- 
[hadoop@master logs]$ hadoop dfsadmin -report
- 
DEPRECATED: Use of this script to execute hdfs command is deprecated.
- 
Instead use the hdfs command for it.
- 
- 
- 
Configured Capacity: 37492883456 (34.92 GB)
- 
Present Capacity: 22908968960 (21.34 GB)
- 
DFS Remaining: 21126250496 (19.68 GB)
- 
DFS Used: 1782718464 (1.66 GB)
- 
DFS Used%: 7.78%
- 
Under replicated blocks: 18
- 
Blocks with corrupt replicas: 0
- 
Missing blocks: 0
- 
Missing blocks (with replication factor 1): 0
- 
Pending deletion blocks: 0
- 
- 
- 
-------------------------------------------------
- 
Live datanodes (2):
- 
- 
- 
Name: 10.0.1.226:50010 (slave-2)
- 
Hostname: slave-2
- 
Decommission Status : Normal
- 
Configured Capacity: 18746441728 (17.46 GB)
- 
DFS Used: 891359232 (850.07 MB)
- 
Non DFS Used: 7806763008 (7.27 GB)
- 
DFS Remaining: 10048319488 (9.36 GB)
- 
DFS Used%: 4.75%
- 
DFS Remaining%: 53.60%
- 
Configured Cache Capacity: 0 (0 B)
- 
Cache Used: 0 (0 B)
- 
Cache Remaining: 0 (0 B)
- 
Cache Used%: 100.00%
- 
Cache Remaining%: 0.00%
- 
Xceivers: 1
- 
Last contact: Wed Jan 17 17:09:23 CST 2018
- 
- 
- 
- 
- 
Name: 10.0.1.227:50010 (slave-1)
- 
Hostname: slave-1
- 
Decommission Status : Normal
- 
Configured Capacity: 18746441728 (17.46 GB)
- 
DFS Used: 891359232 (850.07 MB)
- 
Non DFS Used: 6777151488 (6.31 GB)
- 
DFS Remaining: 11077931008 (10.32 GB)
- 
DFS Used%: 4.75%
- 
DFS Remaining%: 59.09%
- 
Configured Cache Capacity: 0 (0 B)
- 
Cache Used: 0 (0 B)
- 
Cache Remaining: 0 (0 B)
- 
Cache Used%: 100.00%
- 
Cache Remaining%: 0.00%
- 
Xceivers: 1
- 
Last contact: Wed Jan 17 17:09:24 CST 2018
3.节点刷新
当集群有新增或删除节点时使用。
- 
[hadoop@master bin]$ ./hdfs dfsadmin -refreshNodes
- 
Refresh nodes successful
- 
- 
[hadoop@slave-1 sbin]$ ./hadoop-daemon.sh stop datanode
- 
stopping datanode
- 
- 
[hadoop@master bin]$ hadoop dfsadmin -report
- 
DEPRECATED: Use of this script to execute hdfs command is deprecated.
- 
Instead use the hdfs command for it.
- 
- 
- 
Configured Capacity: 37492883456 (34.92 GB)
- 
Present Capacity: 22914383872 (21.34 GB)
- 
DFS Remaining: 21131665408 (19.68 GB)
- 
DFS Used: 1782718464 (1.66 GB)
- 
DFS Used%: 7.78%
- 
Under replicated blocks: 18
- 
Blocks with corrupt replicas: 0
- 
Missing blocks: 0
- 
Missing blocks (with replication factor 1): 0
- 
Pending deletion blocks: 0
- 
- 
- 
-------------------------------------------------
- 
Live datanodes (2):
- 
- 
- 
Name: 10.0.1.226:50010 (slave-2)
- 
Hostname: slave-2
- 
Decommission Status : Normal
- 
Configured Capacity: 18746441728 (17.46 GB)
- 
DFS Used: 891359232 (850.07 MB)
- 
Non DFS Used: 7801290752 (7.27 GB)
- 
DFS Remaining: 10053791744 (9.36 GB)
- 
DFS Used%: 4.75%
- 
DFS Remaining%: 53.63%
- 
Configured Cache Capacity: 0 (0 B)
- 
Cache Used: 0 (0 B)
- 
Cache Remaining: 0 (0 B)
- 
Cache Used%: 100.00%
- 
Cache Remaining%: 0.00%
- 
Xceivers: 1
- 
Last contact: Wed Jan 17 18:16:06 CST 2018
- 
- 
- 
- 
- 
Name: 10.0.1.227:50010 (slave-1)
- 
Hostname: slave-1
- 
Decommission Status : Normal
- 
Configured Capacity: 18746441728 (17.46 GB)
- 
DFS Used: 891359232 (850.07 MB)
- 
Non DFS Used: 6777208832 (6.31 GB)
- 
DFS Remaining: 11077873664 (10.32 GB)
- 
DFS Used%: 4.75%
- 
DFS Remaining%: 59.09%
- 
Configured Cache Capacity: 0 (0 B)
- 
Cache Used: 0 (0 B)
- 
Cache Remaining: 0 (0 B)
- 
Cache Used%: 100.00%
- 
Cache Remaining%: 0.00%
- 
Xceivers: 1
- 
Last contact: Wed Jan 17 18:13:43 CST 2018
- 
- 
[hadoop@master bin]$ ./hdfs dfsadmin -refreshNodes
- 
Refresh nodes successful
- 
- 
- 
[hadoop@master bin]$ ./hdfs dfsadmin -refreshNodes
- 
Refresh nodes successful
- 
[hadoop@master bin]$ hadoop dfsadmin -report
- 
DEPRECATED: Use of this script to execute hdfs command is deprecated.
- 
Instead use the hdfs command for it.
- 
- 
- 
Configured Capacity: 37492883456 (34.92 GB)
- 
Present Capacity: 22914379776 (21.34 GB)
- 
DFS Remaining: 21131661312 (19.68 GB)
- 
DFS Used: 1782718464 (1.66 GB)
- 
DFS Used%: 7.78%
- 
Under replicated blocks: 18
- 
Blocks with corrupt replicas: 0
- 
Missing blocks: 0
- 
Missing blocks (with replication factor 1): 0
- 
Pending deletion blocks: 0
- 
- 
- 
-------------------------------------------------
- 
Live datanodes (2):
- 
- 
- 
Name: 10.0.1.226:50010 (slave-2)
- 
Hostname: slave-2
- 
Decommission Status : Normal
- 
Configured Capacity: 18746441728 (17.46 GB)
- 
DFS Used: 891359232 (850.07 MB)
- 
Non DFS Used: 7801294848 (7.27 GB)
- 
DFS Remaining: 10053787648 (9.36 GB)
- 
DFS Used%: 4.75%
- 
DFS Remaining%: 53.63%
- 
Configured Cache Capacity: 0 (0 B)
- 
Cache Used: 0 (0 B)
- 
Cache Remaining: 0 (0 B)
- 
Cache Used%: 100.00%
- 
Cache Remaining%: 0.00%
- 
Xceivers: 1
- 
Last contact: Wed Jan 17 18:18:54 CST 2018
- 
- 
- 
- 
- 
Name: 10.0.1.227:50010 (slave-1)
- 
Hostname: slave-1
- 
Decommission Status : Normal
- 
Configured Capacity: 18746441728 (17.46 GB)
- 
DFS Used: 891359232 (850.07 MB)
- 
Non DFS Used: 6777208832 (6.31 GB)
- 
DFS Remaining: 11077873664 (10.32 GB)
- 
DFS Used%: 4.75%
- 
DFS Remaining%: 59.09%
- 
Configured Cache Capacity: 0 (0 B)
- 
Cache Used: 0 (0 B)
- 
Cache Remaining: 0 (0 B)
- 
Cache Used%: 100.00%
- 
Cache Remaining%: 0.00%
- 
Xceivers: 1
- 
Last contact: Wed Jan 17 18:13:43 CST 2018
在Namenode 的配置文件slaves 中删除该节点,然后重新刷新节点信息,则后台显示:
- 
[hadoop@master bin]$ ./hdfs dfsadmin -refreshNodes
- 
Refresh nodes successful
- 
[hadoop@master bin]$ hadoop dfsadmin -report
- 
DEPRECATED: Use of this script to execute hdfs command is deprecated.
- 
Instead use the hdfs command for it.
- 
- 
Configured Capacity: 18746441728 (17.46 GB)
- 
Present Capacity: 10945093632 (10.19 GB)
- 
DFS Remaining: 10053734400 (9.36 GB)
- 
DFS Used: 891359232 (850.07 MB)
- 
DFS Used%: 8.14%
- 
Under replicated blocks: 161
- 
Blocks with corrupt replicas: 0
- 
Missing blocks: 0
- 
Missing blocks (with replication factor 1): 0
- 
Pending deletion blocks: 0
- 
- 
-------------------------------------------------
- 
Live datanodes (1):
- 
- 
Name: 10.0.1.226:50010 (slave-2)
- 
Hostname: slave-2
- 
Decommission Status : Normal
- 
Configured Capacity: 18746441728 (17.46 GB)
- 
DFS Used: 891359232 (850.07 MB)
- 
Non DFS Used: 7801348096 (7.27 GB)
- 
DFS Remaining: 10053734400 (9.36 GB)
- 
DFS Used%: 4.75%
- 
DFS Remaining%: 53.63%
- 
Configured Cache Capacity: 0 (0 B)
- 
Cache Used: 0 (0 B)
- 
Cache Remaining: 0 (0 B)
- 
Cache Used%: 100.00%
- 
Cache Remaining%: 0.00%
- 
Xceivers: 1
- 
Last contact: Wed Jan 17 18:26:36 CST 2018
- 
- 
- 
Dead datanodes (1):
- 
- 
Name: 10.0.1.227:50010 (slave-1)
- 
Hostname: slave-1
- 
Decommission Status : Normal
- 
Configured Capacity: 0 (0 B)
- 
DFS Used: 0 (0 B)
- 
Non DFS Used: 6777208832 (6.31 GB)
- 
DFS Remaining: 0 (0 B)
- 
DFS Used%: 100.00%
- 
DFS Remaining%: 0.00%
- 
Configured Cache Capacity: 0 (0 B)
- 
Cache Used: 0 (0 B)
- 
Cache Remaining: 0 (0 B)
- 
Cache Used%: 100.00%
- 
Cache Remaining%: 0.00%
- 
Xceivers: 0
- 
Last contact: Wed Jan 17 18:13:43 CST 2018
- 
4.网络拓扑
- 
[hadoop@master ~]$ hadoop dfsadmin -printTopology
- 
DEPRECATED: Use of this script to execute hdfs command is deprecated.
- 
Instead use the hdfs command for it.
- 
- 
Rack: /default-rack
- 
10.0.1.226:50010 (slave-2)
- 
10.0.1.227:50010 (slave-1)
总结:
- 
[hadoop@master bin]$ ./hdfs dfsadmin -safemode enter #进入Safemode模式
- 
[hadoop@master bin]$ ./hdfs dfsadmin -safemode get #获取当前运行模式
- 
[hadoop@master bin]$ ./hdfs dfsadmin -safemode leave #退出Safemode模式
- 
[hadoop@master bin]$ hadoop dfsadmin -report #当前hadoop集群状态信息
- 
[hadoop@master bin]$ ./hdfs dfsadmin -refreshNodes #新增删除节点更新集群信息
- 
[hadoop@master sbin]$ ./hadoop-daemon.sh stop datanode #停止单个数据节点
- 
[hadoop@master ~]$ hadoop dfsadmin -printTopology #打印集群网络拓扑
- 
 
                    
                 
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号