Input path does not exist: file:/datas/README.md

问题遇到的现象和发生背景

读取hdfs上的数据,结果一直读的file

问题相关代码,请勿粘贴截图

scala> val inputRDD = sc.textFile("/datas/README.md")
scala> inputRDD.count

运行结果及报错内容

org.apache.hadoop.mapred.InvalidInputException: Input path does not exist: file:/datas/README.md
at org.apache.hadoop.mapred.FileInputFormat.singleThreadedListStatus(FileInputFormat.java:287)
.
.

我的解答思路和尝试过的方法

1.不知道sc.textFile()这个默认读的是本地还是hdfs,如果是本地file,需要从哪里修改成hdfs的呢?
2.scala> val inputRDD = sc.textFile("hdfs://localhost:9000/datas/README.md")
用这种加端口的方式也是找不到

我想要达到的结果

inputRDD.count能读到hdfs的文件

不是这样写的,val input = sc.textFile("file:///home/spark/README.md"),///代表本地文件根目录
读取hdfs文件应该是val input = sc.textFile("hdfs://nn:9000/path/file") file代表存放文件的目录

scala> val inputRDD = sc.textFile("/export/server/spark/README.md")
inputRDD: org.apache.spark.rdd.RDD[String] = /export/server/spark/README.md MapPartitionsRDD[3] at textFile at :24

scala> inputRDD.count
res1: Long = 104

scala> inputRDD.first
res2: String = # Apache Spark
读本地是可以的

查看默认分布系统
hdfs dfs -ls /
查看本地路径
hdfs dfs -ls file:///
查看hdfs路径(效果和查看默认分布系统一样)
hdfs dfs -ls hdfs://node1:8020/
默认分布系统的配置是在core-site.xml中
cat /export/server/hadoop/etc/hadoop/core-site.xml

img

<name>fs.defaultFS</name>
<value>hdfs://node1.itcast.cn:8020</value>

总结来说,还是hadoop集群配置方面不够熟悉,图省事直接用的别人hadoop2.6的版本,后来自己搞了hadoop3.4的版本,结果就可以了