Mac spark-shell错误初始化SparkContext


87

我试图在Mac OS Yosemite 10.10.5上使用以下命令启动spark 1.6.0(spark-1.6.0-bin-hadoop2.4)

"./bin/spark-shell". 

它具有以下错误。我也尝试安装不同版本的Spark,但是所有版本都有相同的错误。这是我第二次运行Spark。我以前的运行正常。

log4j:WARN No appenders could be found for logger (org.apache.hadoop.metrics2.lib.MutableMetricsFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Using Spark's repl log4j profile: org/apache/spark/log4j-defaults-repl.properties
To adjust logging level use sc.setLogLevel("INFO")
Welcome to
      ____              __
     / __/__  ___ _____/ /__
    _\ \/ _ \/ _ `/ __/  '_/
   /___/ .__/\_,_/_/ /_/\_\   version 1.6.0
      /_/

Using Scala version 2.10.5 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_79)
Type in expressions to have them evaluated.
Type :help for more information.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 WARN Utils: Service 'sparkDriver' could not bind on port 0. Attempting port 1.
16/01/04 13:49:40 ERROR SparkContext: Error initializing SparkContext.
java.net.BindException: Can't assign requested address: Service 'sparkDriver' failed after 16 retries!
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:444)
    at sun.nio.ch.Net.bind(Net.java:436)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:125)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:485)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1089)
    at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:430)
    at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:415)
    at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:903)
    at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:198)
    at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:348)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:357)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
    at java.lang.Thread.run(Thread.java:745)
java.net.BindException: Can't assign requested address: Service 'sparkDriver' failed after 16 retries!
    at sun.nio.ch.Net.bind0(Native Method)
    at sun.nio.ch.Net.bind(Net.java:444)
    at sun.nio.ch.Net.bind(Net.java:436)
    at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:214)
    at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74)
    at io.netty.channel.socket.nio.NioServerSocketChannel.doBind(NioServerSocketChannel.java:125)
    at io.netty.channel.AbstractChannel$AbstractUnsafe.bind(AbstractChannel.java:485)
    at io.netty.channel.DefaultChannelPipeline$HeadContext.bind(DefaultChannelPipeline.java:1089)
    at io.netty.channel.AbstractChannelHandlerContext.invokeBind(AbstractChannelHandlerContext.java:430)
    at io.netty.channel.AbstractChannelHandlerContext.bind(AbstractChannelHandlerContext.java:415)
    at io.netty.channel.DefaultChannelPipeline.bind(DefaultChannelPipeline.java:903)
    at io.netty.channel.AbstractChannel.bind(AbstractChannel.java:198)
    at io.netty.bootstrap.AbstractBootstrap$2.run(AbstractBootstrap.java:348)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:357)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:357)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
    at java.lang.Thread.run(Thread.java:745)

java.lang.NullPointerException
    at org.apache.spark.sql.SQLContext$.createListenerAndUI(SQLContext.scala:1367)
    at org.apache.spark.sql.hive.HiveContext.<init>(HiveContext.scala:101)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at org.apache.spark.repl.SparkILoop.createSQLContext(SparkILoop.scala:1028)
    at $iwC$$iwC.<init>(<console>:15)
    at $iwC.<init>(<console>:24)
    at <init>(<console>:26)
    at .<init>(<console>:30)
    at .<clinit>(<console>)
    at .<init>(<console>:7)
    at .<clinit>(<console>)
    at $print(<console>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.spark.repl.SparkIMain$ReadEvalPrint.call(SparkIMain.scala:1065)
    at org.apache.spark.repl.SparkIMain$Request.loadAndRun(SparkIMain.scala:1346)
    at org.apache.spark.repl.SparkIMain.loadAndRunReq$1(SparkIMain.scala:840)
    at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:871)
    at org.apache.spark.repl.SparkIMain.interpret(SparkIMain.scala:819)
    at org.apache.spark.repl.SparkILoop.reallyInterpret$1(SparkILoop.scala:857)
    at org.apache.spark.repl.SparkILoop.interpretStartingWith(SparkILoop.scala:902)
    at org.apache.spark.repl.SparkILoop.command(SparkILoop.scala:814)
    at org.apache.spark.repl.SparkILoopInit$$anonfun$initializeSpark$1.apply(SparkILoopInit.scala:132)
    at org.apache.spark.repl.SparkILoopInit$$anonfun$initializeSpark$1.apply(SparkILoopInit.scala:124)
    at org.apache.spark.repl.SparkIMain.beQuietDuring(SparkIMain.scala:324)
    at org.apache.spark.repl.SparkILoopInit$class.initializeSpark(SparkILoopInit.scala:124)
    at org.apache.spark.repl.SparkILoop.initializeSpark(SparkILoop.scala:64)
    at org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1$$anonfun$apply$mcZ$sp$5.apply$mcV$sp(SparkILoop.scala:974)
    at org.apache.spark.repl.SparkILoopInit$class.runThunks(SparkILoopInit.scala:159)
    at org.apache.spark.repl.SparkILoop.runThunks(SparkILoop.scala:64)
    at org.apache.spark.repl.SparkILoopInit$class.postInitialization(SparkILoopInit.scala:108)
    at org.apache.spark.repl.SparkILoop.postInitialization(SparkILoop.scala:64)
    at org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply$mcZ$sp(SparkILoop.scala:991)
    at org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply(SparkILoop.scala:945)
    at org.apache.spark.repl.SparkILoop$$anonfun$org$apache$spark$repl$SparkILoop$$process$1.apply(SparkILoop.scala:945)
    at scala.tools.nsc.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:135)
    at org.apache.spark.repl.SparkILoop.org$apache$spark$repl$SparkILoop$$process(SparkILoop.scala:945)
    at org.apache.spark.repl.SparkILoop.process(SparkILoop.scala:1059)
    at org.apache.spark.repl.Main$.main(Main.scala:31)
    at org.apache.spark.repl.Main.main(Main.scala)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.apache.spark.deploy.SparkSubmit$.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:731)
    at org.apache.spark.deploy.SparkSubmit$.doRunMain$1(SparkSubmit.scala:181)
    at org.apache.spark.deploy.SparkSubmit$.submit(SparkSubmit.scala:206)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:121)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

<console>:16: error: not found: value sqlContext
         import sqlContext.implicits._
                ^
<console>:16: error: not found: value sqlContext
         import sqlContext.sql

然后我添加

export SPARK_LOCAL_IP="127.0.0.1"

到spark-env.sh,错误更改为:

 ERROR : No route to host
    java.net.ConnectException: No route to host
        at java.net.Inet6AddressImpl.isReachable0(Native Method)
        at java.net.Inet6AddressImpl.isReachable(Inet6AddressImpl.java:77)
        at java.net.InetAddress.isReachable(InetAddress.java:475)
...
<console>:10: error: not found: value sqlContext
       import sqlContext.implicits._
              ^
<console>:10: error: not found: value sqlContext
       import sqlContext.sql

在我的工作计算机10.10.5上-如果导出该变量,也会出现(不同的)错误,因此无论如何我都不认为这是修复程序。没有它,它运行良好。您是否尝试在DEBUG日志级别运行以获得更多信息?
jbrown 2016年

1
这可能是因为Spark目前不适用于ipv6。您可以尝试bin/spark-shell --driver-java-options "-Djava.net.preferIPv4Stack=true"
zsxwing

我尝试了@zsxwing,它也有类似的错误16/01/05 10:29:39 ERROR : No route to host 16/01/05 10:29:39 ERROR : No route to host java.net.ConnectException: No route to host at java.net.Inet4AddressImpl.isReachable0(Native Method) at java.net.Inet4AddressImpl.isReachable(Inet4AddressImpl.java:70) at java.net.InetAddress.isReachable(InetAddress.java:475) at java.net.InetAddress.isReachable(InetAddress.java:434) at tachyon.util.NetworkUtils.getLocalIpAddress(NetworkUtils.java:122) at tachyon.util.NetworkUtils.getLocalHostName(NetworkUtils.java:78)...

也许您的计算机中存在一些网络配置问题。你能尝试一下ping 127.0.0.1吗?
zsxwing

@zsxwing我尝试ping 127.0.0.1,它可以正常工作。

Answers:


139

以下步骤可能会有所帮助:

  1. 通过使用“主机名”命令获取您的主机名。

  2. 如果不存在主机名,请在/ etc / hosts文件中输入以下内容:

    127.0.0.1      your_hostname
    

希望这可以帮助!!


谢谢你的建议。当我尝试从jupyter客户端创建sparkContext时,在ubuntu jupyter服务器上遇到了类似的问题。在主机文件中添加映射解决了问题:-)
Julien Bachmann

2
您应该在Mac中编辑“ sudo nano / private / etc / hosts”
赛义德(Saeed)

1
运行ping $(hostname),这必须解析为127.0.0.1
Thomas Decaux

为我修复。谢谢!
安德烈斯·梅贾

1
运行此命令对我也有帮助-> sudo主机名-s 127.0.0.1
MRTJ

119

在网络之间切换时,我总是会得到的。这解决了它:

$ sudo hostname -s 127.0.0.1


4
这也为我工作。就我而言,它是在我登录公司VPN后立即发生的。在开发我的Spark应用程序时,我必须每周运行几次。
AdrianVeidt

企业vpn-隐藏的敌人
StephenBoesch

1
在GNU / Linux上:$ sudo hostname -b 127.0.0.1
orluke '18

1
太棒了 由于公司vpn,我也遇到了这个问题,并对此进行了修复。
Dileep Kumar Patchigolla '18

1
谢谢,那工作。您能否解释一下为什么行得通?
vitalii

34

我是从当前的master分支使用version构建的2.0.0-SNAPSHOT。加入后export SPARK_LOCAL_IP="127.0.0.1",以load-spark-env.sh它为我工作。我正在使用Macos 10.10.5。所以可能是版本问题?


3
我能够使用$ SPARK_LOCAL_IP="127.0.0.1" gradle my-gradle-task-using-local-spark。使用VPN时出现问题。我正在使用Macos 10.11.1。
谢尔盖·奥尔山斯基

31

spark.driver.host如果使用IDE,只需将设置为您的本地主机

SparkConf conf = new  SparkConf().setMaster("local[2]").setAppName("AnyName").set("spark.driver.host", "localhost");
JavaSparkContext sc = new JavaSparkContext(conf);

local [2]是什么意思?我只是将master设置为“ local”,同时设置了spark.driver.host属性,它解决了我的问题。
medloh '17

spark.driver.host直接将其添加到代码中的好主意,而不是弄乱$SPARK_HOME/conf/spark-defaults.conf
StephenBoesch

这是我正在寻找的确切解决方案。有效。为什么仅在使用IDE时才应该这样?这会对非IDE测试产生影响吗?
佛陀

8

我认为有两个错误。

  1. 您的Spark本地ip不正确,需要更改为127.0.0.1。
  2. 您没有正确定义sqlContext。

对于1,我尝试过:

  • 1)在〜/ .bash_profile中导出SPARK_LOCAL_IP =“ 127.0.0.1”
  • 2)在$ SPARK_HOME下的load-spark-env.sh中添加了导出SPARK_LOCAL_IP =“ 127.0.0.1”

但是两者都没有。然后,我尝试了以下操作,并且有效:

val conf = new SparkConf().
    setAppName("SparkExample").
    setMaster("local[*]").
    set("spark.driver.bindAddress","127.0.0.1")
val sc = new SparkContext(conf)

对于2.您可以尝试:

sqlContext = SparkSession.builder.config("spark.master","local[*]").getOrCreate()

然后 import sqlContext.implicits._

SparkSession中的构建器将自动使用SparkContext(如果存在),否则将创建一个。如果需要,可以显式创建两个。


7

如果您不想更改Mac的主机名,则可以执行以下操作:

  1. spark-env.sh.template在您的计算机上找到模板文件(可能在中/usr/local/Cellar/apache-spark/2.1.0/libexec/conf/)。
  2. cp spark-env.sh.template spark-env.sh
  3. export SPARK_LOCAL_IP=127.0.0.1在注释下添加本地IP。

开始spark-shell并享受它。


4

如果您使用Scala在IDE中运行代码,并且遇到相同的问题,并且没有使用上面指出的SparkConf()和SparkSession(),则可以按如下所示绑定本地主机地址,因为设置仅适用在SparkConf()中。您应该使用.config()来设置火花配置,如下所示:

    val spark = SparkSession
       .builder()
       .appName("CSE512-Phase1")
       .master("local[*]").config("spark.driver.bindAddress", "localhost")
       .getOrCreate()

3

导出SPARK_LOCAL_IP = 127.0.0.1(对于Mac .bash_profile)


2

有时防火墙会阻止创建和绑定套接字。确保您的防火墙未启用,并且您还必须在/ etc / hosts中检查计算机的IP,并确保它正常,然后重试:

sudo ufw disable

1
哎呀 在Linux上感谢大家的注意
Mahdi Esmailoghli

2

当您在不同的网络之间切换时会发生这种情况(VPN-PROD,基于公司网络的CI以访问不同的环境)。

每当我切换VPN时,我都会遇到相同的问题。

在Mac上使用主机名值更新sudo / etc / hosts。


2
sparkContext = new JavaSparkContext("local[4]", "Appname")

export SPARK_LOCAL_IP=127.0.0.1

只是做上面对我有用。


0

在Mac中,在“系统偏好设置”->“网络”->“单击您连接的Wifi(它应该显示绿色图标)”中检查IP->“网络名称”正上方检查IP。

在../conf/spark-env.sh中进行以下输入:

SPARK_MASTER_HOST=<<your-ip>>
SPARK_LOCAL_IP=<<your-ip>>

而不是尝试“火花壳”。进行以上更改对我有用。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.