1 ,发布版本 – maven 版本 :
- 可以版本对应 : 可以使用 Amazon EMR 项目存储库构建针对特定 Amazon EMR 发布版附带的准确版本的库和依赖项的 Apache Hive 和 Apache Hadoop 任务代码。
- 避免问题 : 针对存储库中的 Amazon EMR 项目进行构建可确保针对其创建任务的库的版本是在集群上运行时提供的相同版本,从而帮助避免运行时类路径问题。
- 只适合 maven : 目前,Amazon EMR 项目仅适用于 Maven 构建。
2 ,使用 maven 的 aws 仓库 :
- 要访问项目存储库,请将存储库 URL 添加到 Maven 设置文件或特定项目的 pom.xml 配置文件。
- 版本对应信息 :
https://docs.aws.amazon.com/zh_cn/emr/latest/ReleaseGuide/emr-release-5x.html#emr-5260-app-versions - 我们的 emr 版本 : 5.26.0
- 我们应该使用的 hadoop 和 spark 版本 :
1 ,hadoop : 2.8.5-amzn-4
2 ,spark : 2.4.3
- aws - emr - maven 的项目存储库 url :
https://s3-endpoint/region-ID-emr-artifacts/emr-release-label/repos/maven/ - url 解读 :
1 ,s3-endpoint 是存储库的区域的 Amazon Simple Storage Service (Amazon S3) 终端节点,region-ID 是相应的区域。例如,s3.us-west-1.amazonaws.com 和 us-west-1。有关更多信息,请参阅 Amazon Web Services 一般参考中的 Amazon S3 终端节点。由于区域之间的项目不存在差异,因此,您可以为开发环境指定最方便的区域。
2 ,emr-release-label 是将运行代码的 Amazon EMR 集群的发行版标签。版本标签的格式是 emr-x.x.x. For example, emr-5.26.0.
3 ,maven 引入依赖 : 5.26.0
- 宁夏区域
- emr 版本 : emr-5.26.0
- 创建集群版本选择 :
- 查找版本对应信息 :
https://docs.aws.amazon.com/zh_cn/emr/latest/ReleaseGuide/emr-release-5x.html#emr-5260-app-versions - 查找到结果 :
- hadoop 版本 : 2.8.5-amzn-4
- hive 版本 : 2.3.5-amzn-0
- spark 版本 : 2.4.3
4 ,maven 引入依赖 : 例子 ( 全部代码 )
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lifeCycle.spark</groupId>
<artifactId>demo01</artifactId>
<version>1.0-SNAPSHOT</version>
<name>aws-java-sample</name>
<url>http://aws.amazon.com/sdkforjava</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
</properties>
<repositories>
<repository>
<id>emr-5.26.0-artifacts</id>
<name>EMR 5.26.0 Releases Repository</name>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://s3.us-west-1.amazonaws.com/us-west-1-emr-artifacts/emr-5.26.0/repos/maven/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.636</version>
</dependency>
<dependency>
<groupId>org.apache.hadoop</groupId>
<artifactId>hadoop-common</artifactId>
<version>2.8.5-amzn-4</version>
</dependency>
<dependency>
<groupId>org.apache.hive</groupId>
<artifactId>hive-exec</artifactId>
<version>2.3.5-amzn-0</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.8</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.4.3</version>
</dependency>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.11</artifactId>
<version>2.4.3</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>${env.HOME}/.aws/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>com.amazonaws.samples.S3Sample</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<id>scala-compile-first</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<includes>
<include>**/*.scala</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>util.Microseer</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
5 ,文件操作 :
- 将 s3 文件下载到 linux :
hadoop fs -get s3://demo02/img2/timg.jpg myFile.txt - 将文件上传到 s3 :
hadoop fs -put myFile.txt s3://demo02/img2/aiyinsitan.jpg