首先启动集群与spark
其次把spark目录下的README.md
上传到hdfs
进入spark下的bin目录,运行spark-shell
./spark-shell
运行
val textFile = sc.textFile("hdfs://chun1:9000/spark/README.md")val wordCounts = textFile.flatMap(line=>line.split(" ")).map(word=>(word,1)).reduceByKey((a,b)=>a+b).coalesce(1,true).saveAsTextFile("hdfs://chun1:9000/spark/out1")