简述:
checkpoint就是存盘的意思,比如一个程序要运行10步,结果在第8步挂了,难道前面7步要重头再来?如果前面7步是非常耗时的话,那这样损失是非常大的。
步骤:
1、启动spark集群
cd /usr/local/spark-1.6.1-bin-hadoop2.6/sbin/
./start-all.sh
注意:之所以没有配置在环境变量里,是因为hadoop也有个start-all,怕有冲突
2、启动hdfs
start-dfs.sh
3、启动spark shell
cd /usr/local/spark-1.6.1-bin-hadoop2.6/bin/
./spark-shell --master spark://node01:7077 --executor-memory 1024m --total-executor-cores 4
4、设置checkpoint dir
sc.setCheckpointDir("hdfs://node01:9000/ck0001")
5、运行word count
val res=sc.textFile("hdfs://node01:9000/myinput/").flatMap(_.split(" ")).map((_,1)).reduceByKey(_+_)
6、将res放入缓存
res.cache()
7、将res放入checkpoint中
res.checkpoint()
8、collect(必须要作Action类型的算子,否则不会往hdfs放)
res.collect()
8.1、命令执行完效果如下图
9、查看hdfs中的内容
hdfs dfs -cat /ck0001/194cae8f-1124-4d3c-90ec-8107608b5119/rdd-9/part-00000
结果如下
9.1、或者用web hdfs查看(需要修改hdfs-site.xml使web-hdfs生效),如下图