spark任務提交到yarn上命令總結


spark任務提交到yarn上命令總結

1. 使用spark-submit提交任務

  • 集群模式執行 SparkPi 任務,指定資源使用,指定eventLog目錄
spark-submit  --class org.apache.spark.examples.SparkPi \
    --master yarn \
    --conf spark.eventLog.dir=hdfs://dbmtimehadoop/tmp/spark2 \
    --deploy-mode cluster \
    --driver-memory 4g \
    --executor-memory 2g \
    --executor-cores 1 \
    --queue thequeue \
    $SPARK_HOME/examples/jars/spark-examples*.jar \
    10
  • 不指定資源,使用yarn的默認資源分配。
spark-submit  --class org.apache.spark.examples.SparkPi \
    --master yarn \
    --conf spark.eventLog.dir=hdfs://dbmtimehadoop/tmp/spark2 \
    --deploy-mode cluster \
    $SPARK_HOME/examples/jars/spark-examples*.jar 10
  • 動態的加載spark配置
./bin/spark-submit --name "My app" --master local[4] --conf spark.eventLog.enabled=false
  --conf "spark.executor.extraJavaOptions=-XX:+PrintGCDetails -XX:+PrintGCTimeStamps" myApp.jar
  • 客戶端模式執行 SparkPi 任務:spark-submit
spark-submit  --class org.apache.spark.examples.SparkPi \
    --conf spark.eventLog.dir=hdfs://dbmtimehadoop/tmp/spark2 \
    --master yarn \
    --deploy-mode client \
    --driver-memory 4g \
    --executor-memory 2g \
    --executor-cores 1 \
    $SPARK_HOME/examples/jars/spark-examples*.jar \
    10

2. 使用spark-shell提交任務到yarn上

  • 使用spark-shell測試wordcont:使用-jars加載任務運行依賴的jar包,多個jar包以逗號分隔。
    spark-shell --master yarn --conf spark.eventLog.dir=hdfs://dbmtimehadoop/tmp/spark2 --jars /home/fxzhao/hadoop-lzo-0.4.20-SNAPSHOT.jar

在隨后的終端框中如下scala腳本:統計hdfs://dbmtimehadoop/tmp/fuxin.zhao/wordcounttest 中各個單詞的數量。
在scala終端中輸入 “:paste”可以輸入多條scala語句。按CRTL+d 結束。

val textFile = sc.textFile("hdfs://dbmtimehadoop/tmp/fx.zhao/wordcounttest")
val counts = textFile.flatMap(line => line.split(" "))
                 .map(word => (word, 1))
                 .reduceByKey(_ + _)
counts.saveAsTextFile("hdfs://dbmtimehadoop/tmp/fx.zhao/wordcounttest_res")

##########將統計結果按照key排序。
val textFile = sc.textFile("hdfs://dbmtimehadoop/tmp/fx.zhao/wordcounttest")
val counts = textFile.flatMap(line => line.split(" "))
                 .map(word => (word, 1))
                 .reduceByKey(_ + _)
                 .sortByKey()
counts.saveAsTextFile("hdfs://dbmtimehadoop/tmp/fx.zhao/wordcounttest_res")

  • Spark-shell 啟動時添加添加依賴jar包:
    spark-shell --conf spark.eventLog.dir=hdfs://dbmtimehadoop/tmp/spark2 --jars $HADOOP_HOME/share/hadoop/common/lib/hadoop-lzo-0.4.20-SNAPSHOT.jar

3.spark-sql提交任務到spark的兩種方式:

  • 本地模式:
    $ spark-sql --master local

  • yarn模式
    $ spark-sql --master yarn
    //啟動spark-sql時指定eventLog的位置等其他配置(可以通過--conf 來配置修改默認的多個參數)。
    $ spark-sql --master yarn --conf spark.eventLog.dir=hdfs://dbmtimehadoop/tmp/spark2 --conf spark.sql.hive.metastore.version=2.1.0


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM