apache spark - 无法连接到远程spark独立系统

时间:2016-04-21 14:41:48

标签: java apache-spark

我的独立火花正在ec2实例上运行。但是当我尝试通过Java代码连接到它时,我收到了一个错误。 Java代码是:

    SparkConf conf = new SparkConf().setAppName("App_Name")
            .setMaster("spark://172.31.2.165:4040");
            //.set("spark.ui.port","4040");
    JavaSparkContext context = new JavaSparkContext(conf);

错误是:

java.io.IOException: Failed to connect to /172.31.2.165:4040
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:216)
    at org.apache.spark.network.client.TransportClientFactory.createClient(TransportClientFactory.java:167)
    at org.apache.spark.rpc.netty.NettyRpcEnv.createClient(NettyRpcEnv.scala:200)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:187)
    at org.apache.spark.rpc.netty.Outbox$$anon$1.call(Outbox.scala:183)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection timed out: no further information: /172.31.2.165:4040
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
    at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:224)
    at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:289)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:528)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)
    ... 1 more

1 个答案:

答案 0 :(得分:0)

  • 默认情况下,您应该使用端口7077连接到主服务器,端口4040用于Web UI
  • 确保端口7077可以从您运行的任何地方访问Spark作业,例如在从EC2外部运行主服务器时在主服务器所在的安全组中打开它