zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    JVM学习记录-垃圾收集器
    JVM学习记录-垃圾回收算法
    Java设计模式学习记录-策略模式
    【转】Java方向如何准备技术面试答案(汇总版)
    Java设计模式学习记录-代理模式
    JVM之ParNew收集器
    JVM之CMS收集器
    动态代理:cgib、jdk、java javassist
    JVM之Class文件结构
    JAVA之直接内存(DirectMemory)
  • 原文地址:https://www.cnblogs.com/honeybee/p/6434656.html
Copyright © 2011-2022 走看看