好玩的大数据之49:Spark源码编译

一、简介


        利用Spark提供的源码生成自定义的Spark

二、下载


        1.从spark网站

        下载地址:http://spark.apache.org/downloads.html

                            https://archive.apache.org/dist/spark/

            下载得到:spark-3.0.0.tgz

            选版本

选版本
选文件

        2.从github下

        https://github.com/apache/spark

spark


download

三、安装


            tar zxvf spark-3.0.0.tgz

            源码在spark-3.0.0目录下

四、配置


            有两种编译方法

          1.利用maven编译和发布

                a) 设置maven的编译选项

                        vi ~/.bashrc

                                export MAVEN_OPTS="-Xmx4g -XX:ReservedCodeCacheSize=2g"

                        source ~/.bashrc

                b) 设置maven镜像加速

                    在pom.xml中

                    找,在它的下面放入

      aliyun-public

      aliyun-public

      http://maven.aliyun.com/nexus/content/groups/public/

     

        true

     

     

        false

     

   


    再找,在它的下面放入

 

      aliyun-public

      aliyun-public

      http://maven.aliyun.com/nexus/content/groups/public/

     

        true

     

     

        false

     

   

          2.利用sbt编译和发布

                a) 设置maven的编译选项

                    在Spark源码的根目录建立一个叫.jvmopts(前面有个点)

                        vi .jvmopts

-Xmx2g

-XX:ReservedCodeCacheSize=1g

                b) 设置maven镜像加速

                    vi project/SparkBuild.scala

                找DefaultMavenRepository

#注释掉DefaultMavenRepository,变成如下形式

// DefaultMavenRepository,

      Resolver.url("aliyun", url("http://maven.aliyun.com/nexus/content/groups/public/")),

3.改变scala版本号

        1.改变版本号

                要想利用scala2.13编译,需要执行此脚本,默认是scala2.12

                将scala版本设为2.13

                    ./dev/change-scala-version.sh 2.13

                将scala版本设为2.12

                    ./dev/change-scala-version.sh 2.12

        2.enable the profile

                For Maven, please enable the profile (e.g. 2.13):

                        ./build/mvn -Pscala-2.13 compile

                        遇到错误了,还是乖乖的用scala2.12吧

                For SBT, specify a complete scala version using (e.g. 2.13.0):

                        ./build/sbt -Dscala.version=2.13.0

五、验证


          1.利用maven编译和发布

                a)编译

                    #Building With Hive support(hive 2.3.7)(可以通过调整pom.xml的版本号来修改默认值)

                            ./build/mvn -Pyarn -Phive -Phive-thriftserver -DskipTests clean package

                    #Building With Hive support(hadoop3.2.1,hive 2.3.7)

                            ./build/mvn -Pyarn -Phive -Phive-thriftserver -DskipTests -Dhadoop.version=3.2.1  clean package

                    #Building With Hive support(hadoop3.2.1,hive3.1.2)这个没有成功

                           ./build/mvn -Pyarn -Phive -Phive-thriftserver -DskipTests -Dhadoop.version=3.2.1 -Dhive.version=3.1.2 clean package

                    #Building with Mesos support

                            ./build/mvn -Pmesos -DskipTests clean package

                    #Building with Kubernetes support

                            ./build/mvn -Pkubernetes -DskipTests clean package


            b)发布

            ./dev/make-distribution.sh --help

帮助

                    #usage:

                    ./dev/make-distribution.sh [--name] [--tgz] [--pip] [--r] [--mvn ]

            例子:

#默认hadoop2.7.4,hive2.3.7(可以通过调整pom.xml的版本号来修改默认值)

./dev/make-distribution.sh --name hadoop3.2.1-hive --tgz

./dev/make-distribution.sh --name hadoop3.2.1-hive --tgz -Pyarn -Phive -Phive-thriftserver -DskipTests

#加入其他的组件(没有试过)

./dev/make-distribution.sh --name custom-spark --pip --r --tgz -Psparkr -Phive -Phive-thriftserver -Pmesos -Pyarn -Pkubernetes

          2.利用sbt编译和打包

                a)编译

                        ./build/sbt package

               b)发布

                        参见前面的./dev/make-distribution.sh 


六、参考


https://spark.apache.org/docs/latest/building-spark.html#packaging-without-hadoop-dependencies-for-yarn

你可能感兴趣的:(好玩的大数据之49:Spark源码编译)