Spark、Flink、Beam Beam编写完适用于Spark、Flink使用
mr->spark?
开发不爽 mr两个过程 速度不快 m存硬盘r存hdfs 框架多样性 批处理 流式处理
速度快 内存和磁盘 都比mr快 易用 支持多语言 命令行直接运行 通用性 同一个应用程序同时引用库
运行 可运行在hdfs之上计算
Tachyon 正式更名为 Alluxio,新的版本新增支持任意存储系统如阿里云对象存储 OSS、Amazon S3……
MPI是一个跨语言的通讯协议,,用于编写并行计算机。MPI的目标是高性能,大规模性,和可移植性。
生态对比hadoop、spark
对比hadoop、spark
对比mr和spark
开发Spark
运行模式 代码是一样的提交参数不同 导致运行模式不同
解压文件
tar -zxf apache-maven-3.6.1-bin.tar.gz -C ./
环境变量配置
export SCALA_HOME=/root/software/scala-2.10.6
export PATH=$SCALA_HOME/bin:$PATH
export MAVEN_HOME=/root/software/apache-maven-3.6.1
export PATH=$MAVEN_HOME/bin:$PATH
//刷新配置
source /etc/profile
验证
scala
mvn -version
手动编译适合cdh的压缩包(注意1.7的jdk可能会过时了) spark-2.4.3-bin-2.6.0-cdh5.15.1.tgz
进入bin目录启动模式(本地测试local好) /root/software/spark-2.4.3-bin-2.6.0-cdh5.15.1/bin
master URL []两个线程
//启动spark两个线程
./spark-shell --master local[2]
快速指南 简单helloworld
注意本地读取
[root@hadoop01 data]# cat hello.txt
hello world
hello hadoop
hello hdfs
scala
scala> val textFile = spark.read.textFile("/root/data/hello.txt")
scala> textFile.collect
res1: Array[String] = Array(hello world, hello hadoop, hello hdfs, "")
scala> textFile.count
res2: Long = 4
检验 http://hadoop01:4040/jobs/
spark启动:spark-shell --master local[2]
spark实现wc:
val file = sc.textFile("file:///home/hadoop/data/hello.txt")
val a = file.flatMap(line => line.split(" "))
val b = a.map(word => (word,1))
Array((hadoop,1), (welcome,1), (hadoop,1), (hdfs,1), (mapreduce,1), (hadoop,1), (hdfs,1))
val c = b.reduceByKey(_ + _)
Array((mapreduce,1), (welcome,1), (hadoop,3), (hdfs,2))
sc.textFile("file:///home/hadoop/data/hello.txt").flatMap(line => line.split(" ")).map(word => (word,1)).reduceByKey(_ + _).collect
配合使用的框架,流入流出
注意hadoop版本和scala版本,新版flink并未细分下载选项
flink解压
tar -zxf flink-1.12.1-bin-scala_2.11.tgz -C ./
wordcount
./bin/flink run ./examples/batch/WordCount.jar \
--input file:///root/data/hello.txt --output file:///root/data/tmp/flink_wc_output
[root@hadoop01 tmp]# cat flink_wc_output
hadoop 1
hdfs 1
hello 3
world 1
java\python编写应用于批处理、流处理
jdk1.7之后 和 maven 前置环节
tree
Beam运行:
mvn archetype:generate \
-DarchetypeGroupId=org.apache.beam \
-DarchetypeArtifactId=beam-sdks-java-maven-archetypes-examples \
-DarchetypeVersion=2.27.0 \
-DgroupId=org.example \
-DartifactId=word-count-beam \
-Dversion="0.1" \
-Dpackage=org.apache.beam.examples \
-DinteractiveMode=false
#direct方式运行
mvn compile exec:java -Dexec.mainClass=org.apache.beam.examples.WordCount \
-Dexec.args="--inputFile=/home/hadoop/data/hello.txt --output=counts" \
-Pdirect-runner
#spark方式运行
mvn compile exec:java -Dexec.mainClass=org.apache.beam.examples.WordCount \
-Dexec.args="--runner=SparkRunner --inputFile=/home/hadoop/data/hello.txt --output=counts" -Pspark-runner
#flink方式运行