如果您需要将自有 HDFS 的原始数据迁移至腾讯云 EMR,可以通过两种方式进行数据迁移,第一种是通过腾讯云对象存储(COS)进行数据中转迁移,第二种是通过 Hadoop 自带文件迁移工具 DistCp 进行数据迁移。本文主要介绍通过腾讯云对象存储(COS)进行数据中转迁移。
如果您的原始数据不是 HDFS 数据而是其他形式的文件数据,可以通过 COS 的 web 控制台或者 COS 提供的 API 来把数据传入到 COS,然后在 EMR 集群中进行分析,COS 传输数据请查看资料。
工具配置。
配置文件统一放在工具目录里的 conf 目录,将需要同步的 HDFS 集群的 core-site.xml 拷贝到 conf 中,其中包含了 NameNode 的配置信息,编辑配置文件 cos_info.conf,包括 appid、bucket、region 以及密钥信息。
注意:
命令参数说明:
-ak <ak> the cos secret id //用户的 SecretId,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参考:https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1
-appid,--appid <appid> the cos appid
-bucket,--bucket <bucket_name> the cos bucket name
-cos_info_file,--cos_info_file <arg> the cos user info config default is ./conf/cos_info.conf
-cos_path,--cos_path <cos_path> the absolute cos folder path
-h,--help print help message
-hdfs_conf_file,--hdfs_conf_file <arg> the hdfs info config default is ./conf/core-site.xml
-hdfs_path,--hdfs_path <hdfs_path> the hdfs path
-region,--region <region> the cos region. legal value cn-south, cn-east, cn-north, sg
-sk <sk> the cos secret key //用户的 SecretKey,建议使用子账号密钥,授权遵循最小权限指引,降低使用风险。子账号密钥获取可参考:https://www.tencentcloud.com/document/product/598/37140?from_cn_redirect=1
-skip_if_len_match,--skip_if_len_match skip upload if hadoop file length match cos
执行迁移:
# 所有操作都要在工具目录下。如果同时设置了配置文件和命令行参数,以命令行参数为准
./hdfs_to_cos_cmd -h
# 从 HDFS 拷贝到 COS(如果 COS 上已存在文件,则会覆盖)
./hdfs_to_cos_cmd --hdfs_path=/tmp/hive --cos_path=/hdfs/20170224/
# 从 HDFS 拷贝到 COS,同时要拷贝的文件和 COS 的长度一致,则忽略上传(适用于拷贝一次后,重新拷贝)
# 这里只做长度的判断,因为如果将 Hadoop 上的文件摘要算出,开销较大
./hdfs_to_cos_cmd --hdfs_path=/tmp/hive --cos_path=/hdfs/20170224/ -skip_if_len_match
# 完全通过命令行设置参数
./hdfs_to_cos_cmd -appid 1252xxxxxx -ak
AKIDVt55xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx -sk
KS08jDVbVElxxxxxxxxxxxxxxxxxxxxxxxxxx -bucket test -cos_path /hdfs
-hdfs_path /data/data -region cn-south -hdfs_conf_file
/home/hadoop/hadoop-2.8.1/etc/hadoop/core-site.xml
验证运行命令后,输出如下日志::
[Folder Operation Result : [ 53(sum)/ 53(ok) / 0(fail)]]
[File Operation Result: [22(sum)/ 22(ok) / 0(fail) / 0(skip)]]
[Used Time: 3 s]
您也可以登录 COS 控制台查看数据是否已经正确迁移过来。对象存储使用指引请参见 快速入门。
本页内容是否解决了您的问题?