Apache Hadoop 2.7如何支持读写OSS

本文涉及的产品
对象存储 OSS,20GB 3个月
日志服务 SLS,月写入数据量 50GB 1个月
云备份 Cloud Backup,100GB 3个月
简介: 背景 2017.12.13日Apache Hadoop 3.0.0正式版本发布,默认支持阿里云OSS对象存储系统,作为Hadoop兼容的文件系统,后续版本号大于等于Hadoop 2.9.x系列也支持OSS。

背景

2017.12.13日Apache Hadoop 3.0.0正式版本发布,默认支持阿里云OSS对象存储系统,作为Hadoop兼容的文件系统,后续版本号大于等于Hadoop 2.9.x系列也支持OSS。然而,低版本的Apache Hadoop官方不再支持OSS,本文将描述如何通过支持包来使Hadoop 2.7.2能够读写OSS。

如何使用

下面的步骤需要在所有的Hadoop节点执行

下载支持包

http://gosspublic.alicdn.com/hadoop-spark/hadoop-oss-2.7.2.tar.gz

解压这个支持包,里面的文件是:

[root@apache hadoop-oss-2.7.2]# ls -lh
总用量 3.1M
-rw-r--r-- 1 root root 3.1M 2月  28 17:01 hadoop-aliyun-2.7.2.jar

这个支持包是根据Hadoop 2.7.2的版本,并打了Apache Hadoop对OSS支持的patch后编译得到,其他的小版本对OSS的支持后续也将陆续提供。

部署

首先将文件hadoop-aliyun-2.7.2.jar复制到$HADOOP_HOME/share/hadoop/tools/lib/目录下;

修改​​$HADOOP_HOME/libexec/hadoop-config.sh文件,在文件的327行加下代码:

CLASSPATH=$CLASSPATH:$TOOL_PATH

修改的目的就是将$HADOOP_HOME/share/hadoop/tools/lib/放到Hadoop的CLASSPATH里面;下面是修改前后,这个文件的diff供参考(hadoop-config.sh.bak是修改前的文件):

[root@apache hadoop-2.7.2]# diff -C 3 libexec/hadoop-config.sh.bak libexec/hadoop-config.sh
*** libexec/hadoop-config.sh.bak    2019-03-01 10:35:59.629136885 +0800
--- libexec/hadoop-config.sh    2019-02-28 16:33:39.661707800 +0800
***************
*** 325,330 ****
--- 325,332 ----
  CLASSPATH=${CLASSPATH}:$HADOOP_MAPRED_HOME/$MAPRED_DIR'/*'
fi

+ CLASSPATH=$CLASSPATH:$TOOL_PATH
+
# Add the user-specified CLASSPATH via HADOOP_CLASSPATH
# Add it first or last depending on if user has
# set env-var HADOOP_USER_CLASSPATH_FIRST

增加OSS的配置

修改core-site.xml文件,增加如下配置项:

配置项 说明
fs.oss.endpoint 如 oss-cn-zhangjiakou-internal.aliyuncs.com 要连接的endpoint
fs.oss.accessKeyId access key id
fs.oss.accessKeySecret access key secret
fs.oss.impl org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystem hadoop oss文件系统实现类,目前固定为这个
fs.oss.buffer.dir /tmp/oss 临时文件目录
fs.oss.connection.secure.enabled false 是否enable https, 根据需要来设置,enable https会影响性能
fs.oss.connection.maximum 2048 与oss的连接数,根据需要设置

相关参数的解释可以在这里找到

重启集群,验证读写OSS

增加配置后,重启集群,重启后,可以测试

# 测试写
hadoop fs -mkdir oss://{your-bucket-name}/hadoop-test
# 测试读
hadoop fs -ls oss://{your-bucket-name}/

运行teragen

[root@apache hadoop-2.7.2]# hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar teragen -Dmapred.map.tasks=100 10995116 oss://{your-bucket-name}/1G-input
19/02/28 16:38:59 INFO client.RMProxy: Connecting to ResourceManager at apache/192.168.0.176:8032
19/02/28 16:39:01 INFO terasort.TeraSort: Generating 10995116 using 100
19/02/28 16:39:01 INFO mapreduce.JobSubmitter: number of splits:100
19/02/28 16:39:01 INFO Configuration.deprecation: mapred.map.tasks is deprecated. Instead, use mapreduce.job.maps
19/02/28 16:39:01 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1551343125387_0001
19/02/28 16:39:02 INFO impl.YarnClientImpl: Submitted application application_1551343125387_0001
19/02/28 16:39:02 INFO mapreduce.Job: The url to track the job: http://apache:8088/proxy/application_1551343125387_0001/
19/02/28 16:39:02 INFO mapreduce.Job: Running job: job_1551343125387_0001
19/02/28 16:39:09 INFO mapreduce.Job: Job job_1551343125387_0001 running in uber mode : false
19/02/28 16:39:09 INFO mapreduce.Job:  map 0% reduce 0%
19/02/28 16:39:18 INFO mapreduce.Job:  map 1% reduce 0%
19/02/28 16:39:19 INFO mapreduce.Job:  map 2% reduce 0%
19/02/28 16:39:21 INFO mapreduce.Job:  map 4% reduce 0%
19/02/28 16:39:25 INFO mapreduce.Job:  map 5% reduce 0%
19/02/28 16:39:28 INFO mapreduce.Job:  map 6% reduce 0%
......
19/02/28 16:42:36 INFO mapreduce.Job:  map 94% reduce 0%
19/02/28 16:42:38 INFO mapreduce.Job:  map 95% reduce 0%
19/02/28 16:42:41 INFO mapreduce.Job:  map 96% reduce 0%
19/02/28 16:42:44 INFO mapreduce.Job:  map 97% reduce 0%
19/02/28 16:42:45 INFO mapreduce.Job:  map 98% reduce 0%
19/02/28 16:42:46 INFO mapreduce.Job:  map 99% reduce 0%
19/02/28 16:42:48 INFO mapreduce.Job:  map 100% reduce 0%
19/02/28 16:43:11 INFO mapreduce.Job: Job job_1551343125387_0001 completed successfully
19/02/28 16:43:12 INFO mapreduce.Job: Counters: 37
    File System Counters
        FILE: Number of bytes read=0
        FILE: Number of bytes written=11931190
        FILE: Number of read operations=0
        FILE: Number of large read operations=0
        FILE: Number of write operations=0
        HDFS: Number of bytes read=8497
        HDFS: Number of bytes written=0
        HDFS: Number of read operations=100
        HDFS: Number of large read operations=0
        HDFS: Number of write operations=0
        OSS: Number of bytes read=0
        OSS: Number of bytes written=1099511600
        OSS: Number of read operations=1100
        OSS: Number of large read operations=0
        OSS: Number of write operations=500
......

运行distcp

从OSS往HDFS拷贝数据

[root@apache hadoop-2.7.2]# hadoop distcp oss://{your-bucket-name}/data hdfs:/data/input
19/03/05 09:43:59 INFO tools.DistCp: Input Options: DistCpOptions{atomicCommit=false, syncFolder=false, deleteMissing=false, ignoreFailures=false, maxMaps=20, sslConfigurationFile='null', copyStrategy='uniformsize', sourceFileListing=null, sourcePaths=[oss://{your-bucket-name}/data], targetPath=hdfs:/data/input, targetPathExists=false, preserveRawXattrs=false}
19/03/05 09:43:59 INFO client.RMProxy: Connecting to ResourceManager at apache/192.168.0.176:8032
19/03/05 09:44:00 INFO Configuration.deprecation: io.sort.mb is deprecated. Instead, use mapreduce.task.io.sort.mb
19/03/05 09:44:00 INFO Configuration.deprecation: io.sort.factor is deprecated. Instead, use mapreduce.task.io.sort.factor
19/03/05 09:44:01 INFO client.RMProxy: Connecting to ResourceManager at apache/192.168.0.176:8032
19/03/05 09:44:01 INFO mapreduce.JobSubmitter: number of splits:24
19/03/05 09:44:01 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1551343125387_0008
19/03/05 09:44:01 INFO impl.YarnClientImpl: Submitted application application_1551343125387_0008
19/03/05 09:44:01 INFO mapreduce.Job: The url to track the job: http://apache:8088/proxy/application_1551343125387_0008/
19/03/05 09:44:01 INFO tools.DistCp: DistCp job-id: job_1551343125387_0008
19/03/05 09:44:01 INFO mapreduce.Job: Running job: job_1551343125387_0008
19/03/05 09:44:07 INFO mapreduce.Job: Job job_1551343125387_0008 running in uber mode : false
19/03/05 09:44:07 INFO mapreduce.Job:  map 0% reduce 0%
19/03/05 09:44:16 INFO mapreduce.Job:  map 4% reduce 0%
19/03/05 09:44:19 INFO mapreduce.Job:  map 8% reduce 0%
......
19/03/05 09:45:11 INFO mapreduce.Job:  map 96% reduce 0%
19/03/05 09:45:12 INFO mapreduce.Job:  map 100% reduce 0%
19/03/05 09:45:13 INFO mapreduce.Job: Job job_1551343125387_0008 completed successfully
19/03/05 09:45:13 INFO mapreduce.Job: Counters: 38
    File System Counters
        FILE: Number of bytes read=0
        FILE: Number of bytes written=2932262
        FILE: Number of read operations=0
        FILE: Number of large read operations=0
        FILE: Number of write operations=0
        HDFS: Number of bytes read=24152
        HDFS: Number of bytes written=1099511600
        HDFS: Number of read operations=898
        HDFS: Number of large read operations=0
        HDFS: Number of write operations=251
        OSS: Number of bytes read=1099511600
        OSS: Number of bytes written=0
        OSS: Number of read operations=2404
        OSS: Number of large read operations=0
        OSS: Number of write operations=0
......

[root@apache hadoop-2.7.2]# hadoop fs -ls hdfs:/data
Found 1 items
drwxr-xr-x   - root supergroup          0 2019-03-05 09:45 hdfs:///data/input

从HDFS往OSS拷贝数据

[root@apache hadoop-2.7.2]# hadoop distcp hdfs:/data/input oss://{your-bucket-name}/data/output
19/03/05 09:48:06 INFO tools.DistCp: Input Options: DistCpOptions{atomicCommit=false, syncFolder=false, deleteMissing=false, ignoreFailures=false, maxMaps=20, sslConfigurationFile='null', copyStrategy='uniformsize', sourceFileListing=null, sourcePaths=[hdfs:/data/input], targetPath=oss://{your-bucket-name}/data/output, targetPathExists=false, preserveRawXattrs=false}
19/03/05 09:48:06 INFO client.RMProxy: Connecting to ResourceManager at apache/192.168.0.176:8032
19/03/05 09:48:06 INFO Configuration.deprecation: io.sort.mb is deprecated. Instead, use mapreduce.task.io.sort.mb
19/03/05 09:48:06 INFO Configuration.deprecation: io.sort.factor is deprecated. Instead, use mapreduce.task.io.sort.factor
19/03/05 09:48:07 INFO client.RMProxy: Connecting to ResourceManager at apache/192.168.0.176:8032
19/03/05 09:48:07 INFO mapreduce.JobSubmitter: number of splits:24
19/03/05 09:48:08 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1551343125387_0009
19/03/05 09:48:08 INFO impl.YarnClientImpl: Submitted application application_1551343125387_0009
19/03/05 09:48:08 INFO mapreduce.Job: The url to track the job: http://apache:8088/proxy/application_1551343125387_0009/
19/03/05 09:48:08 INFO tools.DistCp: DistCp job-id: job_1551343125387_0009
19/03/05 09:48:08 INFO mapreduce.Job: Running job: job_1551343125387_0009
19/03/05 09:48:14 INFO mapreduce.Job: Job job_1551343125387_0009 running in uber mode : false
19/03/05 09:48:14 INFO mapreduce.Job:  map 0% reduce 0%
19/03/05 09:48:24 INFO mapreduce.Job:  map 4% reduce 0%
19/03/05 09:48:27 INFO mapreduce.Job:  map 8% reduce 0%
......
19/03/05 09:49:18 INFO mapreduce.Job:  map 92% reduce 0%
19/03/05 09:49:20 INFO mapreduce.Job:  map 96% reduce 0%
19/03/05 09:49:21 INFO mapreduce.Job:  map 100% reduce 0%
19/03/05 09:49:22 INFO mapreduce.Job: Job job_1551343125387_0009 completed successfully
19/03/05 09:49:22 INFO mapreduce.Job: Counters: 38
    File System Counters
        FILE: Number of bytes read=0
        FILE: Number of bytes written=2932910
        FILE: Number of read operations=0
        FILE: Number of large read operations=0
        FILE: Number of write operations=0
        HDFS: Number of bytes read=1099535478
        HDFS: Number of bytes written=0
        HDFS: Number of read operations=548
        HDFS: Number of large read operations=0
        HDFS: Number of write operations=48
        OSS: Number of bytes read=0
        OSS: Number of bytes written=1099511600
        OSS: Number of read operations=1262
        OSS: Number of large read operations=0
        OSS: Number of write operations=405
......

[root@apache hadoop-2.7.2]# hadoop fs -ls oss://{your-bucket-name}/data/output
Found 101 items
-rw-rw-rw-   1 root root          0 2019-03-05 09:48 oss://{your-bucket-name}/data/output/_SUCCESS
-rw-rw-rw-   1 root root   10995200 2019-03-05 09:48 oss://{your-bucket-name}/data/output/part-m-00000
-rw-rw-rw-   1 root root   10995100 2019-03-05 09:48 oss://{your-bucket-name}/data/output/part-m-00001
......

参考链接

https://yq.aliyun.com/articles/292792?spm=a2c4e.11155435.0.0.7ccba82fbDwfhK

https://github.com/apache/hadoop/blob/trunk/hadoop-tools/hadoop-aliyun/src/site/markdown/tools/hadoop-aliyun/index.md

相关实践学习
借助OSS搭建在线教育视频课程分享网站
本教程介绍如何基于云服务器ECS和对象存储OSS,搭建一个在线教育视频课程分享网站。
目录
相关文章
|
7月前
|
敏捷开发 测试技术 持续交付
云效产品使用常见问题之账号授权就能对当前主账号下所有 OSS 进行读写权限如何解决
云效作为一款全面覆盖研发全生命周期管理的云端效能平台,致力于帮助企业实现高效协同、敏捷研发和持续交付。本合集收集整理了用户在使用云效过程中遇到的常见问题,问题涉及项目创建与管理、需求规划与迭代、代码托管与版本控制、自动化测试、持续集成与发布等方面。
|
4月前
|
消息中间件 分布式计算 Hadoop
Apache Flink 实践问题之Flume与Hadoop之间的物理墙问题如何解决
Apache Flink 实践问题之Flume与Hadoop之间的物理墙问题如何解决
64 3
|
2月前
|
分布式计算 Hadoop 网络安全
Hadoop-08-HDFS集群 基础知识 命令行上机实操 hadoop fs 分布式文件系统 读写原理 读流程与写流程 基本语法上传下载拷贝移动文件
Hadoop-08-HDFS集群 基础知识 命令行上机实操 hadoop fs 分布式文件系统 读写原理 读流程与写流程 基本语法上传下载拷贝移动文件
44 1
|
2月前
|
存储 机器学习/深度学习 缓存
Hadoop-07-HDFS集群 基础知识 分布式文件系统 读写原理 读流程与写流程 基本语法上传下载拷贝移动文件
Hadoop-07-HDFS集群 基础知识 分布式文件系统 读写原理 读流程与写流程 基本语法上传下载拷贝移动文件
57 1
|
2月前
|
存储 分布式计算 大数据
大数据-145 Apache Kudu 架构解读 Master Table 分区 读写
大数据-145 Apache Kudu 架构解读 Master Table 分区 读写
51 0
|
4月前
|
存储 分布式计算 Hadoop
【揭秘Hadoop背后的秘密!】HDFS读写流程大曝光:从理论到实践,带你深入了解Hadoop分布式文件系统!
【8月更文挑战第24天】Hadoop分布式文件系统(HDFS)是Hadoop生态系统的关键组件,专为大规模数据集提供高效率存储及访问。本文深入解析HDFS数据读写流程并附带示例代码。HDFS采用NameNode和DataNode架构,前者负责元数据管理,后者承担数据块存储任务。文章通过Java示例演示了如何利用Hadoop API实现数据的写入与读取,有助于理解HDFS的工作原理及其在大数据处理中的应用价值。
123 1
|
4月前
|
分布式计算 Hadoop 大数据
大数据处理框架在零售业的应用:Apache Hadoop与Apache Spark
【8月更文挑战第20天】Apache Hadoop和Apache Spark为处理海量零售户数据提供了强大的支持
78 0
|
6月前
|
分布式计算 Hadoop
关于hadoop搭建的问题org.apache.hadoop.io.nativeio.NativeIO.java
关于hadoop搭建的问题org.apache.hadoop.io.nativeio.NativeIO.java
80 5
|
6月前
|
存储 分布式计算 Hadoop
使用Apache Hadoop进行分布式计算的技术详解
【6月更文挑战第4天】Apache Hadoop是一个分布式系统框架,应对大数据处理需求。它包括HDFS(分布式文件系统)和MapReduce编程模型。Hadoop架构由HDFS、YARN(资源管理器)、MapReduce及通用库组成。通过环境搭建、编写MapReduce程序,可实现分布式计算。例如,WordCount程序用于统计单词频率。优化HDFS和MapReduce性能,结合Hadoop生态系统工具,能提升整体效率。随着技术发展,Hadoop在大数据领域将持续发挥关键作用。
|
7月前
|
存储 分布式计算 Hadoop
【Hadoop】HDFS 读写流程
【4月更文挑战第9天】【Hadoop】HDFS 读写流程

相关产品

  • 对象存储
  • 推荐镜像

    更多