打包并提交运行Spark应用程序jar包

来源:互联网 发布:linux 驱动 ioctl 编辑:程序博客网 时间:2024/06/05 14:58

基于eclipse的Spark IDE可在 http://scala-ide.org/ 下载。

以WordCount为例:

  1. package com.lxw.test
  2.  
  3. import org.apache.spark.{SparkConf, SparkContext}
  4. import SparkContext._
  5.  
  6. object WordCount {
  7. def main (args: Array[String]) {
  8. if(args.length < 2) {
  9. println("Usage: WordCount ")
  10. System.exit(1)
  11. }
  12. val hdfsIn = args(0);
  13. val hdfsOut = args(1);
  14. val sc = new SparkContext(new SparkConf().setAppName("WordCount"))
  15. val srcData = sc.textFile(hdfsIn)
  16. val result = srcData.flatMap(_.split("\\s+")).map((_,1)).reduceByKey(_+_)
  17. result.saveAsTextFile(hdfsOut)
  18. }
  19. }

在eclipse中将程序打成普通的Java jar包即可。

在Spark的一台Client机器上使用spark-submit来提交运行jar包:

  1. $SPARK_HOME/bin/spark-submit \
  2. --name "lxw1234-wordcount" \
  3. --master spark://192.168.1.130:7077 \
  4. --executor-memory 1G \
  5. --class com.lxw.test.WordCount \
  6. /home/lxw1234/lxw-spark.jar /logs/site/2015-05-14/ /tmp/lxwoutput

本文转自:http://lxw1234.com/archives/2015/05/215.htm

0 0