spark 安装 0.8 版本
操作系统Ubuntu 10.04,已经安装JDK 1.7。
http://spark.incubator.apache.org/downloads.html
2. spark 0.8依赖于scala 2.9.3,安装这个版本的scala。
2.1 下载scala 0.9.3 http://www.scala-lang.org/download/2.9.3.html#Software_Requirements
2.2 解压缩到/usr/local/scala目录下
2.3 在/etc/profile添加一行代码:
export PATH=$PATH:/usr/local/scala/bin
3. 编译spark
3.1 在~/setup/spark-new/目录下,将spark-0.8.0-incubating.tgz解压缩到目录~/setup/spark-new/spark-0.8.0:
tar xvf spark-0.8.0-incubating.tgz
3.2 运行sbt进行编译:
. /etc/profile #更新环境变量
cd ~/setup/spark-new/spark-0.8.0
sbt/sbt assembly
这个步骤会下载很多库,然后进行编译,编译时间大概会在1个小时左右。
4. 交互式运行
4.1 参考这里:http://spark.incubator.apache.org/docs/latest/quick-start.html
4.2 在运行例子前,如果系统已经安装了Hadoop,所以需要启动了Hadoop,然后把spark的README.md文件复制到HDFS上。
4.3 启动spark shell:
cd /home/brian/setup/spark-new/spark-0.8.0
./shark-shell
4.4 按照运行例子,处理README.md文件。
5. 写scala写一个标准的spark app
5.1 创建一个目录~/test
5.2 test目录的内容如下,其中,simple.sbt和SimpleApp.scala是文件,其他都是目录
find .
.
./simple.sbt
./src
./src/main
./src/main/scala
./src/main/scala/SimpleApp.scala
5.3 simple.sbt文件内容如下:
name := "Simple Project"
version := "1.0"
scalaVersion := "2.9.3"
libraryDependencies += "org.apache.spark" %% "spark-core" % "0.8.0-incubating"
resolvers += "Akka Repository" at "http://repo.akka.io/releases/"
5.4 SimpleApp.scala文件内容如下:
import org.apache.spark.SparkContext
import org.apache.spark.SparkContext._
object SimpleApp{
def main(args: Array[String]){
val logFile = "/home/brian/setup/spark-new/spark-0.8.0/README.md"
val sc = new SparkContext("local", "Simple App",
"/home/brian/setup/spark-new/spark-0.8.0",
List("target/scala-2.9.3/simple-project_2.9.3-1.0.jar"))
val logData = sc.textFile(logFile, 2).cache()
val numAs = logData.filter(line => line.contains("a")).count()
val numBs = logData.filter(line => line.contains("b")).count()
println("Lines with a: %s, lines with b: %s".format(numAs, numBs))
}
}
5.5 编译:
cd ~/test
~/setup/spark-new/spark-0.8.0/sbt/sbt package
~/setup/spark-new/spark-0.8.0/sbt/sbt run
5.6 运算结果:
Lines with a: 66, lines with b: 35