欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

org.apache.spark.SparkException: A master URL must be set in your configuration

程序员文章站 2022-07-12 14:16:27
...

 

org.apache.spark.SparkException: A master URL must be set in your configuration

错误

org.apache.spark.SparkException: A master URL must be set in your configuration
	at org.apache.spark.SparkContext.<init>(SparkContext.scala:379) ~[spark-core_2.11-2.1.4-SNAPSHOT.jar:2.1.4-SNAPSHOT]
	at org.apache.spark.SparkContext$.getOrCreate(SparkContext.scala:2323) [spark-core_2.11-2.1.4-SNAPSHOT.jar:2.1.4-SNAPSHOT]
	at org.apache.spark.sql.SparkSession$Builder$$anonfun$6.apply(SparkSession.scala:876) [spark-sql_2.11-2.1.4-SNAPSHOT.jar:2.1.4-SNAPSHOT]
	at org.apache.spark.sql.SparkSession$Builder$$anonfun$6.apply(SparkSession.scala:868) [spark-sql_2.11-2.1.4-SNAPSHOT.jar:2.1.4-SNAPSHOT]
	at scala.Option.getOrElse(Option.scala:121) [scala-library-2.11.8.jar:na]
	at org.apache.spark.sql.SparkSession$Builder.getOrCreate(SparkSession.scala:868) [spark-sql_2.11-2.1.4-SNAPSHOT.jar:2.1.4-SNAPSHOT]
	at org.apache.spark.examples.sql.JavaSparkSQLExample.main(JavaSparkSQLExample.java:96) [classes/:na]

从提示中可以看出找不到程序运行的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 As --> Run Configurations --> arguments --> VM arguments 设置为“-Dspark.master=local”

org.apache.spark.SparkException: A master URL must be set in your configuration

org.apache.spark.SparkException: A master URL must be set in your configuration