Spark 提交应用程序

来源:互联网 发布:scratch live for mac 编辑:程序博客网 时间:2024/06/07 06:21

提交应用程序

原文地址: http://spark.apache.org/docs/latest/submitting-applications.html
仅限交流使用,转载请注明出处。如有错误,欢迎指出!

Henvealf/译

使用 spark-submit 脚本来运行你的应用程序到集群上。

绑定你的应用的依赖

当你的程序依赖一些其他的项目时,需要将依赖一起放进 jar 包中。这样就需要创建一个 assembly jar(或者 “uber” jar),让里面包括你自己的代码以及依赖包。 创建 assembly jar 的时候,要将 Spark 与 Hadoop 的设置为 provided 依赖,因为在运行的时候集群管理器会提供这些依赖。

打好 assembly jar 后,就可以使用 bin/spark-submit 来运行了,一会详细说。

对于 Python, 你可以使用 spark-submit 命令的 –py-files 参数来添加 .py .zip 或者 .egg 文件了。如果你有多个 Python 文件,那么就放在 .zip 或 .egg 中吧。

使用 spark-submit 运行应用程序

下面是一个模板:

./bin/spark-submit \  --class <main-class> \  --master <master-url> \  --deploy-mode <deploy-mode> \  --conf <key>=<value> \  ... # other options  <application-jar> \  [application-arguments]

上面列出了一些常用的选项:

  • –class : 应用程序的入口点(主类) 例如 org.apache.spark.examples.SparkPi

  • –master : 集群的 master URL. (例如 spark://23.195.26.187:7077)

  • –deploy-mode : 是否将你的 driver 部署到 worker 节点上(cluster),或者使用本地来作为外部的客户端(client),默认为 client

  • –conf : 任意的 Spark 配置属性,如果属性值中有空格,就用引号包裹上整个配置 “key=value”

  • application-jar : jar包或者单个 .py 文件的路径,并且路径必须在你的集群上全局可用,比如:在你目前的所有节点的 hdfs:// 或者 file:// 路径。

  • –py-files : 当应用程序为 zip 或者 egg 时,就用此来代替 application-jar

  • application-arguments : 传入你 main 方法中的参数。

关于 deploy-mode 选项

如果你设置了防火墙的的提交任务的机器 与 worker 距离很近,比如说在一个集群上。那么建议使用 client 模式,使用这种模式能在本机控制台上看到应用程序在控制台上的输出。

如果提交任务的机器距离 worker 节点太远,为了避免网络传输的开销与网络安全,建议使用 cluster 模式。

使用 –help 来查看更多信息

下面有一些例子

# Run application locally on 8 cores./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 clusterexport 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

Master URLs

Master URL 意思 local 在本地运行一个 worker local[K] 在本地运行 K 个 worker 线程(理想情况,请与你的 cpu 核数相同) local[*] 在本地运行你机器CPU核数的 worker 线程。 spark://HOST:PORT 连接单机集群的master。默认端口号为 7077 mesos://HOST:PORT 连接 Mesos 集群,端口号默认为 5050 yarn 连接 yarn 集群, client 或者 cluster模式,取决于 –deploy-mode的值。集群的位置将会从 HADOOP_CONF_DIR 或者 YARN_CONF_DIR 变量中指向的配置文件中寻找。

从文件中加载配置

默认会去 conf/spark-defaults.conf 中去读取选项。

如果配置文件中设置了你想要的属性,你就不用在 spark-submit 后设置该属性了。

SparkConf 中设置的属性优先级高于配置文件中的属性。

使用 –verbose 输出调试时信息,来查看配置选项。

依赖管理器

可使用 –jars 来添加 jar 依赖。

支持的URL模式有:

  • file

  • hdfs: http: https: ftp:

  • local:

1 0
原创粉丝点击