hadoop-aliyun
模块为阿里云与 阿里云对象存储服务 (阿里云 OSS) 的集成提供支持。生成的 JAR 文件 hadoop-aliyun.jar
还声明对该支持所需的所有外部工件的传递依赖关系,使下游应用程序能够轻松使用该支持。
要使其成为 Apache Hadoop 的默认类路径的一部分,只需确保 hadoop-env.sh 中的 HADOOP_OPTIONAL_TOOLS 在列表中包含“hadoop-aliyun”。
FileSystem
接口,呈现一个分层文件系统视图。阿里云 OSS 是“对象存储”的一个示例。为了实现可扩展性,尤其是高可用性,阿里云 OSS 放宽了经典“POSIX”文件系统承诺的一些约束。
具体来说
delete()
和 rename()
由递归逐文件操作实现。它们至少需要与文件数成正比的时间,在此期间,部分更新可能可见。delete()
和 rename()
无法保证原子性。如果操作被中断,则文件系统将处于中间状态。依赖于此特性的 Hadoop 功能可能会出现意外行为。例如,YARN 的 AggregatedLogDeletionService 将不会删除适当的日志文件。
您的阿里云凭证不仅要支付服务费用,还提供对数据的读写访问权限。拥有该帐户的任何人都不仅可以读取您的数据集,还可以删除它们。
请勿通过以下方式无意中共享这些凭证:1. 将包含机密的任何配置文件检入 SCM。2. 将它们记录到控制台,因为它们最终总会被人看到。3. 在 URL 中使用凭证定义文件系统 URI,例如 oss://accessKeyId:accessKeySecret@directory/file
。它们最终将出现在日志和错误消息中。4. 在错误报告中包含机密。
如果您执行上述任何操作,请立即更改您的凭证!
具体来说,在阿里云 E-MapReduce 上,oss://
也受支持,但实现方式不同。如果您正在使用阿里云 E-MapReduce,请按照以下说明进行操作,并注意,与 E-MapReduce 中阿里云 OSS 集成相关的所有问题只能由阿里云自己解决:请向他们提出您的问题。
<property> <name>fs.oss.accessKeyId</name> <description>Aliyun access key ID</description> </property> <property> <name>fs.oss.accessKeySecret</name> <description>Aliyun access key secret</description> </property> <property> <name>fs.oss.credentials.provider</name> <description> Class name of a credentials provider that implements com.aliyun.oss.common.auth.CredentialsProvider. Omit if using access/secret keys or another authentication mechanism. The specified class must provide an accessible constructor accepting java.net.URI and org.apache.hadoop.conf.Configuration, or an accessible default constructor. </description> </property>
<property> <name>fs.AbstractFileSystem.oss.impl</name> <value>org.apache.hadoop.fs.aliyun.oss.OSS</value> <description>The implementation class of the OSS AbstractFileSystem. If you want to use OSS as YARN’s resource storage dir via the fs.defaultFS configuration property in Hadoop’s core-site.xml, you should add this configuration to Hadoop's core-site.xml </description> </property> <property> <name>fs.oss.endpoint</name> <description>Aliyun OSS endpoint to connect to. An up-to-date list is provided in the Aliyun OSS Documentation. </description> </property> <property> <name>fs.oss.impl</name> <value>org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystem</value> </property> <property> <name>fs.oss.proxy.host</name> <description>Hostname of the (optinal) proxy server for Aliyun OSS connection</description> </property> <property> <name>fs.oss.proxy.port</name> <description>Proxy server port</description> </property> <property> <name>fs.oss.proxy.username</name> <description>Username for authenticating with proxy server</description> </property> <property> <name>fs.oss.proxy.password</name> <description>Password for authenticating with proxy server.</description> </property> <property> <name>fs.oss.proxy.domain</name> <description>Domain for authenticating with proxy server.</description> </property> <property> <name>fs.oss.proxy.workstation</name> <description>Workstation for authenticating with proxy server.</description> </property> <property> <name>fs.oss.attempts.maximum</name> <value>20</value> <description>How many times we should retry commands on transient errors.</description> </property> <property> <name>fs.oss.connection.establish.timeout</name> <value>50000</value> <description>Connection setup timeout in milliseconds.</description> </property> <property> <name>fs.oss.connection.timeout</name> <value>200000</value> <description>Socket connection timeout in milliseconds.</description> </property> <property> <name>fs.oss.paging.maximum</name> <value>1000</value> <description>How many keys to request from Aliyun OSS when doing directory listings at a time. </description> </property> <property> <name>fs.oss.multipart.upload.size</name> <value>10485760</value> <description>Size of each of multipart pieces in bytes.</description> </property> <property> <name>fs.oss.upload.active.blocks</name> <value>4</value> <description>Active(Concurrent) upload blocks when uploading a file.</description> </property> <property> <name>fs.oss.multipart.download.threads</name> <value>10</value> <description>The maximum number of threads allowed in the pool for multipart download and upload.</description> </property> <property> <name>fs.oss.multipart.download.ahead.part.max.number</name> <value>4</value> <description>The maximum number of read ahead parts when reading a file.</description> </property> <property> <name>fs.oss.max.total.tasks</name> <value>128</value> <description>The maximum queue number for multipart download and upload.</description> </property> <property> <name>fs.oss.max.copy.threads</name> <value>25</value> <description>The maximum number of threads allowed in the pool for copy operations.</description> </property> <property> <name>fs.oss.max.copy.tasks.per.dir</name> <value>5</value> <description>The maximum number of concurrent tasks allowed when copying a directory.</description> </property> <property> <name>fs.oss.multipart.upload.threshold</name> <value>20971520</value> <description>Minimum size in bytes before we start a multipart uploads or copy. Notice: This property is deprecated and will be removed in further version. </description> </property> <property> <name>fs.oss.multipart.download.size</name> <value>102400/value> <description>Size in bytes in each request from ALiyun OSS.</description> </property> <property> <name>fs.oss.list.version</name> <value>2</value> <description>Select which version of the OSS SDK's List Objects API to use. Currently support 2(default) and 1(older API). </description> </property> <property> <name>fs.oss.buffer.dir</name> <description>Comma separated list of directories to buffer OSS data before uploading to Aliyun OSS</description> </property> <property> <name>fs.oss.acl.default</name> <value></vaule> <description>Set a canned ACL for bucket. Value may be private, public-read, public-read-write. </description> </property> <property> <name>fs.oss.server-side-encryption-algorithm</name> <value></vaule> <description>Specify a server-side encryption algorithm for oss: file system. Unset by default, and the only other currently allowable value is AES256. </description> </property> <property> <name>fs.oss.connection.maximum</name> <value>32</value> <description>Number of simultaneous connections to oss.</description> </property> <property> <name>fs.oss.connection.secure.enabled</name> <value>true</value> <description>Connect to oss over ssl or not, true by default.</description> </property>
要测试 oss://
文件系统客户端,需要两个将身份验证详细信息传递给测试运行器的文件。
auth-keys.xml
core-site.xml
这两个配置文件必须放入 hadoop-tools/hadoop-aliyun/src/test/resources
中。
core-site.xml
此文件预先存在,并获取 auth-keys.xml
中创建的配置。
在大多数情况下,不需要修改,除非在测试期间需要设置特定非默认属性。
auth-keys.xml
此文件触发 Aliyun OSS 模块的测试。如果没有此文件,此模块中的所有测试都不会执行
它包含连接到 Aliyun OSS 所需的访问密钥 ID/密钥和代理信息,还应提供 OSS 存储桶 URL。
test.fs.oss.name
:用于 Aliyun OSS 测试的存储桶 URL存储桶的内容将在测试过程中被清除,因此不要将存储桶用于除测试之外的任何目的。
在 /test/resources
下创建文件 contract-test-options.xml
。如果未定义特定文件 fs.contract.test.fs.oss
测试路径,则将跳过这些测试。运行任何这些测试还需要凭据,这些凭据可以从 auth-keys.xml
复制,也可以通过直接 XInclude 导入复制。以下是 contract-test-options.xml
的示例
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <include xmlns="http://www.w3.org/2001/XInclude" href="auth-keys.xml"/> <property> <name>fs.contract.test.fs.oss</name> <value>oss://spark-tests</value> </property> <property> <name>fs.oss.impl</name> <value>org.apache.hadoop.fs.aliyun.oss.AliyunOSSFileSystem</value> </property> <property> <name>fs.oss.endpoint</name> <value>oss-cn-hangzhou.aliyuncs.com</value> </property> <property> <name>fs.oss.buffer.dir</name> <value>/tmp/oss</value> </property> <property> <name>fs.oss.multipart.download.size</name> <value>102400</value> </property> </configuration>