Hudi安装设置(容器情况)大数据技能竞赛平台搭建

打印 上一主题 下一主题

主题 1080|帖子 1080|积分 3250


情况预备

hadoop搭建(容器情况)
spark on yarn搭建(容器情况)
在上面情况搭建完成的底子上搭建hudi
预备好maven包和hudi包,可以去下面这里下载
apache-maven-3.6.3-bin.tar.gz
https://gitcode.com/xfcloud/BIgdataA/blob/main/hudi/apache-maven-3.6.3-bin.tar.gzhudi-0.12.0.src.tgz
https://gitcode.com/xfcloud/BIgdataA/blob/main/hudi/hudi-0.12.0.src.tgz
Hudi安装设置

本任务需要使用root用户完成相关设置,具体要求如下:
1、 从宿主机/opt目录下将maven相关安装包复制到容器Master中的/opt/software(若路径不存在,则需新建)中,将maven相关安装包解压到/opt/module/目录下(若路径不存在,则需新建)并设置maven当地库为/opt/software/RepMaven/,远程仓库使用阿里云镜像,设置maven的情况变量,并在/opt/下执行mvn -v,将运行效果截图粘贴至客户端桌面【Release\任务A提交效果.docx】中对应的任务序号下;

     <mirror>
   <id>nexus-aliyun</id>
   <mirrorOf>central</mirrorOf>
   <name>Nexus aliyun</name>
   <url>http://maven.aliyun.com/nexus/content/groups/public</url>
  </mirror>
  第一步:从宿主机/opt目录下将maven相关安装包复制到容器Master中的/opt/software(若路径不存在,则需新建)中

  1. [root@Bigdata ~]# docker cp /opt/apache-maven-3.6.3-bin.tar.gz master:/software
复制代码
第二步:将maven相关安装包解压到/opt/module/目录下(若路径不存在,则需新建)

  1. [root@master ~]# tar zxvf /opt/software/apache-maven-3.6.3-bin.tar.gz -C /opt/module/
复制代码
第三步:设置maven当地库为/opt/software/RepMaven/,远程仓库使用阿里云镜像

  1. [root@master ~]# vi /opt/module/maven/conf/settings.xml
复制代码
当地仓库,找到 <localRepository>/path/to/local/repo</localRepository>这个后再下面添加
  1.   <localRepository>/opt/software/RepMaven/</localRepository>
复制代码

远程仓库,找到mirrors标签,在里面添加阿里云镜
  1.   <mirror>
  2.    <id>nexus-aliyun</id>
  3.    <mirrorOf>central</mirrorOf>
  4.    <name>Nexus aliyun</name>
  5.    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
  6.   </mirror>
复制代码

第四步:设置maven的情况变量

[root@master ~]# vi /etc/profile 添加相应的情况变量
  1. export MAVEN_HOME=/opt/module/maven
  2. export PATH=$PATH:$MAVEN_HOME/bin
复制代码
第五步:在/opt/下执行mvn -v

  1. [root@master ~]# cd /opt/
  2. [root@master opt]# mvn -v
复制代码


2、 从宿主机/opt目录下将Hudi相关安装包复制到容器Master中的/opt/software(若路径不存在,则需新建)中,将Hudi相关安装包解压到/opt/module/目录下(若路径不存在,则需新建),将下令复制并粘贴至客户端桌面【Release\任务A提交效果.docx】中对应的任务序号下;

第一步:从宿主机/opt目录下将Hudi相关安装包复制到容器Master中的/opt/software(若路径不存在,则需新建)中

  1. [root@Bigdata ~]# docker cp /opt/hudi-0.12.0.src.tgz master:/opt/software
复制代码
第二步:将Hudi相关安装包解压到/opt/module/目录下(若路径不存在,则需新建)

  1. [root@master ~]# tar zxvf /opt/software/hudi-0.12.0.src.tgz -C /opt/module/
复制代码
3、 完成解压安装及设置后使用maven对Hudi进行构建(spark3.1,scala-2.12),编译完成后与Spark集成,集成后使用spark-shell操作Hudi,将spark-shell启动使用spark-shell运行下面给到的案例,并将最终查询效果截图粘贴至客户端桌面【Release\任务A提交效果.docx】中对应的任务序号下。

第一步:设置hudi

1)、替换父模块pom.xml(比赛有给直接替换就行,没给就自己设置)

替换为这个
 父模块pom.xml
https://gitcode.com/xfcloud/BIgdataA/blob/main/hudi/pom.xml
或者手动修改
  1. [root@master ~]# vi /opt/module/hudi-0.12.0/pom.xml
复制代码
新增repository加快依赖下载
  1. <repository>
  2.         <id>nexus-aliyun</id>
  3.         <name>nexus-aliyun</name>
  4.         <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
  5.         <releases>
  6.             <enabled>true</enabled>
  7.         </releases>
  8.         <snapshots>
  9.             <enabled>false</enabled>
  10.         </snapshots>
  11. </repository>
复制代码

修改依赖的组件版本,找到对应的标签修改就行了
  1. <hadoop.version>3.1.3</hadoop.version>
  2. <hive.version>3.1.2</hive.version>
复制代码
2)、HoodieParquetDataBlock.java替换(比赛有给直接替换就行,没给就自己设置)

替换为这个
 HoodieParquetDataBlock.java
https://gitcode.com/xfcloud/BIgdataA/blob/main/hudi/HoodieParquetDataBlock.java
或者手动修改
  1. [root@master ~]# vi /opt/module/hudi-0.12.0/hudi-common/src/main/java/org/apache/hudi/common/table/log/block/HoodieParquetDataBlock.java
复制代码
修改第110行,原先只有一个参数,添加第二个参数null,否则会因为hadoop2.x和3.x版本兼容问题(找不到合适的FSDataOutputStream构造器)

3)、hudi-spark-bundle/pom.xml替换(比赛有给直接替换就行,没给就自己设置)

替换为这个
 hudi-spark-bundle/pom.xml
https://gitcode.com/xfcloud/BIgdataA/blob/main/hudi/hudi-spark-bundle/pom.xml
或者手动修改
  1. [root@master ~]# vi /opt/module/hudi-0.12.0/packaging/hudi-spark-bundle/pom.xml
复制代码
插入以下内容,标注插入的地方插入相应的内容
  1. <!-- Hive -->
  2.     <dependency>
  3.       <groupId>${hive.groupid}</groupId>
  4.       <artifactId>hive-service</artifactId>
  5.       <version>${hive.version}</version>
  6.       <scope>${spark.bundle.hive.scope}</scope>
  7.     <!-- 这里插入下面内容1 start -->  
  8.       <exclusions>
  9.         <exclusion>
  10.           <artifactId>guava</artifactId>
  11.           <groupId>com.google.guava</groupId>
  12.         </exclusion>
  13.         <exclusion>
  14.           <groupId>org.eclipse.jetty</groupId>
  15.           <artifactId>*</artifactId>
  16.         </exclusion>
  17.         <exclusion>
  18.           <groupId>org.pentaho</groupId>
  19.           <artifactId>*</artifactId>
  20.         </exclusion>
  21.       </exclusions>
  22.      <!-- 插入内容1 end -->  
  23.     </dependency>
  24.    
  25.     <dependency>
  26.       <groupId>${hive.groupid}</groupId>
  27.       <artifactId>hive-service-rpc</artifactId>
  28.       <version>${hive.version}</version>
  29.       <scope>${spark.bundle.hive.scope}</scope>
  30.     </dependency>
  31.    
  32.     <dependency>
  33.       <groupId>${hive.groupid}</groupId>
  34.       <artifactId>hive-jdbc</artifactId>
  35.       <version>${hive.version}</version>
  36.       <scope>${spark.bundle.hive.scope}</scope>
  37.       <!-- 这里插入下面内容2 start -->
  38.       <exclusions>
  39.         <exclusion>
  40.           <groupId>javax.servlet</groupId>
  41.           <artifactId>*</artifactId>
  42.         </exclusion>
  43.         <exclusion>
  44.           <groupId>javax.servlet.jsp</groupId>
  45.           <artifactId>*</artifactId>
  46.         </exclusion>
  47.         <exclusion>
  48.           <groupId>org.eclipse.jetty</groupId>
  49.           <artifactId>*</artifactId>
  50.         </exclusion>
  51.       </exclusions>
  52.       <!-- 插入内容2 end -->
  53.     </dependency>
  54.    
  55.     <dependency>
  56.       <groupId>${hive.groupid}</groupId>
  57.       <artifactId>hive-metastore</artifactId>
  58.       <version>${hive.version}</version>
  59.       <scope>${spark.bundle.hive.scope}</scope>
  60.       <!-- 这里插入下面内容3 start -->
  61.       <exclusions>
  62.         <exclusion>
  63.           <groupId>javax.servlet</groupId>
  64.           <artifactId>*</artifactId>
  65.         </exclusion>
  66.         <exclusion>
  67.           <groupId>org.datanucleus</groupId>
  68.           <artifactId>datanucleus-core</artifactId>
  69.         </exclusion>
  70.         <exclusion>
  71.           <groupId>javax.servlet.jsp</groupId>
  72.           <artifactId>*</artifactId>
  73.         </exclusion>
  74.         <exclusion>
  75.           <artifactId>guava</artifactId>
  76.           <groupId>com.google.guava</groupId>
  77.         </exclusion>
  78.       </exclusions>
  79.       <!-- 插入内容3 end -->
  80.     </dependency>
  81.    
  82.     <dependency>
  83.       <groupId>${hive.groupid}</groupId>
  84.       <artifactId>hive-common</artifactId>
  85.       <version>${hive.version}</version>
  86.       <scope>${spark.bundle.hive.scope}</scope>
  87.       <!-- 这里插入下面内容4 start -->
  88.       <exclusions>
  89.         <exclusion>
  90.           <groupId>org.eclipse.jetty.orbit</groupId>
  91.           <artifactId>javax.servlet</artifactId>
  92.         </exclusion>
  93.         <exclusion>
  94.           <groupId>org.eclipse.jetty</groupId>
  95.           <artifactId>*</artifactId>
  96.         </exclusion>
  97.       </exclusions>
  98.       <!-- 插入内容4 end -->
  99.         </dependency>
  100.        
  101.     <!-- 增加hudi配置版本的jetty 这里插入下面内容5 start -->
  102.     <dependency>
  103.       <groupId>org.eclipse.jetty</groupId>
  104.       <artifactId>jetty-server</artifactId>
  105.       <version>${jetty.version}</version>
  106.     </dependency>
  107.    
  108.     <dependency>
  109.       <groupId>org.eclipse.jetty</groupId>
  110.       <artifactId>jetty-util</artifactId>
  111.       <version>${jetty.version}</version>
  112.     </dependency>
  113.    
  114.     <dependency>
  115.       <groupId>org.eclipse.jetty</groupId>
  116.       <artifactId>jetty-webapp</artifactId>
  117.       <version>${jetty.version}</version>
  118.     </dependency>
  119.    
  120.     <dependency>
  121.       <groupId>org.eclipse.jetty</groupId>
  122.       <artifactId>jetty-http</artifactId>
  123.       <version>${jetty.version}</version>
  124.     </dependency>
  125.     <!-- 插入内容5 end -->
复制代码
4)、将packaging/hudi-utilities-bundle/pom.xml替换(比赛有给直接替换就行,没给就自己设置)

替换为这个
 hudi-utilities-bundle/pom.xml
https://gitcode.com/xfcloud/BIgdataA/blob/main/hudi/hudi-utilities-bundle/pom.xml
或者手动修改
  1. [root@master ~]# vi /opt/module/hudi-0.12.0/packaging/hudi-utilities-bundle/pom.xml
复制代码
插入以下内容,标注插入的地方插入相应的内容
  1.   <!-- Hoodie -->
  2.     <dependency>
  3.       <groupId>org.apache.hudi</groupId>
  4.       <artifactId>hudi-common</artifactId>
  5.       <version>${project.version}</version>
  6.       <!-- 这里插入下面内容1 start -->
  7.       <exclusions>
  8.         <exclusion>
  9.           <groupId>org.eclipse.jetty</groupId>
  10.           <artifactId>*</artifactId>
  11.         </exclusion>
  12.       </exclusions>
  13.       <!-- 插入内容1 end -->
  14.     </dependency>
  15.     <dependency>
  16.       <groupId>org.apache.hudi</groupId>
  17.       <artifactId>hudi-client-common</artifactId>
  18.       <version>${project.version}</version>
  19.       <!-- 这里插入下面内容2 start -->
  20.       <exclusions>
  21.         <exclusion>
  22.           <groupId>org.eclipse.jetty</groupId>
  23.           <artifactId>*</artifactId>
  24.         </exclusion>
  25.       </exclusions>
  26.       <!-- 插入内容2 end -->
  27.     </dependency>
  28. <!-- Hive -->
  29.     <dependency>
  30.       <groupId>${hive.groupid}</groupId>
  31.       <artifactId>hive-service</artifactId>
  32.       <version>${hive.version}</version>
  33.       <scope>${utilities.bundle.hive.scope}</scope>
  34.       <!-- 这里插入下面内容3 start -->
  35.       <exclusions>
  36.        <exclusion>
  37.           <artifactId>servlet-api</artifactId>
  38.           <groupId>javax.servlet</groupId>
  39.         </exclusion>
  40.         <exclusion>
  41.           <artifactId>guava</artifactId>
  42.           <groupId>com.google.guava</groupId>
  43.         </exclusion>
  44.         <exclusion>
  45.           <groupId>org.eclipse.jetty</groupId>
  46.           <artifactId>*</artifactId>
  47.         </exclusion>
  48.         <exclusion>
  49.           <groupId>org.pentaho</groupId>
  50.           <artifactId>*</artifactId>
  51.         </exclusion>
  52.       </exclusions>
  53.       <!-- 插入内容3 end -->
  54.     </dependency>
  55.     <dependency>
  56.       <groupId>${hive.groupid}</groupId>
  57.       <artifactId>hive-service-rpc</artifactId>
  58.       <version>${hive.version}</version>
  59.       <scope>${utilities.bundle.hive.scope}</scope>
  60.     </dependency>
  61.     <dependency>
  62.       <groupId>${hive.groupid}</groupId>
  63.       <artifactId>hive-jdbc</artifactId>
  64.       <version>${hive.version}</version>
  65.       <scope>${utilities.bundle.hive.scope}</scope>
  66.       <!-- 这里插入下面内容4 start -->
  67.       <exclusions>
  68.         <exclusion>
  69.           <groupId>javax.servlet</groupId>
  70.           <artifactId>*</artifactId>
  71.         </exclusion>
  72.         <exclusion>
  73.           <groupId>javax.servlet.jsp</groupId>
  74.           <artifactId>*</artifactId>
  75.         </exclusion>
  76.         <exclusion>
  77.           <groupId>org.eclipse.jetty</groupId>
  78.           <artifactId>*</artifactId>
  79.         </exclusion>
  80.       </exclusions>
  81.       <!-- 插入内容4 end -->
  82.     </dependency>
  83.     <dependency>
  84.       <groupId>${hive.groupid}</groupId>
  85.       <artifactId>hive-metastore</artifactId>
  86.       <version>${hive.version}</version>
  87.       <scope>${utilities.bundle.hive.scope}</scope>
  88.       <!-- 这里插入下面内容5 start -->
  89.       <exclusions>
  90.         <exclusion>
  91.           <groupId>javax.servlet</groupId>
  92.           <artifactId>*</artifactId>
  93.         </exclusion>
  94.         <exclusion>
  95.           <groupId>org.datanucleus</groupId>
  96.           <artifactId>datanucleus-core</artifactId>
  97.         </exclusion>
  98.         <exclusion>
  99.           <groupId>javax.servlet.jsp</groupId>
  100.           <artifactId>*</artifactId>
  101.         </exclusion>
  102.         <exclusion>
  103.           <artifactId>guava</artifactId>
  104.           <groupId>com.google.guava</groupId>
  105.         </exclusion>
  106.       </exclusions>
  107.       <!-- 插入内容5 end -->
  108.     </dependency>
  109.     <dependency>
  110.       <groupId>${hive.groupid}</groupId>
  111.       <artifactId>hive-common</artifactId>
  112.       <version>${hive.version}</version>
  113.       <scope>${utilities.bundle.hive.scope}</scope>
  114.       <!-- 这里插入下面内容6 start -->
  115.       <exclusions>
  116.         <exclusion>
  117.           <groupId>org.eclipse.jetty.orbit</groupId>
  118.           <artifactId>javax.servlet</artifactId>
  119.         </exclusion>
  120.         <exclusion>
  121.           <groupId>org.eclipse.jetty</groupId>
  122.           <artifactId>*</artifactId>
  123.         </exclusion>
  124.       </exclusions>
  125.       <!-- 插入内容6 end -->
  126. </dependency>
  127.     <!-- 增加hudi配置版本的jetty 这里插入下面内容7 start -->
  128.     <dependency>
  129.       <groupId>org.eclipse.jetty</groupId>
  130.       <artifactId>jetty-server</artifactId>
  131.       <version>${jetty.version}</version>
  132.     </dependency>
  133.    
  134.     <dependency>
  135.       <groupId>org.eclipse.jetty</groupId>
  136.       <artifactId>jetty-util</artifactId>
  137.       <version>${jetty.version}</version>
  138.     </dependency>
  139.     <dependency>
  140.       <groupId>org.eclipse.jetty</groupId>
  141.       <artifactId>jetty-webapp</artifactId>
  142.       <version>${jetty.version}</version>
  143.     </dependency>
  144.     <dependency>
  145.       <groupId>org.eclipse.jetty</groupId>
  146.       <artifactId>jetty-http</artifactId>
  147.       <version>${jetty.version}</version>
  148.     </dependency>
  149. <!-- 插入内容7 end -->
复制代码
第二步:编译完成后与Spark集成,集成后使用spark-shell操作Hudi

  1. 进入hudi项目目录
  2. cd /opt/module/hudi
  3. 编译构建
  4. mvn clean package -DskipTests -Dspark3.1 -Dscala-2.12
复制代码


编译完看下能不能进hudi-cli
  1. /opt/module/hudi-0.12.0/hudi-cli/hudi-cli.sh
复制代码

与spark集成
将上述编译好的安装包拷贝到spark下的jars目录中
  1. cp /opt/module/hudi-0.12.0/packaging/hudi-spark-bundle/target/hudi-spark3.1-bundle_2.12-0.12.0.jar /opt/module/spark/jars/
复制代码

第三步:将spark-shell启动使用spark-shell运行下面给到的案例

启动spark-shell
  1. spark-shell \
  2.   --conf 'spark.serializer=org.apache.spark.serializer.KryoSerializer' \
  3.   --conf 'spark.sql.hive.convertMetastoreParquet=false'
复制代码
 将案例复制到下令行运行

  1. (提示:编译需要替换以下内容:
  2. 1.将父模块pom.xml替换;
  3. 2.hudi-common/src/main/java/org/apache/hudi/common/table/log/block/HoodieParquetDataBlock.java替换;
  4. 3.将packaging/hudi-spark-bundle/pom.xml替换;
  5. 4.将packaging/hudi-utilities-bundle/pom.xml替换)
  6. import org.apache.hudi.QuickstartUtils._
  7. import scala.collection.JavaConversions._
  8. import org.apache.spark.sql.SaveMode._
  9. import org.apache.hudi.DataSourceReadOptions._
  10. import org.apache.hudi.DataSourceWriteOptions._
  11. import org.apache.hudi.config.HoodieWriteConfig._
  12. import org.apache.hudi.common.model.HoodieRecord
  13. val tableName = "hudi_trips_cow"
  14. val basePath = "file:///tmp/hudi_trips_cow"
  15. val dataGen = new DataGenerator
  16. val inserts = convertToStringList(dataGen.generateInserts(10))
  17. val df = spark.read.json(spark.sparkContext.parallelize(inserts, 2))
  18. df.write.format("hudi").
  19.   options(getQuickstartWriteConfigs).
  20.   option(PRECOMBINE_FIELD_OPT_KEY, "ts").
  21.   option(RECORDKEY_FIELD_OPT_KEY, "uuid").
  22.   option(PARTITIONPATH_FIELD_OPT_KEY, "partitionpath").
  23.   option(TABLE_NAME, tableName).
  24.   mode(Overwrite).
  25.   save(basePath)
  26. val tripsSnapshotDF = spark.read.format("hudi").load(basePath + "/*/*/*/*")
  27. tripsSnapshotDF.createOrReplaceTempView("hudi_trips_snapshot")
  28. spark.sql("select fare, begin_lon, begin_lat, ts from  hudi_trips_snapshot where fare > 20.0").show()
复制代码
END

一键三连是我写文章的动力!
声明:此文章为个人学习笔记,如文章有问题欢迎留言探讨,也希望您的指正 !

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

宁睿

论坛元老
这个人很懒什么都没写!
快速回复 返回顶部 返回列表