[TOC]
灵魂拷问:你真的理解distcp吗?这里说的就是distcp的那点事
背景
明天在整顿笔记的时候,发现了好几篇长期记录都是记录的集群间文件复制须要留神的中央,尽管记录的货色和重点不同,然而外围的货色都是distcp相干的,所以,感觉还是有点必要归总一下,这篇文章的内容次要是一点细节问题,更多的是偏重在遇到疑难的时候如何疾速去找到本人的答案
参考地址
概述
首先,distcp是个什么货色呢,从字面意思来说就是 distributed copy(分布式拷贝)
,也就是说将原来以一个人做的事件,摊派给很多人来并行处理,当然这个工作分工的粒度是基于文件的,也就是说只有一个文件,那么这个拷贝最多也就只能一个人来实现
根本用法
# 能够应用hdfs协定(同版本hadoop),也能够是用hftp协定(不同版本hadoop可用)hadoop distcp hdfs://nn1:8020/foo/bar hdfs://nn2:8020/bar/foo# 同时能够指定多个数据源进行拷贝hadoop distcp hdfs://nn1:8020/foo/bar1 hdfs://nn2:8020/foo/bar2 hdfs://nn3:8020/bar/foo# 也能够应用 -f ,字面意思就是 -file也就是我的数据源source是以绝对路径模式列表存储一个文件中
参数阐明
这里就不一一翻译每一个参数的中文意思,根本都能直译是什么意思,这里次要说一下我感觉应用上可能须要留神的细节问题
[yourFather@hadoop-onedata ~]$ hadoop distcp --helpusage: distcp OPTIONS [source_path...] <target_path> OPTIONS -append Reuse existing data in target files and append new data to them if possible -async Should distcp execution be blocking -atomic Commit all changes or none -bandwidth <arg> Specify bandwidth per map in MB -delete Delete from target, files missing in source -diff <arg> Use snapshot diff report to identify the difference between source and target -f <arg> List of files that need to be copied -filelimit <arg> (Deprecated!) Limit number of files copied to <= n -i Ignore failures during copy -log <arg> Folder on DFS where distcp execution logs are saved -m <arg> Max number of concurrent maps to use for copy -mapredSslConf <arg> Configuration for ssl config file, to use with hftps:// -overwrite Choose to overwrite target files unconditionally, even if they exist. -p <arg> preserve status (rbugpcaxt)(replication, block-size, user, group, permission, checksum-type, ACL, XATTR, timestamps). If -p is specified with no <arg>, then preserves replication, block size, user, group, permission, checksum type and timestamps. raw.* xattrs are preserved when both the source and destination paths are in the /.reserved/raw hierarchy (HDFS only). raw.* xattrpreservation is independent of the -p flag. Refer to the DistCp documentation for more details. -sizelimit <arg> (Deprecated!) Limit number of files copied to <= n bytes -skipcrccheck Whether to skip CRC checks between source and target paths. -strategy <arg> Copy strategy to use. Default is dividing work based on file sizes -tmp <arg> Intermediate work path to be used for atomic commit -update Update target, copying only missingfiles or directories
- --append,--overwrite,--update之间的关系
参数 | 解释 | 备注 |
---|---|---|
append | 追加,复用sink文件曾经存在的数据,并尝试将数据追加,判断规范TODO | |
overwrite | 笼罩,不论之前是否存在是从新生成 | |
update | 更新,判断规范是source和sink文件大小是否统一 |
- -m
这个很好解释,应为distcp应用的是mapreduce模型,和sqoop有点相似,所以-m就是-map,说的就是并行度,启动最多
多少个map来同时拷贝,为什么说最多呢,因为拷贝是基于文件的(严格来说应该是block),一个文件拆成多份拷贝的难度必定要略微大一点,所以如果source只有一个文件,那么-m指定多少个,也都只会有一个map task执行拷贝工作
- -i
疏忽失败,就是如果拷贝工作比拟重,资源缓和时很有可能会中途失败啥的,然而又不像每次重启工作从新全量拷贝,这里能够思考疏忽失败,后续执行的时候的再增量拷贝
- -strategy
拷贝策略问题,默认是依照文件的大小进行工作的拆分,可选参数为dynamic|uniform
,默认是每个拷贝工作拷贝雷同的字节数
- -p
字面意思就是保留到指标零碎中文件的status,包含正本、block大小、用户权限等,当然默认必定是和指标零碎保持一致
- -bandwidth
很显著,就是带宽大小,因为distcp没有计算逻辑,属于io密集型工作,集群迁徙的时候须要对带宽的应用有严格的把控,这个参数就是管制map的应用带宽,那么限度distcp工作个数以及distcp工作的map个数即可管制整体迁徙程序的带宽应用
QA
这里记录的是我在应用的时候遇到的小问题,并不一定是什么原理优化的问题,就是应用上可能会产生疑难或者歧义的中央
Q1:如果拷贝的时候,数据呈现抵触,会有什么后果?
A1:如果soure呈现同名文件,distcp工作会产生失败并打印出错日志;如果目标目录曾经存在待拷贝的文件,默认会疏忽掉源文件的拷贝工作,当然也能够设置报错;如果有另外的过程向指标文件中写数据也会报错并打印日志
Q2:distcp的工作部署地位有要求吗?
A2:只要求运行distcp工作的节点或者说task可能和上下游进行拜访交互即可,并不要求部署的地位,理论状况个别部署在指标集群的节点上
Q3:distcp工作在做大数据迁徙的时候须要留神什么?
A3:distcp工作是大io的工作,所以带宽是限度因素,能够写一个监控集群机器带宽(shell/python尤佳)的脚本,而后在闲暇工夫去启动迁徙工作
附录
# 样例1:复制目录的时候上游会主动生成目录,无需手动增加,如下time hadoop distcp hdfs://nn1:8020/user/hive/warehouse/${database}.db/${table}/dt=${partition} hdfs://nn2:8020/user/hive/warehouse/${database}.db/${table} >> /logs/distcp/${database}.log# 样例2:多参数的拷贝hadoop distcp \ -Dmapred.jobtracker.maxtasks.per.job=1800000 \ #工作最大map数(数据分成多map工作) -Dmapred.job.max.map.running=4000 \ #最大map并发 -Ddistcp.bandwidth=150000000 \ #带宽 -Ddfs.replication=2 \ #复制因子,两正本 -Ddistcp.skip.dir=$skipPath \ #过滤的目录(不拷贝的目录) -Dmapred.map.max.attempts=9 \ #每个task最大尝试次数 -Dmapred.fairscheduler.pool=distcp \ #指定工作运行的pool -pugp \ #保留属性(用户,组,权限) -i \ #疏忽失败的task -skipcrccheck \ #疏忽CRC校验(避免源,指标集群hdfs版本不统一导致工作失败。) hdfs://clusterA:9000/AAA/data \ #源地址 hdfs://clusterB:9000/BBB/data #指标地址 # 样例3:跨版本的拷贝,参数和dfs.http.address保持一致hadoop distcp -numListstatusThreads 40 -update -delete -prbugpaxtq hftp://nn1:50070/source hdfs://cluster2/target
参考链接:
- hadoop迁徙
- 分布式拷贝
记录稍显仓促,如有谬误,请不吝指正