1.编译环境
CentOS6.6 JDK1.7.0_80 Maven3.2.5
2.下载Spark源代码并解压
[[email protected] ~]$ pwd /home/yyl [[email protected] make]$ pwd /home/yyl/make [[email protected] make]$ wget http://mirrors.cnnic.cn/apache/spark/spark-1.5.0/spark-1.5.0.tgz [[email protected] make]$ tar -zxf spark-1.5.0.tgz
3.编译
解压后的源码包的根目录下有个 pom.xml 文件,这个文件就是使用 Maven 编译 Spark 的脚步文件。
OK,现在开始编译:
[[email protected] spark-1.5.0]$ pwd /home/yyl/make/spark-1.5.0 [[email protected] spark-1.5.0]$ export MAVEN_OPTS="-Xmx2g -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=512m" [[email protected] spark-1.5.0]$ mvn -Pyarn -Phadoop-2.4 -Dhadoop.version=2.4.0 -DskipTests clean package
编译过程中报错:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-enforcer-plugin:1.4:enforce (enforce-versions) on project spark-parent_2.10: Some Enforcer rules have failed. Look above for specific messages explaining why the rule failed. -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
这个错误有两个解决办法:一是编译时加入 -Denforcer.skip=true 参数;二是修改 pom.xml 文件中 properties 定义的变量的值为实际环境中 maven 、java 的版本
[[email protected] spark-1.5.0]$ vim pom.xml <java.version>1.7</java.version> <maven.version>3.2.5</maven.version>
解决上面的错误后重新编译,结果又报错:
[INFO] ------------------------------------------------------------------------ [INFO] Reactor Summary: [INFO] [INFO] Spark Project Parent POM ........................... SUCCESS [ 4.619 s] [INFO] Spark Project Launcher ............................. SUCCESS [ 11.669 s] [INFO] Spark Project Networking ........................... SUCCESS [ 11.537 s] [INFO] Spark Project Shuffle Streaming Service ............ SUCCESS [ 6.245 s] [INFO] Spark Project Unsafe ............................... SUCCESS [ 17.217 s] [INFO] Spark Project Core ................................. SUCCESS [04:15 min] [INFO] Spark Project Bagel ................................ SUCCESS [ 22.739 s] [INFO] Spark Project GraphX ............................... SUCCESS [01:09 min] [INFO] Spark Project Streaming ............................ SUCCESS [02:04 min] [INFO] Spark Project Catalyst ............................. SUCCESS [02:43 min] [INFO] Spark Project SQL .................................. SKIPPED ...... --------------------------------------------------- java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: scala.reflect.internal.Types$TypeError: bad symbolic reference. A signature in WebUI.class refers to term servlet in value org.jetty which is not available. It may be completely missing from the current classpath, or the version on the classpath might be incompatible with the version used when compiling WebUI.class. at scala.reflect.internal.pickling.UnPickler$Scan.toTypeError(UnPickler.scala:847) at scala.reflect.internal.pickling.UnPickler$Scan$LazyTypeRef.complete(UnPickler.scala:854) at scala.reflect.internal.pickling.UnPickler$Scan$LazyTypeRef.load(UnPickler.scala:863) at scala.reflect.internal.Symbols$Symbol.typeParams(Symbols.scala:1489) ......
这是什么原因呢,查看Spark1.5官方编译文档,有这么一句话:
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. 果断升级 maven 到3.3.3,再次编译,OK,编译成功!
如果你想要编译兼容 Scala2.11.x 的 Spark,则使用如下命令编译:
[[email protected] spark-1.5.0]$ ./dev/change-scala-version.sh 2.11 [[email protected] spark-1.5.0]$ mvn -Pyarn -Phadoop-2.4 -Dscala-2.11 -DskipTests clean package
编译支持 Hive 和 JDBC 的 Spark
[[email protected] spark-1.5.0]$ mvn -Pyarn -Phadoop-2.4 -Dhadoop.version=2.4.0 -Phive -Phive-thriftserver -DskipTests clean package
4. 生成部署包
源码包的根目录下有个 make-distribution.sh 脚本,这个脚本可以打包Spark的发行包,make-distribution.sh 文件其实就是调用了 Maven 进行编译,可以通过下面的命令运行:
[[email protected] spark-1.5.0]$ ./make-distribution.sh --tgz -Pyarn -Phadoop-2.4 -Dhadoop.version=2.4.0 -Phive -Phive-thriftserver -DskipTests clean package
make-distribution.sh的语法:./make-distribution.sh [--name] [--tgz] [--mvn <mvn-command>] [--with-tachyon] <maven build options>
--tgz :在根目录下生成 spark-$VERSION-bin.tgz ,不加此参数时不生成 tgz 文件,只生成 /dist 目录
--name NAME :和 tgz 结合可以生成 spark-$VERSION-bin-$NAME.tgz 的部署包,不加此参数时 NAME 为 hadoop 的版本号
--with-tachyon :是否支持内存文件系统 Tachyon ,不加此参数时不支持 tachyon