Skip to content

NLBSN/sparktraining

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sparktraining

Examples for Spark Training in chinahadoop.cn 此工程是在董西成老师的基础上进行修改的,加入了我自己的一些练习。如有侵权,请发邮件到1042038872@qq.com,我会及时做出处理的,谢谢。

本地运行Spark方法

  • 下载spark安装包
  • 解压spark安装包
  • 进入spark解压目录下,运行:
$ bin/spark-shell
  • 在命令行提示符下拷贝以下代码并查看执行结果
import scala.math.random

val tasks = 10
val n = tasks * 100000

val count = sc.parallelize(1 until n, tasks).map { i =>
  val x = random * 2 - 1
  val y = random * 2 - 1
  if (x*x + y*y <= 1) 1 else 0
}.reduce(_ + _)
println("Pi is roughly " + 4.0 * count / n )

分布式运行Spark方法

搭建hadoop集群

Hadoop YARN/HDFS配置文件参考:conf/hadoop目录

配置Spark客户端,并启动spark history server

  • Spark客户端配置文件参考:conf/spark目录
  • 启动spark history server: sbin/start-history-server.sh

将spark-shell运行在yarn client或cluster模式

  • yarn client模式:bin/spark-shell --master yarn --deploy-mode client
  • yarn cluster:bin/spark-shell --master yarn --deploy-mode cluster

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages