hadoop(四)hdfs命令

This is about jdk

Posted by PsycheLee on 2015-09-08

hadoop(四)hdfs命令

SNN

SNN

1.snn执行checkpoint动作时候,nn会停止使用当前的edit文件515-516,
会暂时将读写操作记录到一个新的edit文件中 517
2.snn将nn的fsimage 514 和 edits文件 515-516 远程下载到本地
3.snn将fsimage 514加载到内存中,将 edits文件 515-516 内容之内存中从头到尾的执行一次,创建一个新的fsimage文件 516
4.snn将新的fsimage 516推送给nn
5.nn接受到fsimage 516.ckpt 滚动为fsimage 516,
新的edit文件中 517.new 滚动为 edit 517
是一份最新

SNN操作流程 一般主要是面试,但是一定要了解 帮助对hdfs的底层实现基本掌握。
生产上我们是不用SNN,是用HDFS HA

NN active NN standby 热备

hadoop命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[bigdata@hadoop001 ~]$ hadoop
Usage: hadoop [--config confdir] COMMAND
where COMMAND is one of:
fs run a generic filesystem user client
version print the version
jar <jar> run a jar file
checknative [-a|-h] check native hadoop and compression libraries availability
distcp <srcurl> <desturl> copy file or directories recursively
archive -archiveName NAME -p <parent path> <src>* <dest> create a hadoop archive
classpath prints the class path needed to get the
credential interact with credential providers
Hadoop jar and the required libraries
daemonlog get/set the log level for each daemon
s3guard manage data on S3
trace view and modify Hadoop tracing settings
or
CLASSNAME run the class named CLASSNAME

Most commands print help when invoked w/o parameters.
  • 是否支持压缩

    1
    2
    3
    4
    5
    6
    7
    8
    9
    [bigdata@hadoop001 ~]$ hadoop checknative
    20/11/30 22:06:12 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
    Native library checking:
    hadoop: false
    zlib: false
    snappy: false
    lz4: false
    bzip2: false
    openssl: false

编译hadoop

https://blog.csdn.net/u010452388/article/details/99691421

  • 执行或程序抛异常,检查classpath

    1
    2
    [bigdata@hadoop001 ~]$ hadoop classpath
    /home/bigdata/app/hadoop-2.6.0-cdh5.16.2/etc/hadoop:/home/bigdata/app/hadoop-2.6.0-cdh5.16.2/share/hadoop/common/lib/*:/home/bigdata/app/hadoop-2.6.0-cdh5.16.2/share/hadoop/common/*:/home/bigdata/app/hadoop-2.6.0-cdh5.16.2/share/hadoop/hdfs:/home/bigdata/app/hadoop-2.6.0-cdh5.16.2/share/hadoop/hdfs/lib/*:/home/bigdata/app/hadoop-2.6.0-cdh5.16.2/share/hadoop/hdfs/*:/home/bigdata/app/hadoop-2.6.0-cdh5.16.2/share/hadoop/yarn/lib/*:/home/bigdata/app/hadoop-2.6.0-cdh5.16.2/share/hadoop/yarn/*:/home/bigdata/app/hadoop-2.6.0-cdh5.16.2/share/hadoop/mapreduce/lib/*:/home/bigdata/app/hadoop-2.6.0-cdh5.16.2/share/hadoop/mapreduce/*:/home/bigdata/app/hadoop/contrib/capacity-scheduler/*.jar

    http://cn.voidcc.com/question/p-tenieuea-bex.html

hdfs命令

​ hfsf dfs和hadoop fs等价

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Usage: hadoop fs [generic options]

[-cat [-ignoreCrc] <src> ...]
[-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
[-chown [-R] [OWNER][:[GROUP]] PATH...]

[-copyFromLocal [-f] [-p] [-l] <localsrc> ... <dst>] 等价于put
[-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>] 等价于get
[-put [-f] [-p] [-l] <localsrc> ... <dst>]
[-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-cp [-f] [-p | -p[topax]] <src> ... <dst>]
[-du [-s] [-h] [-x] <path> ...]

[-find <path> ... <expression> ...]

[-ls [-C] [-d] [-h] [-q] [-R] [-t] [-S] [-r] [-u] [<path> ...]]
[-mkdir [-p] <path> ...]

[-mv <src> ... <dst>] 【生产上不建议使用移动,原因是移动过程中假如有问题,会导致数据不全。建议是使用cp ,验证通过,再去删除源端】

[-rm [-f] [-r|-R] [-skipTrash] <src> ...] 【-skipTrash 不建议使用】
[-rmdir [--ignore-fail-on-non-empty] <dir> ...]

dfs管理操作

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[bigdata@hadoop001 ~]$ hdfs dfsadmin
Usage: hdfs dfsadmin
Note: Administrative commands can only be run as the HDFS superuser.
[-report [-live] [-dead] [-decommissioning]]
[-safemode <enter | leave | get | wait>] 【安全模式】
[-saveNamespace]
[-rollEdits]
[-restoreFailedStorage true|false|check]
[-refreshNodes]
[-setQuota <quota> <dirname>...<dirname>]
[-clrQuota <dirname>...<dirname>]
[-setSpaceQuota <quota> <dirname>...<dirname>]
[-clrSpaceQuota <dirname>...<dirname>]
[-finalizeUpgrade]
[-rollingUpgrade [<query|prepare|finalize>]]
[-refreshServiceAcl]
[-refreshUserToGroupsMappings]
[-refreshSuperUserGroupsConfiguration]
[-refreshCallQueue]
[-refresh <host:ipc_port> <key> [arg1..argn]
[-reconfig <datanode|...> <host:ipc_port> <start|status|properties>]
[-printTopology]
[-refreshNamenodes datanode_host:ipc_port]
[-deleteBlockPool datanode_host:ipc_port blockpoolId [force]]
[-setBalancerBandwidth <bandwidth in bytes per second>]
[-fetchImage <local directory>]
[-allowSnapshot <snapshotDir>]
[-disallowSnapshot <snapshotDir>]
[-shutdownDatanode <datanode_host:ipc_port> [upgrade]]
[-getDatanodeInfo <datanode_host:ipc_port>]
[-metasave filename]
[-triggerBlockReport [-incremental] <datanode_host:ipc_port>]
[-listOpenFiles [-blockingDecommission] [-path <path>]]
[-help [cmd]]

HA命令

1
2
3
4
5
6
7
[bigdata@hadoop001 ~]$ hdfs haadmin
Usage: DFSHAAdmin [-ns <nameserviceId>]
[-transitionToActive <serviceId> [--forceactive]]
[-transitionToStandby <serviceId>]
[-failover [--forcefence] [--forceactive] <serviceId> <serviceId>]
[-getServiceState <serviceId>]
[-checkHealth <serviceId>]

健康检查

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[bigdata@hadoop001 ~]$ hdfs fsck /
20/11/30 22:14:06 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Connecting to namenode via http://hadoop001:50070/fsck?ugi=bigdata&path=%2F
FSCK started by bigdata (auth:SIMPLE) from /172.22.212.16 for path / at Mon Nov 30 22:14:07 CST 2020
.........Status: HEALTHY
Total size: 181851 B
Total dirs: 14
Total files: 9
Total symlinks: 0
Total blocks (validated): 7 (avg. block size 25978 B)
Minimally replicated blocks: 7 (100.0 %)
Over-replicated blocks: 0 (0.0 %)
Under-replicated blocks: 0 (0.0 %)
Mis-replicated blocks: 0 (0.0 %)
Default replication factor: 1
Average block replication: 1.0
Corrupt blocks: 0
Missing replicas: 0 (0.0 %)
Number of data-nodes: 1
Number of racks: 1
FSCK ended at Mon Nov 30 22:14:07 CST 2020 in 6 milliseconds


The filesystem under path '/' is HEALTHY

安全模式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
[bigdata@hadoop001 ~]$ hdfs dfsadmin -safemode get
20/11/30 22:17:08 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Safe mode is OFF

[bigdata@hadoop001 hadoop]$ hdfs dfs -put README.txt 【写】
20/11/30 22:19:04 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

[bigdata@hadoop001 hadoop]$ hdfs dfs -ls /user/bigdata
20/11/30 22:19:43 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Found 4 items
-rw-r--r-- 1 bigdata supergroup 1366 2020-11-30 22:19 /user/bigdata/README.txt
drwxr-xr-x - bigdata supergroup 0 2020-11-28 12:14 /user/bigdata/input
drwxr-xr-x - bigdata supergroup 0 2020-11-28 12:15 /user/bigdata/output
drwxr-xr-x - bigdata supergroup 0 2020-11-28 13:28 /user/bigdata/output2
[bigdata@hadoop001 hadoop]$ hdfs dfs -cat /user/bigdata/README.txt【读】


[bigdata@hadoop001 hadoop]$ hdfs dfsadmin -safemode enter
20/11/30 22:21:24 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Safe mode is ON
[bigdata@hadoop001 hadoop]$ hdfs dfs -put NOTICE.txt
20/11/30 22:21:55 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
put: Cannot create file/user/bigdata/NOTICE.txt._COPYING_. Name node is in safe mode.

OFF 读写都OK

ON 写不行, 读OK

  • 被动–》安全模式

    未来必然hdfs查看日志出现安全模式的信息,说明你的hdfs集群是有问题的,相当于处于一个保护模式

    一般需要你尝试手动执行命令,离开安全模式 【优先操作】

  • 主动–》安全模式,做 维护操作

    这个时间段保证hdfs不会有新数据进入

回收站

1
2
3
4
5
6
7
[bigdata@hadoop001 hadoop]$ pwd
/home/bigdata/app/hadoop/etc/hadoop
[bigdata@hadoop001 hadoop]$ vi core-site.xml
<property>
<name>fs.trash.interval</name>
<value>10080</value>
</property>
1
2
3
[bigdata@hadoop001 hadoop]$ hdfs dfs -rm /user/bigdata/input/1.log
20/11/30 22:30:06 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
20/11/30 22:30:07 INFO fs.TrashPolicyDefault: Moved: 'hdfs://hadoop001:9000/user/bigdata/input/1.log' to trash at: hdfs://hadoop001:9000/user/bigdata/.Trash/Current/user/bigdata/input/1.log

【生产上必须要回收站,且回收站默认时间尽量长,7天;】
【涉及到删除,不准使用 -skipTrash,就是让文件进入回收站,以防万一 】

各个节点平衡

1
2
3
[bigdata@hadoop001 hadoop]$ start-balancer.sh 
starting balancer, logging to /home/bigdata/app/hadoop-2.6.0-cdh5.16.2/logs/hadoop-bigdata-balancer-hadoop001.out
Time Stamp Iteration# Bytes Already Moved Bytes Left To Move Bytes Being Moved

举例:

threshold = 10.0

每个节点磁盘使用率-平均磁盘使用率<10%

第一个节点 90% -76% = 14% 多了4%
第二个节点 60% -76% = -16% 少-16%
第三个节点 80% -76%= 4% 满足

230%/3=76%

【生产上,写个定时脚本,每天晚上业务低谷去执行一下】
./start-balancer.sh

参数 dfs.datanode.balance.bandwidthPerSec 10m–》50m
控制数据平衡操作的带宽大小

假如生产就3台机器 3个副本,请问这个定时脚本没有用

单个节点多块磁盘平衡

1
2
3
4
5
[bigdata@hadoop001 hadoop]$ vi hdfs-site.xml [多块磁盘时使用]
<property>
<name>dfs.datanode.data.dir </name>
<value>/data01/dfs/dn,/data02/dfs/dn,/data03/dfs/dn</value>
</property>

/data01 100G
/data02 200G
/data03 490G

1
2
3
4
5
6
7
8
9
10
11
[bigdata@hadoop001 hadoop]$ hdfs diskbalancer
usage: hdfs diskbalancer [command] [options]

DiskBalancer distributes data evenly between different disks on a
datanode. DiskBalancer operates by generating a plan, that tells datanode
how to move data between disks. Users can execute a plan by submitting it
to the datanode.
To get specific help on a particular command please run
hdfs diskbalancer -help <command>.
--help <arg> valid commands are plan | execute | query | cancel |
report

Apache hadoop2.x 没戏 不支持 dfs.disk.balancer.enabled 搜索不到
https://hadoop.apache.org/docs/r2.10.1/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml

Apache hadoop3.x 支持 dfs.disk.balancer.enabled 搜索到 是true
https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml

CDH hadoop2.x 支持 dfs.disk.balancer.enabled 搜索到 是false
http://archive.cloudera.com/cdh5/cdh/5/hadoop-2.6.0-cdh5.16.2/hadoop-project-dist/hadoop-hdfs/hdfs-default.xml

配置

1
2
3
4
<property>
<name>dfs.disk.balancer.enabled</name>
<value>true</value>
</property>
1
[bigdata@hadoop001 hadoop]$ hdfs diskbalancer -plan hadoop001

hdfs diskbalancer -execute hadoop001.plan.json 执行
hdfs diskbalancer -query hadoop001

【生产上,写个定时脚本,每日晚上业务低谷去执行一下】