时间:2021-07-01 10:21:17 帮助过:20人阅读
在window上编程提示没有写Hadoop的权限
Exception in thread "main" org.apache.hadoop.security.AccessControlException: Permission denied: user=Mypc, access=WRITE, inode="/":fan:supergroup:drwxr-xr-x
曾经踩过的坑: 保存结果到hdfs上没有写的权限
* 通过修改权限将文件写入到指定的目录下
*
* $HADOOP_HOME/bin/hdfs dfs -mkdir /output
* $HADOOP_HOME/bin/hdfs dfs -chmod 777 /output
使用spark读取hdfs上的文件,进行wordcount 然后将结果保存到hdfs上。
object HdfsFileWordCount {
def main(args: Array[String]): Unit = {
val conf = new SparkConf().setMaster("local[*]").setAppName("hdfs file word count")
val sc = new SparkContext(conf)
val wc = sc.textFile("hdfs://master:8020/data/student.txt",1).flatMap(_.split(" "))
.filter(_.nonEmpty)
.map((_,1))
// .filter(_._2 > 1)
.reduceByKey(_+_)
.persist(StorageLevel.MEMORY_ONLY)
wc.foreach(println)
wc.saveAsTextFile("hdfs://master:8020/output/res1")
sc.stop()
}
}
Exception in thread "main" org.apache.hadoop.security.AccessControlException: Permission denied: user=Mypc, access=WRITE, inode="/":fan:supergroup:drwxr-xr-x
标签:hdfs top hadoop 通过 bsp for obj def 保存