# 1.查找spark所在目录
find / -name spark
# 2.进入目录
cd /export/servers/spark
# 3.启动sparkshell
bin/spark-shell --master local[6]
# 4.编写wordcount代码并执行
import org.apache.spark.sql.SparkSession
val sc = SparkSession.builder.master("local[*]").appName("test").getOrCreate()
val rdd1 = sc.sparkContext.textFile("file:///export/data/wordcount.txt")
val flattenCountRdd = rdd1.flatMap(_.split(" ")).map((_, 1))
val aggCountRdd = flattenCountRdd.reduceByKey(_ + _)
val result = aggCountRdd.collect
print(result)
Linux系统中Find命令的使用及spark的wordcount程序启动
最新推荐文章于 2024-04-17 09:49:09 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)