博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hadoop集群之间的hdfs文件拷贝
阅读量:7103 次
发布时间:2019-06-28

本文共 3065 字,大约阅读时间需要 10 分钟。

hot3.png

1、背景

部门有个需求,在网络互通的情况下,把现有的hadoop集群(未做Kerberos认证,集群名为:bd-stg-hadoop)的一些hdfs文件拷贝到新的hadoop集群(做了Kerberos认证,集群名为zp-tt-hadoop)

如果是两个都没有做安全认证的集群互传文件,使用distcp可以很快实现。通过查阅资料,在cdh的官网上竟然有这么神奇的一个参数可以解决这么一个奇葩的需求。传送门:http://www.cloudera.com/documentation/enterprise/5-5-x/topics/cdh_admin_distcp_secure_insecure.html

2、实现

2.1 Copying Data between two Insecure cluster

两个都没有做安全认证的集群,通常方法如下:

$ hadoop distcp hdfs://nn1:8020/foo/bar hdfs://nn2:8020/bar/foo

也可以通过webhdfs的方式:

$ hadoop distcp webhdfs://nn1:8020/foo/bar  webhdfs://nn2:8020/bar/foo

对于不同Hadoop版本间的拷贝,用户应该使用HftpFileSystem。 这是一个只读文件系统,所以DistCp必须运行在目标端集群上。 源的格式是 hftp://<dfs.http.address>/<path> (默认情况dfs.http.address是 <namenode>:50070)。

distcp的一些参数如下:

-i:忽略失败(不建议开启)-log 
:记录日志到
-m
:同时拷贝的最大数目(指定了拷贝数据时map的数目。请注意并不是map数越多吞吐量越大。)-overwrite:覆盖目标(如果一个map失败并且没有使用-i选项,不仅仅那些拷贝失败的文件,这个分块任务中的所有文件都会被重新拷贝。 就像下面提到的,它会改变生成目标路径的语义,所以 用户要小心使用这个选项。)-update:如果源和目标的大小不一样则进行覆盖-f
:使用
作为源文件列表

2.2 Copying Data between a Secure and an Insecure

在secure-cluster上的core-site.xml配置文件中添加:

ipc.client.fallback-to-simple-auth-allowed
true

然后在secure-cluster执行如下命令:

distcp webhdfs://insecureCluster webhdfs://secureCluster distcp webhdfs://secureCluster webhdfs://insecureCluster

在我实际操作过程中,两个集群都有做ha,使用上面的命令会报错:

16/09/27 14:47:52 ERROR tools.DistCp: Exception encountered java.lang.IllegalArgumentException: java.net.UnknownHostException: bd-stg-hadoop	at org.apache.hadoop.security.SecurityUtil.buildTokenService(SecurityUtil.java:374)	at org.apache.hadoop.security.SecurityUtil.buildTokenService(SecurityUtil.java:392)	at org.apache.hadoop.hdfs.web.WebHdfsFileSystem.initialize(WebHdfsFileSystem.java:167)	at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:2643)	at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:93)	at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:2680)	at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:2662)	at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:379)	at org.apache.hadoop.fs.Path.getFileSystem(Path.java:296)	at org.apache.hadoop.tools.GlobbedCopyListing.doBuildListing(GlobbedCopyListing.java:76)	at org.apache.hadoop.tools.CopyListing.buildListing(CopyListing.java:86)	at org.apache.hadoop.tools.DistCp.createInputFileListing(DistCp.java:365)	at org.apache.hadoop.tools.DistCp.execute(DistCp.java:171)	at org.apache.hadoop.tools.DistCp.run(DistCp.java:122)	at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70)	at org.apache.hadoop.tools.DistCp.main(DistCp.java:429)Caused by: java.net.UnknownHostException: bd-stg-hadoop

解决如下:

把bd-stg-hadoop集群名字改成了active-namenode的host再进行操作,如下:

$ hadoop distcp webhdfs://bd-stg-namenode-138/tmp/hivebackup/app/app_stg_session webhdfs://zp-tt-hadoop:8020/tmp/hivebackup/app/app_stg_session

成功执行后, 可以发现原理就是启动一个只有map的MapReduce作业来实现两个集群间的数据复制。

2.3 Copying Data between two Secure cluster

这种情况相对有些复杂了,需要Kerberos做跨域的配置。本文暂不研究讨论。

转载于:https://my.oschina.net/Yumikio/blog/752319

你可能感兴趣的文章
我的友情链接
查看>>
[转载] Beyond-海阔天空
查看>>
[转载] Intention scheduling for BDI agent systems
查看>>
centOS普通用户ssh失败
查看>>
TinyOS、NesC程序开发经验谈
查看>>
IO流,对象序列化
查看>>
程序员的运动乐趣
查看>>
在阿里云上开放Redis默认的6379端口
查看>>
护照申办证明
查看>>
搜索引擎优化最为关键的七个地方
查看>>
sudo详解
查看>>
nginx启动 停止 重启等 管理脚本
查看>>
ubuntu12.04 安装BeautifulSoup遇到的问题
查看>>
Java删除文件夹和文件
查看>>
docker学习系列一:初识docker
查看>>
如何修改ssh的端口号?
查看>>
我的友情链接
查看>>
mysql binlog配置
查看>>
使用正则表达式匹配嵌套Html标签
查看>>
书摘---创业36条军规8:资本的五个问题
查看>>