在hadoop下创建文件夹
bin/hdfs dfs -mkdir -p /usr/hadoop/spark/
touch wc.input 写一些文本进去、
上传到hdfs上 bin/hdfs dfs -put wc.input /usr/hadoop/spark/
查看是否上传成功 bin/hdfs dfs -text /usr/hadoop/spark/wc.input
检测hdfs是否脱离安全模式
[root@hadoop-spark hadoop]# bin/hdfs dfsadmin -safemode get
启动spark读取
scala> val rdd=sc.textFile("hdfs://hadoop-spark.dragon.org:8020/user/hadoop/data/wc.input")
scala> rdd.cache()
scala> val wordcount=rdd.flatMap(_.split(" ")).map(x=>(x,1)).reduceByKey(_+_)
scala> wordcount.take(10)
scala> val wordsort=wordcount.map(x=>(x._2,x._1)).sortByKey(false).map(x=>(x._2,x._1))
scala> wordsort.take(10)