首页 > 代码库 > Spark wordcount开发并提交到集群运行

Spark wordcount开发并提交到集群运行

使用的ide是eclipse

package com.luogankun.spark.baseimport org.apache.spark.SparkConfimport org.apache.spark.SparkContextimport org.apache.spark.SparkContext._/** * 统计字符出现次数 */object WorkCount {  def main(args: Array[String]) {    if (args.length < 1) {      System.err.println("Usage: <file>")      System.exit(1)    }    val conf = new SparkConf()    val sc = new SparkContext(conf)    val line = sc.textFile(args(0))    line.flatMap(_.split("\t")).map((_, 1)).reduceByKey(_+_).collect.foreach(println)        sc.stop  }}

 

导出成jar包。

 

提交到集群运行脚本: WordCount.sh

#!/bin/bashset -xcd $SPARK_HOME/binspark-submit --name SogouA --class com.luogankun.spark.base.WorkCount --master spark://hadoop000:7077 \--executor-memory 1G --total-executor-cores 1 /home/spark/lib/spark.jar hdfs://hadoop000:8020/hello.txt

 

执行WordCount.sh脚本