我能够在AWS EC2上创建单节点hadoop集群 . 我在那里保存了一个文件(sample.txt),我试图通过我的应用程序远程访问 . 但是,连接被拒绝 .

我能够在 http://ec2-...:50070 上查看该文件,一切似乎都运行良好 .

EC2的安全性设置为

输入|协议|港口范围|目的地/来源

所有交通|全部|全部| 0.0.0.0/0

JPS

13168 SecondaryNameNode
12977 DataNode
12821 NameNode
13449 NodeManager
14393 Jps
4585 JobHistoryServer
13322 ResourceManager

核心站点

<property>
   <name>fs.defaultFS</name>
   <value>hdfs://localhost:8020</value>
</property>

HDFS现场

<property>
    <name>dfs.replication</name>
    <value>1</value>
  </property>

  <property>
    <name>dfs.namenode.name.dir</name>
    <value>file:///usr/local/hadoop/.../namenode</value>
  </property>

 <property>
   <name>dfs.datanode.data.dir</name>
   <value>file:///usr/local/hadoop/.../datanode</value>
 </property>

我正在尝试从aws加载hdfs文件并使用它做一些事情 .

val hdfsLocation = "hdfs://ec2-xx-xx-xx-xx.compute-1.amazonaws.com:8020/tmp/sample.txt"

val spark = SparkSession
      .builder()
      .master("local[*]")
      .appName("sample")
      .getOrCreate()

val sample = spark.read.textFile(hdfsLocation)

ERROR

使用Spark的默认log4j配置文件:org / apache / spark / log4j-defaults.properties线程“main”中的异常java.net.ConnectException:从sample-linux / 127.0.1.1调用ec2 - *** . compute-1 . amazonaws.com:8020连接异常失败:java.net.ConnectException:连接被拒绝;有关更多详细信息,请参阅:sun.reflect的Sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)中的sun.reflect.NativeConstructorAccessorImpl.newInstance0(本地方法)中的http://wiki.apache.org/hadoop/ConnectionRefused . 在org.apache的org.apache.hadoop.net.NetUtils.wrapWithMessage(NetUtils.java:791)的java.lang.reflect.Constructor.newInstance(Constructor.java:423)中委托ConstructConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)位于org.apache.hadoop.ipc.Client.call(Client.java)的org.apache.hadoop.ipc.Client.call(Client.java:1474)的.hadoop.net.NetUtils.wrapException(NetUtils.java:731) :1401)org.apache.hadoop.ipc.ProtobufRpcEngine $ Invoker.invoke(ProtobufRpcEngine.java:232)at com.sun.proxy . $ Proxy14.getFileInfo(Unknown Source)at org.apache.hadoop.hdfs.protocolPB . 在sun.refle的sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)的ClientNamenodeProtocolTranslatorPB.getFileInfo(ClientNamenodeProtocolTranslatorPB.java:752) ct.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)位于org.apache.hadoop的java.lang.reflect.Method.invoke(Method.java:498)的sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)位于com.sun.proxy的org.apache.hadoop.io.retry.RetryInvocationHandler.invoke(RetryInvocationHandler.java:102)中的.io.retry.RetryInvocationHandler.invokeMethod(RetryInvocationHandler.java:187) . $ Proxy15.getFileInfo(Unknown Source )org.apache.hadoop.hdfs.DFSClient.getFileInfo(DFSClient.java:1977)org.apache.hadoop.hdfs.DistributedFileSystem $ 18.doCall(DistributedFileSystem.java:1118)at org.apache.hadoop.hdfs.DistributedFileSystem位于org.apache.hadoop.fs.FileSystemLinkResolver.resolve(FileSystemLinkResolver.java:81)的$ 18.doCall(DistributedFileSystem.java:1114)org.apache.hadoop.hdfs.DistributedFileSystem.getFileStatus(DistributedFileSystem.java:1114)at org org.apache.spark.sql.execution.datasources.D上的.apache.hadoop.fs.FileSystem.exists(FileSystem.java:1400) ataSource $$ anonfun $ 14.apply(DataSource.scala:359)at org.apache.spark.sql.execution.datasources.DataSource $$ anonfun $ 14.apply(DataSource.scala:348)at scala.collection.TraversableLike $$ anonfun $ flatMap $ 1.apply(TraversableLike.scala:241)at scala.collection.TraversableLike $$ anonfun $ flatMap $ 1.apply(TraversableLike.scala:241)at scala.collection.immutable.List.foreach(List.scala:392) at scala.collection.TraversableLike $ class.flatMap(TraversableLike.scala:241)at scala.collection.immutable.List.flatMap(List.scala:355)at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation (DataSource.scala:348)org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:178)位于org.apache的org.apache.spark.sql.DataFrameReader.text(DataFrameReader.scala:623) . 位于aws1.main的aws1 $ .main(aws1.scala:22)的org.apache.spark.sql.DataFrameReader.textFile(DataFrameReader.scala:632)中的spark.sql.DataFrameReader.textFile(DataFrameReader.scala:657)( aws1.scala)引起:java.net.ConnectException:在sun.nio.ch.SocketChannelImpl.checkConnect(本地方法)的sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)处于org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java: 206)org.apache.hadoop.net.NetUtils.connect(NetUtils.java:530)org.apache.hadoop.net.NetUtils.connect(NetUtils.java:494)atg.apache.hadoop.ipc.Client位于org.apache.hadoop.ipc.Client的$ Connection.setupConnection(Client.java:609)org.apache.hadoop.ipc.Client $ Connection.access $ 2800(客户端 . java:370)atOrg.apache.hadoop.ipc.Client.getConnection(Client.java:1523)org.apache.hadoop.ipc.Client.call(Client.java:1440)... 31更多

如果我遗漏任何其他信息,请告诉我 . 这是我第一次使用Hadoop和AWS . 我感谢任何帮助 .