15 ,java 操作 emr ( maven 引入组件,版本选择 ) ,

1 ,发布版本 – maven 版本 :

  1. 可以版本对应 : 可以使用 Amazon EMR 项目存储库构建针对特定 Amazon EMR 发布版附带的准确版本的库和依赖项的 Apache Hive 和 Apache Hadoop 任务代码。
  2. 避免问题 : 针对存储库中的 Amazon EMR 项目进行构建可确保针对其创建任务的库的版本是在集群上运行时提供的相同版本,从而帮助避免运行时类路径问题。
  3. 只适合 maven : 目前,Amazon EMR 项目仅适用于 Maven 构建。

2 ,使用 maven 的 aws 仓库 :

  1. 要访问项目存储库,请将存储库 URL 添加到 Maven 设置文件或特定项目的 pom.xml 配置文件。
  2. 版本对应信息 :
    https://docs.aws.amazon.com/zh_cn/emr/latest/ReleaseGuide/emr-release-5x.html#emr-5260-app-versions
  3. 我们的 emr 版本 : 5.26.0
    在这里插入图片描述
  4. 我们应该使用的 hadoop 和 spark 版本 :
    1 ,hadoop : 2.8.5-amzn-4
    2 ,spark : 2.4.3
    在这里插入图片描述
  5. aws - emr - maven 的项目存储库 url :
    https://s3-endpoint/region-ID-emr-artifacts/emr-release-label/repos/maven/
  6. 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

  1. 宁夏区域
  2. emr 版本 : emr-5.26.0
  3. 创建集群版本选择 :
    在这里插入图片描述
  4. 查找版本对应信息 :
    https://docs.aws.amazon.com/zh_cn/emr/latest/ReleaseGuide/emr-release-5x.html#emr-5260-app-versions
  5. 查找到结果 :
    在这里插入图片描述
  6. hadoop 版本 : 2.8.5-amzn-4
    在这里插入图片描述
  7. hive 版本 : 2.3.5-amzn-0
    在这里插入图片描述
  8. 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>

    <!-- 1 ,编码方式,java 版本 -->
    <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>

    <!-- 2 ,aws 仓库,宁夏区域 -->
    <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.cn-northwest-1.amazonaws.com/cn-northwest-1-emr-artifacts/emr-5.26.0/repos/maven/</url>-->
            <url>https://s3.us-west-1.amazonaws.com/us-west-1-emr-artifacts/emr-5.26.0/repos/maven/</url>
        </repository>
    </repositories>

    <!-- 3 ,引入依赖 -->
    <dependencies>

        <!-- 统一 servlet 依赖 ( 不然下面的依赖中,会有依赖冲突 ) -->
        <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>

        <!-- aws 版本 -->
        <dependency>
            <groupId>com.amazonaws</groupId>
            <artifactId>aws-java-sdk</artifactId>
            <version>1.11.636</version>
        </dependency>
        <!-- hadoop 版本 -->
        <dependency>
            <groupId>org.apache.hadoop</groupId>
            <artifactId>hadoop-common</artifactId>
            <version>2.8.5-amzn-4</version>
        </dependency>
        <!-- hive 版本 -->
        <dependency>
            <groupId>org.apache.hive</groupId>
            <artifactId>hive-exec</artifactId>
            <version>2.3.5-amzn-0</version>
        </dependency>
        <!-- scala 版本 -->
        <dependency>
            <groupId>org.scala-lang</groupId>
            <artifactId>scala-library</artifactId>
            <version>2.11.8</version>
        </dependency>
        <!-- spark core -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.11</artifactId>
            <version>2.4.3</version>
        </dependency>
        <!-- spark sql -->
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-sql_2.11</artifactId>
            <version>2.4.3</version>
        </dependency>
    </dependencies>

    <!-- 打包插件 : 将 scala 和 java 代码一同打包成 jar 包 -->
    <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>

            <!-- maven 打包插件,将依赖也打进 jar 包 -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.4.1</version>
                <configuration>
                    <!-- get all project dependencies -->
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                    <!-- MainClass in mainfest make a executable jar -->
                    <archive>
                        <manifest>
                            <mainClass>util.Microseer</mainClass>
                        </manifest>
                    </archive>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <!-- bind to the packaging phase -->
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

5 ,文件操作 :

  1. 将 s3 文件下载到 linux :
    hadoop fs -get s3://demo02/img2/timg.jpg myFile.txt
  2. 将文件上传到 s3 :
    hadoop fs -put myFile.txt s3://demo02/img2/aiyinsitan.jpg
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值