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
作者:
丹江湖畔養蜂子的趙大爹
出處:http://www.cnblogs.com/honeybee/
關于作者:丹江湖畔養蜂子的趙大爹
本文版權歸作者和部落格園共有,歡迎轉載,但未經作者同意必須保留此段聲明,且在文章頁面明顯位置給出原文連結