spark学习笔记

整理一下自己之前的spark学习笔记,温故而知新。

spark rdd相关传送门spark rdd


启动spark-shell

local模式

MASTER=local bin/spark-shell

local master模式

local cluster模式是一种伪cluster模式,在单机环境下模拟standalone的集群,启动顺序分别如下

  1. 启动master
  2. 启动worker
  3. 启动spark-shell

启动master

修改配置
  1. 进入$SPARK_HOME/conf目录
  2. cp spark-env.sh.template spark-env.sh
  3. 向spark-env.sh中添加
export SPARK_MASTER_IP=localhost
export SPARK_LOCAL_IP=localhost
export SPARK_MASTER_PORT=7077
export SPARK_MASTER_WEBUI_PORT=8081 #默认8080
启动master
$SPARK_HOME/sbin/start-master.sh

master主要是运行类 org.apache.spark.deploy.master.Master,在8081端口启动监听,日志在logs下

启动worker

bin/spark-class org.apache.spark.deploy.worker.Worker spark://localhost:7077 -i 127.0.0.1  -c 1 -m 512M

master web ui的地址是http://localhost:8081

启动spark-shell

./bin/spark-shell --master spark://localhost:7077

http://localhost:4040 可以查看spark jobs,stags,storage,environment,executors等信息

参考