1. 程式人生 > 其它 >linux上執行spark java程式

linux上執行spark java程式

spark-submit 命令:

在spark安裝目錄的bin目錄下有一個spark-submit指令碼,可以用來提交執行spark程式

如果配置了spark的path可以直接使用spark-submit命令


編譯構建spark程式

使用sbt 或者maven構建程式生成jar包
spark-submit的使用

spark-submit \
--class <main-class> \
--master <master-url> \
--deploy-mode <deploy-mode> \
--conf <key>=<value> \
... # other options


<application-jar> \
[application-arguments]

--class: 要執行的jar包裡的類,比如 test.spark.examples

--master: master的地址 比如 spark://23.195.26.187:7077

--deploy-mode: 部署模式

--conf: 執行時的一些配置 “key=value”型別

application-jar: 要執行的jar包路徑,可以是hdfs:// 開頭或者 file:// 開頭。比如:/root/program/spark/test.jar

application-arguments: 要傳給執行類主方法的引數,沒有可以不傳


例子

# 本地執行,使用8個核心,傳入引數100
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master local[8] \
/path/to/examples.jar \
100

# Run on a Spark standalone cluster in client deploy mode
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master spark://207.184.161.138:7077 \
--executor-memory 20G \


--total-executor-cores 100 \
/path/to/examples.jar \
1000

# Run on a Spark standalone cluster in cluster deploy mode with supervise
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master spark://207.184.161.138:7077 \
--deploy-mode cluster \
--supervise \
--executor-memory 20G \
--total-executor-cores 100 \
/path/to/examples.jar \
1000

# Run on a YARN cluster
export HADOOP_CONF_DIR=XXX
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master yarn \
--deploy-mode cluster \ # can be client for client mode
--executor-memory 20G \
--num-executors 50 \
/path/to/examples.jar \
1000

# Run a Python application on a Spark standalone cluster
./bin/spark-submit \
--master spark://207.184.161.138:7077 \
examples/src/main/python/pi.py \
1000

# Run on a Mesos cluster in cluster deploy mode with supervise
./bin/spark-submit \
--class org.apache.spark.examples.SparkPi \
--master mesos://207.184.161.138:7077 \
--deploy-mode cluster \
--supervise \
--executor-memory 20G \
--total-executor-cores 100 \
http://path/to/examples.jar \
1000


示例:

上傳JAR包路徑:

/root/project/test-1.0.0.jar

命令:

spark-submit --class SparkExample --master local /root/project/test-1.0.0.jar

備註:

1、官網: http://spark.apache.org/docs/latest/submitting-applications.html