Spark(python)

編程語言 Spark Python Scala 靜雅惜靈 2017-04-24

一、 安裝

下載jdk、scala、spark並配置環境變量/etc/profile

Spark(python)

創建軟鏈接

Spark(python)

打開python的spark連接窗口 or ./bin/spark-submit test.py

Spark(python)

簡化連接窗口日誌信息

在conf目錄下:cp log4j.properties.template log4j.properties

vim log4j.properties

Spark(python)

cp spark-env.sh.template spark-env.sh(編譯好的故scala不用配置)

Spark(python)

cp slaves.template slaves

Spark(python)

啟動

Spark(python)

Linux or window下瀏覽器訪問:

Spark(python)

Spark shell 求pi 或者(./bin/run-example SparkPi 10)

Spark(python)

Spark(python)

一、 Wordcount

啟動spark\hdfs

Spark(python)

進入pyspark或者(bin/pyspark --master spark://spark01:7077 --executor-memory 1G --total-executor-cores 1)運行:

sc.textFile('hdfs://spark01:9000/wc/test01.log').flatMap(lambda line: line.split("\t")).map(lambda word: (word, 1)).reduceByKey(lambda a, b: a+b).saveAsTextFile('hdfs://spark01:9000/out')

Spark(python)

Spark(python)

Spark(python)

Spark(python)

或者新建文件test.py

Spark(python)

執行bin/spark-submit test.py

bin/spark-submit --master spark://spark01:7077 --executor-memory 1G --total-executor-cores 1 test.py

Spark(python)

一、 RDD

1.Pyspark命令行

Spark(python)

2.Python文件形式

Spark(python)

相關推薦

推薦中...