解决A master URL must be set in your configuration错误

Love The Way You Lie 2022-05-27 02:44 492阅读 0赞

在运行spark的测试程序SparkPi时,点击运行,出现了如下错误:

  1. Exception in thread "main" org.apache.spark.SparkException: A master URL must be set in your configuration
  2. at org.apache.spark.SparkContext.<init>(SparkContext.scala:185)
  3. at SparkPi$.main(SparkPi.scala:12)
  4. at SparkPi.main(SparkPi.scala)
  5. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  6. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
  7. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  8. at java.lang.reflect.Method.invoke(Method.java:606)
  9. at com.intellij.rt.execution.application.AppMain.main(AppMain.java:134)
  10. Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties

从提示中可以看出找不到程序运行的master,此时需要配置环境变量。
传递给spark的master url可以有如下几种:

local 本地单线程
local[K] 本地多线程(指定K个内核)
local[*] 本地多线程(指定所有可用内核)
spark://HOST:PORT 连接到指定的 Spark standalone cluster master,需要指定端口。
mesos://HOST:PORT 连接到指定的 Mesos 集群,需要指定端口。
yarn-client客户端模式 连接到 YARN 集群。需要配置 HADOOP_CONF_DIR。
yarn-cluster集群模式 连接到 YARN 集群。需要配置 HADOOP_CONF_DIR。

点击run–>edit configuration,在左侧点击该项目。在右侧VM options中输入“-Dspark.master=local”,指示本程序本地单线程运行,再次运行即可。

配置如图:
这里写图片描述

本文转载自csdn文章:解决A master URL must be set in your configuration错误

发表评论

表情:
评论列表 (有 0 条评论,492人围观)

还没有评论,来说两句吧...

相关阅读