一、基本概念
二、HDFS基本使用命令
hdfs dfs
Usage: hadoop fs [generic options]
[-appendToFile <localsrc> ... <dst>]
[-cat [-ignoreCrc] <src> ...]
[-checksum <src> ...]
[-chgrp [-R] GROUP PATH...]
[-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
[-chown [-R] [OWNER][:[GROUP]] PATH...]
[-copyFromLocal [-f] [-p] [-l] <localsrc> ... <dst>]
[-copyToLocal [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-count [-q] [-h] <path> ...]
[-cp [-f] [-p | -p[topax]] <src> ... <dst>]
[-createSnapshot <snapshotDir> [<snapshotName>]]
[-deleteSnapshot <snapshotDir> <snapshotName>]
[-df [-h] [<path> ...]]
[-du [-s] [-h] <path> ...]
[-expunge]
[-find <path> ... <expression> ...]
[-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst>]
[-getfacl [-R] <path>]
[-getfattr [-R] {-n name | -d} [-e en] <path>]
[-getmerge [-nl] <src> <localdst>]
[-help [cmd ...]]
[-ls [-d] [-h] [-R] [<path> ...]]
[-mkdir [-p] <path> ...]
[-moveFromLocal <localsrc> ... <dst>]
[-moveToLocal <src> <localdst>]
[-mv <src> ... <dst>]
[-put [-f] [-p] [-l] <localsrc> ... <dst>]
[-renameSnapshot <snapshotDir> <oldName> <newName>]
[-rm [-f] [-r|-R] [-skipTrash] <src> ...]
[-rmdir [--ignore-fail-on-non-empty] <dir> ...]
[-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>]]
[-setfattr {-n name [-v value] | -x name} <path>]
[-setrep [-R] [-w] <rep> <path> ...]
[-stat [format] <path> ...]
[-tail [-f] <file>]
[-test -[defsz] <path>]
[-text [-ignoreCrc] <src> ...]
[-touchz <path> ...]
[-truncate [-w] <length> <path> ...]
[-usage [cmd ...]]
(1)hdfs命令行
(1)查看帮助
hdfs dfs -help
(2)查看当前目录信息
hdfs dfs -ls /
(3)上传文件
hdfs dfs -put /本地路径 /hdfs路径
(4)剪切文件
hdfs dfs -moveFromLocal a.txt /aa.txt
(5)下载文件到本地
hdfs dfs -get /hdfs路径 /本地路径
(6)合并下载
hdfs dfs -getmerge /hdfs路径文件夹 /合并后的文件
(7)创建文件夹
hdfs dfs -mkdir /hello
(8)创建多级文件夹
hdfs dfs -mkdir -p /hello/world
(9)移动hdfs文件
hdfs dfs -mv /hdfs路径 /hdfs路径
(10)复制hdfs文件
hdfs dfs -cp /hdfs路径 /hdfs路径
(11)删除hdfs文件
hdfs dfs -rm /aa.txt
(12)删除hdfs文件夹
hdfs dfs -rm -r /hello
(13)查看hdfs中的文件
hdfs dfs -cat /文件
hdfs dfs -tail -f /文件
(14)查看文件夹中有多少个文件
hdfs dfs -count /文件夹
(15)查看hdfs的总空间
hdfs dfs -df /
hdfs dfs -df -h /
(16)修改副本数
hdfs dfs -setrep 3 /a.txt
(17)查看文件的统计信息
hdfs dfs -stat /1.txt
hdfs dfs -stat "%o %r" /1.txt
hdfs dfs -stat [format] path
不加任何的format,默认显示文件的创建时间
format:
%b:打印文件的大小
%n:打印文件名
%o:打印block size的值
%r:打印副本数
%y:打印UTC的时间
%Y:打印从1970年以来的UTC的微秒数
%F:如果是目录打印directory,文件则打印regular file
(17)tail
将文件大小尾部1k字节的内容输出到控制台,支持-f选项
(18)test
测试检查目录或者文件是否存在
-e:检查文件是否存在
-z:检查文件是否为0字节
-d:检查路径是否为目录
(19)text
将文本文件或者某些格式的非文件通过文本格式输出,婿的格式是zip和TextRecordOutputStream
(20)distcp
HDFS集群的数据迁移解决方案,利用distcp在hdfs之间传输数据
hadoop distcp -overwrite hdfs://host01:9000/input hdfs://host02:9000/
hadoop的垃圾回收站
在core-site.xml里添加配置fs.trash.interval
恢复数据则利用命令mv
expunge:清空垃圾回收站
(2)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> [-storageType <storagetype>] <dirname>...<dirname>]
[-clrSpaceQuota [-storageType <storagetype>] <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>]
[-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>]
[-help [cmd]]
-
查看系统报告
hdfs dfs -report -
查看日志
(1)日志的位置
[root@host01 current]# cd $HADOOP_HOME/logs
[root@host01 logs]# pwd
/usr/local/hadoop-2.7.6/logs
在host01的日志应该在host01上看日志,host02的应该在host02上看,哪个节点出问题就看哪个日志
日志格式:所属集群 所属集群 当前用户 组件 主机名.log
hadoop|yarn
eg:hadoop-root-datanode-host01.log
查看方式:less
tail直接跟踪启动过程
-
java的错误
主要看cause by这块 -
一些其他的操作
1.时间同步:date -s""
2.配置时间服务器,其他节点都同步服务器的时间 -namenode
三、解决安全模式3种办法
安全模式已经启动的提示:
Safe mode is ON. The reported blocks 0 needs additional 26 blocks to reach the threshold 0.9990 of total blocks 26.
The number of live datanodes 3 has reached the minimum number 0.
Safe mode will be turned off automatically once the thresholds have been reached.
1、暴力解决。重新初始化
2、调整这个参数的大小
<property>
<name>dfs.namenode.safemode.threshold-pct</name>
<value>0.999f</value>
<description>
Specifies the percentage of blocks that should satisfy
the minimal replication requirement defined by dfs.namenode.replication.min.
Values less than or equal to 0 mean not to wait for any particular
percentage of blocks before exiting safemode.
Values greater than 1 will make safe mode permanent.
</description>
</property>
3、
使用命令强制退出安全模式
hdfs dfsadmin -safemode leave
使用命令检查hdfs的磁盘错误并删除错误文件
hdfs fsck /
hdfs fsck / -delete ## 删除损坏的block
也可以使用linux中的fsck工具来处理