凯发娱发k8

编译安装spark 1.5.x(building spark) -凯发娱发k8

2023-10-20,,

原文连接:http://spark.apache.org/docs/1.5.0/building-spark.html

· building with build/mvn

· building a runnable distribution

· setting up maven’s memory usage

· specifying the hadoop version

· building with hive and jdbc support

· building for scala 2.11

· tests in maven

· continuous compilation

· building spark with intellij idea or eclipse

· running java 8 test suites

· building for pyspark on yarn

· packaging without hadoop dependencies for yarn

· building with sbt

· testing with sbt

· speeding up compilation with zinc

building spark using maven requires maven 3.3.3 or newer and java 7 . the spark build can supply a suitable maven binary; see below.

安装spark 1.5.x需要maven 3.3.3及以后版本并且需要jdk1.7及以后版本。

building with build/mvn(使用build/mvn编译

spark now comes packaged with a self-contained maven installation to ease building and deployment of spark from source located under the build/ directory. this script will automatically download and setup all necessary build requirements (maven, scala, and zinc) locally within the build/ directory itself. it honors any mvn binary if present already, however, will pull down its own copy of scala and zinc regardless to ensure proper version requirements are met. build/mvn execution acts as a pass through to the mvn call allowing easy transition from previous build methods. as an example, one can build a version of spark as follows:

目前 spark 编译目录已经将 maven 自带进去了,以方便编译以及部署。这个脚本将会在它本地 build/ 编译目录自动下载和安装所有编译过程中所必需的( maven,scala 和 zinc )。如果这些已经存在,它将允许 mvn 二进制包下载它自己 scala 和 zinc 的拷贝副本,不管是否满足正确版本的要求。build/mvn 的执行允许从以前的版本的方法轻松过渡建。举个例子,可以如以下编译一个 spark 版本:

build/mvn -pyarn -phadoop-2.4 -dhadoop.version=2.4.0 -dskiptests clean package

other build examples can be found below.

note: when building on an encrypted filesystem (if your home directory is encrypted, for example), then the spark build might fail with a “filename too long” error. as a workaround, add the following in the configuration args of the scala-maven-plugin in the project pom.xml:

可以在下面找到其他的编译例子。

note: 当在一个加密的文件系统上进行编译(比如,当你的 home 目录被加密了),那么 spark 在编译时可能会出错,报错信息为 “filename too long”。作为一个变通方案,将下面添加到项目pom.xml中的scala-maven-plugin的配置参数:

-xmax-classfile-name

128

并在项目 project/sparkbuild.scala添加:

scalacoptions in compile = seq("-xmax-classfile-name", "128"),添加到 sharedsettings变量。如果你不确定在哪里添加这行也可以看这个pr.

and in project/sparkbuild.scala add:

scalacoptions in compile = seq("-xmax-classfile-name", "128"),

to the sharedsettings val. see also this pr if you are unsure of where to add these lines.

building a runnable distribution(编译运行版本)

to create a spark distribution like those distributed by the spark downloads page, and that is laid out so as to be runnable, use make-distribution.sh in the project root directory. it can be configured with maven profile settings and so on like the direct maven build. example:

为了像在 spark downloads 页面下载的那些版本一样创建 spark 发布版。通过在项目根目录下使用 make-distribution.sh。像在直接 maven 编译那样在 maven profile文件中进行配置。例如:

./make-distribution.sh --name custom-spark --tgz -phadoop-2.4 -pyarn

为了看更多信息,可以运行:./make-distribution.sh --help.

for more information on usage, run ./make-distribution.sh --help

setting up maven’s memory usage

you’ll need to configure maven to use more memory than usual by setting maven_opts. we recommend the following settings:

你需要通过设置 maven_opts来配置 maven,需要分配比通常更多的内存来设置 maven。我们推荐以下的设置:

export maven_opts="-xmx2g -xx:maxpermsize=512m -xx:reservedcodecachesize=512m"

if you don’t run this, you may see errors like the following:

如果不运行上述命令,你可能会遇到如下的错误:

[info] compiling 203 scala sources and 9 java sources to /users/me/development/spark/core/target/scala-2.10/classes...

[error] permgen space -> [help 1]

[info] compiling 203 scala sources and 9 java sources to /users/me/development/spark/core/target/scala-2.10/classes...

[error] java heap space -> [help 1]

you can fix this by setting the maven_opts variable as discussed before.

可以通过之前提到的设置 maven_opts 变量解决这个问题。

note:

· for java 8 and above this step is not required.

· if using build/mvn with no maven_opts set, the script will automate this for you.

note:

· 对于 java 8 来说,以上步骤不是必需的

· 如果使用不带 maven_opts设置的 build/mvn ,那么脚本会自动帮你完成这些

specifying the hadoop version

because hdfs is not protocol-compatible across versions, if you want to read from hdfs, you’ll need to build spark against the specific hdfs version in your environment. you can do this through the hadoop.version property. if unset, spark will build against hadoop 2.2.0 by default. note that certain build profiles are required for particular hadoop versions:

因为 hdfs 各版本协议是不兼容的,如果你想从 hdfs 中读取数据,你需要在你的环境中编译 spark 来适应具体的 hdfs 版本。可以通过 “hadoop.version” 属性进行设置。如果没有设置,spark 将会默认编译 hadoop2.2.0 版本的。注意到特定的 hadoop 版本需要对应特定配置文件:

hadoop version

profile required

1.x to 2.1.x

hadoop-1

2.2.x

hadoop-2.2

2.3.x

hadoop-2.3

2.4.x

hadoop-2.4

2.6.x and later 2.x

hadoop-2.6

for apache hadoop versions 1.x, cloudera cdh “mr1” distributions, and other hadoop versions without yarn, use:

对于 apache hadoop 版本 1.x ,cloudrea cdh “mr1”发行版本,和其他不基于yarn 的 hadoop 版本,请使用:

# apache hadoop 1.2.1

mvn -dhadoop.version=1.2.1 -phadoop-1 -dskiptests clean package

# cloudera cdh 4.2.0 with mapreduce v1

mvn -dhadoop.version=2.0.0-mr1-cdh4.2.0 -phadoop-1 -dskiptests clean package

you can enable the yarn profile and optionally set the yarn.version property if it is different from hadoop.version. spark only supports yarn versions 2.2.0 and later.

你可以使 “yarn” 配置文件成功启动,如果与 “hadoop.version” 参数值不一致的话,则可选配置 “yarn.version” 属性。spark 只支持 yarn 版本 2.2.0 及以上。

examples:

# apache hadoop 2.2.x

mvn -pyarn -phadoop-2.2 -dskiptests clean package

# apache hadoop 2.3.x

mvn -pyarn -phadoop-2.3 -dhadoop.version=2.3.0 -dskiptests clean package

# apache hadoop 2.4.x or 2.5.x

mvn -pyarn -phadoop-2.4 -dhadoop.version=version -dskiptests clean package

versions of hadoop after 2.5.x may or may not work with the -phadoop-2.4 profile (they were

released after this version of spark).

# different versions of hdfs and yarn.

mvn -pyarn -phadoop-2.3 -dhadoop.version=2.3.0 -dyarn.version=2.2.0 -dskiptests clean package

building with hive and jdbc support

to enable hive integration for spark sql along with its jdbc server and cli, add the -phive and phive-thriftserver profiles to your existing build options. by default spark will build with hive 0.13.1 bindings.

如果开启带 hive 整合以及 jdbc 服务器和命令行界面 (cli) 支持的 spark sql,添加 -phive 和 phive-thriftserver配置参数到现有的编译选项中。

# apache hadoop 2.4.x with hive 13 support

mvn -pyarn -phadoop-2.4 -dhadoop.version=2.4.0 -phive -phive-thriftserver -dskiptests clean package

building for scala 2.11

to produce a spark package compiled with scala 2.11, use the -dscala-2.11 property:

为了处理 由 scala 2.11 编译的 spark 包,请使用 -dscala-2.11:

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

mvn -pyarn -phadoop-2.4 -dscala-2.11 -dskiptests clean package

spark does not yet support its jdbc component for scala 2.11.

对于 scala 2.11 来说,spark 目前为止并不支持它的 jdbc.

spark tests in maven

tests are run by default via the scalatest maven plugin.

some of the tests require spark to be packaged first, so always run mvn package with -dskiptests the first time. the following is an example of a correct (build, test) sequence:

默认使用 scalatest maven plugin 运行测试

某些测试需要先打包 spark ,然后第一时间运行mvn包使用-dskiptests参数,所以第一次测试时运行 :

mvn -pyarn -phadoop-2.3 -dskiptests -phive -phive-thriftserver clean package

mvn -pyarn -phadoop-2.3 -phive -phive-thriftserver test

the scalatest plugin also supports running only a specific test suite as follows:

这个 scalatest 插件同样也支持只运行指定的测试组件,如下所示:

mvn -dhadoop.version=... -dwildcardsuites=org.apache.spark.repl.replsuite test

continuous compilation

we use the scala-maven-plugin which supports incremental and continuous compilation. e.g.

我们使用 scala-maven-plugin 插件支持渐进和持续编译,例如:

mvn scala:cc

should run continuous compilation (i.e. wait for changes). however, this has not been tested extensively. a couple of gotchas to note:

将进行持续编译(例如随时监测代码变化,一有改变就编译(wait for changes))。然而,这个并没有广泛测过。一系列陷阱记录下来:

it only scans the paths src/main and src/test (see docs), so it will only work from within certain submodules that have that structure.

you’ll typically need to run mvn install from the project root for compilation within specific submodules to work; this is because submodules that depend on other submodules do so via the spark-parent module).

thus, the full flow for running continuous-compilation of the core submodule may look more like:

· 它只扫描 src/main 和 src/test 路径(可查看 docs),所以它只会在具体某些具有那个结构的子模块下工作

· 你将需要运行 mvn install 从项目根目录下编译到在具体子模块中来工作。这是因为子模块通过 spark-parent 模块依赖其他子模块

所以,完整的运行 core 子模块连续-编译的代码段 可能更像下面这段:

$ mvn install

$ cd core

$ mvn scala:cc

building spark with intellij idea or eclipse

for help in setting up intellij idea or eclipse for spark development, and troubleshooting, refer to the wiki page for ide setup.

spark 开发环境中,关于搭建 intellij idea 或 eclipse 的有关帮助,和故障排除,请参考 wiki page for ide setup.

running java 8 test suites

running only java 8 tests and nothing else.

除了只运行 java8 测试工具集外,并没有运行其他工具集:

mvn install -dskiptests -pjava8-tests

java 8 tests are run when -pjava8-tests profile is enabled, they will run in spite of -dskiptests. for these tests to run your system must have a jdk 8 installation. if you have jdk 8 installed but it is not the system default, you can set java_home to point to jdk 8 before running the tests.

仅当 -pjava8-tests 配置参数开启生效时,java 8 测试就可以运行,尽管 -dskiptests 配置项开启时也会运行。为了在你系统中进行这些测试,就必须安装 jdk8。如果你已经安装了 jdk8 但是它并不是系统默认的 jdk,那么你在运行这些测试之前,可以先设置 java_home 来指向 jdk 8。

building for pyspark on yarn

pyspark on yarn is only supported if the jar is built with maven. further, there is a known problem with building this assembly jar on red hat based operating systems (see spark-1753). if you wish to run pyspark on a yarn cluster with red hat installed, we recommend that you build the jar elsewhere, then ship it over to the cluster. we are investigating the exact cause for this.

如果使用 mavern 编译 jar,则只支持 pyspark on yarn。另外,基于 red hat 内核的操作系统上,使用这个集成包编译会有一个问题(参见 spark-1753)。如果你需要在 red hat 机子上的 yarn 集群上运行 pyspark,我们建议你在别处编译 jar 包,然后封装到集群。我们正在调查具体的原因。

packaging without hadoop dependencies for yarn

the assembly jar produced by mvn package will, by default, include all of spark’s dependencies, including hadoop and some of its ecosystem projects. on yarn deployments, this causes multiple versions of these to appear on executor classpaths: the version packaged in the spark assembly and the version on each node, included with yarn.application.classpath. the hadoop-provided profile builds the assembly without including hadoop-ecosystem projects, like zookeeper and hadoop itself.

通过 mvn package 命令编译生成的 jar 包,默认会包含所有 spark 的依赖库,包括 hadoop 和一些它的生态体系的工程。在 yarn 部署上,这会在 executor classpath 出现多个不同版本的 jar 包:即每个节点包括 yarn.application.classpath 参数。使用 hadoop-provided 配置参数编译可以不集成 hadoop 生态体系的工程,比如 zookeeper 和 hadoop 它自身。

building with sbt

maven is the official build tool recommended for packaging spark, and is the build of reference. but sbt is supported for day-to-day development since it can provide much faster iterative compilation. more advanced developers may wish to use sbt.

maven 是 spark 编译官方推荐的编译工具,并且也是编译参考。但是 sbt 都在不断更新发展,这是因为它能提供更快的迭代编译。更多高级的开发者可能希望使用 sbt。

the sbt build is derived from the maven pom files, and so the same maven profiles and variables can be set to control the sbt build. for example:

sbt 编译是源自 maven pom 文件,使用相同的 maven 配置和变量同样可以控制 sbt 编译,例如:

build/sbt -pyarn -phadoop-2.3 assembly

testing with sbt

some of the tests require spark to be packaged first, so always run build/sbt assembly the first time. the following is an example of a correct (build, test) sequence:

某些测试需要先安装 spark,所以都先运行 build/sbt 编译。以下是一个正确(编译,测试)序列的例子:

build/sbt -pyarn -phadoop-2.3 -phive -phive-thriftserver assembly

build/sbt -pyarn -phadoop-2.3 -phive -phive-thriftserver test

to run only a specific test suite as follows:

如下,仅运行一个特定的测试工具集:

build/sbt -pyarn -phadoop-2.3 -phive -phive-thriftserver "test-only org.apache.spark.repl.replsuite"

to run test suites of a specific sub project as follows:

如下,运行一个指定的子项目测试套件:

build/sbt -pyarn -phadoop-2.3 -phive -phive-thriftserver core/test

speeding up compilation with zinc

zinc is a long-running server version of sbt’s incremental compiler. when run locally as a background process, it speeds up builds of scala-based projects like spark. developers who regularly recompile spark with maven will be the most interested in zinc. the project site gives instructions for building and running zinc; os x users can install it using brew install zinc.

zinc 是 sbt 的增量编译的长期运行服务器版本。当作为后台本地运行,它可以使得基于 scala 项目,比如 spark的编译速度加速。通常使用 maven 编译 spark 的开发者。这个工程网页给出了编译和运行zinc 的介绍,os 操作系统使用者可以使用 brew 来安装 zinc。

if using the build/mvn package zinc will automatically be downloaded and leveraged for all builds. this process will auto-start after the first time build/mvn is called and bind to port 3030 unless the zinc_port environment variable is set. the zinc process can subsequently be shut down at any time by running build/zinc-/bin/zinc -shutdown and will automatically restart whenever build/mvn is called.

如果使用 build/mvn 打包 zinc 将会自动下载所有版本。这个过程将会自动在第一次调用 build/mvn 和绑定到 3030 端口时自动开启,除非 zinc_port 环境变量已经设置。zinc 过程可以通过运行 build/zinc -/bin/zinc 在后来随时关闭,也可以无论何时调用 build/mvn 时,zinc进程将自动重启。

我的编译步骤(spark 1.5.0源码编译

我选择使用make-distribution.sh编译spark(修改make-distribution.sh脚本,注释掉下框中的信息并且手工修改版本信息):

#version=$("$mvn" help:evaluate -dexpression=project.version 2>/dev/null | grep -v "info" | tail -n 1)

#spark_hadoop_version=$("$mvn" help:evaluate -dexpression=hadoop.version $@ 2>/dev/null\

#    | grep -v "info"\

#   | tail -n 1)

#spark_hive=$("$mvn" help:evaluate -dexpression=project.activeprofiles -pl sql/hive $@ 2>/dev/null\

#    | grep -v "info"\

#    | fgrep --count "hive";\

# reset exit status to 0, otherwise the script stops here if the last grep finds nothing\

# because we use "set -o pipefail"

#   echo -n)

version=1.3.0

scala_version=2.10

spark_hadoop_version=2.5.0-cdh5.3.6

spark_hive=1

./make-distribution.sh [--name] [--tgz] [--mvn ] [--with-tachyon]

./make-distribution.sh --tgz -phadoop-2.4 -dhadoop-version=2.5.0-cdh5.3.6 -pyarn -phive-0.13.1 -phive-thriftserver

编译安装spark 1.5.x(building spark)的相关教程结束。

网站地图