摘要:本文主要向大家介绍了【云计算】SparkStreaming之提交wordcount功能,通过具体的内容向大家展现,希望对大家学习云计算有所帮助。
本文主要向大家介绍了【云计算】SparkStreaming之提交wordcount功能,通过具体的内容向大家展现,希望对大家学习云计算有所帮助。
一、目的:
使用wordcount官方自带案例,熟悉spark-submit和spark-shell两种提交spark应用程序方法。
二、操作目的
1.使用spark-submit提交
(1)启动hdfs
(2)spark根目录下执行
bin/spark-submit --master local[2] \
--class org.apache.spark.examples.streaming.NetworkWordCount \
--name NetworkWordCount \
/opt/modules/spark-2.1.0-bin-2.7.3/examples/jars/spark-examples_2.11-2.1.0.jar bigdata.ibeifeng.com 9999
2.使用spark-shell提交
(1)启动hdfs
(2)启动shell
./spark-shell --master local[2]
(3)启动metastore
bin/hive --service metastore &
(4)写入代码
import org.apache.spark.streaming.{Seconds, StreamingContext}
val ssc = new StreamingContext(sc, Seconds(4))
val lines = ssc.socketTextStream("bigdata.ibeifeng.com", 9999)
val words = lines.flatMap(_.split(" "))
val wordCounts = words.map(x => (x, 1)).reduceByKey(_ + _)
wordCounts.print()
ssc.start()
ssc.awaitTermination()
3.测试
(1)开启nc
nc -lk 9999
(测试成功!)
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标大数据云计算大数据安全频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号