最近耳聞Spark風生水起,這兩天利用休息時間研究了一下,果真仍是給人很多驚喜。惋惜,筆者不善JAVA,只有PYTHON和SCALA接口。花了很多時間從零開始認識PYTHON和SCALA,很多時間答了VIM的IDE,總算走入正途。下面將一些SPARK集羣搭建心得簡單寫一下。期間也零星碰到很多問題。java
//spark
1,去mirror站點下138M大小的編譯好的包,去下SCALA 2.9.X,HADOOP該啓動的啓動python
2,配置各類$HOME和$PATH
配置$SPARK_HOME/conf/spark-env.sh中的javahome,scalehome,sparkhome
配置slaves文件加入主機名
配置.bash_profile javahome,scalehome,sparkhome 和pathgit
3,把1主和2備用SCP同步一下
scp scala root@192.168.137.104:/root/soft
scp spark root@192.168.137.104:/root
主:start-all.sh
jps多了一個master,jps多了一個worker
http://cent3:8080/
http://cent4:8081/
http://cent2:8081/github
4,跑自帶實例
./run org.apache.spark.examples.SparkPi local
./run-example org.apache.spark.examples.SparkPi spark://cent3:7077
./run-example org.apache.spark.examples.SparkLR spark://cent3:7077
./run-example org.apache.spark.examples.SparkKMeans spark://cent3:7077 ./kmeans_data.txt 2 1shell
5,跑spark-shell 【SBT理解不能。。-_-,好複雜】
MASTER=spark://cent3:7077 ./spark-shell
scala> System.setProperty("spark.executor.memory", "512") #調優MEM參數
scala> System.setProperty("spark.cores.max", "5") #調優CPU參數
scala> val file = sc.textFile("hdfs://cent3:9000/user/root/mandela.txt")
scala> val count = file.flatMap(line => line.split(" ")).map(word => (word, 1)).reduceByKey(_+_)
scala> count.collect()
res0: Array[(java.lang.String, Int)] = Array((peacefully,2), ("",15), (domination,,1), (African,3), (Peace,1), (handed,1), (awarded,1), (era,,1), (cut,1), (example,1), (my,1), (probed,1), (as,2), (country's,3), (rural,1), (his,9), (voluntary,1), (when,3), (last,1), (elections,1), (its,2), (who,1), (appearance,1), (teeth,1), (neighborhood,1), (three,1), (new,1), (jail,1), (president,3), (Charged,1), (died,1), (prisoner.,1), (mission,1), (years,2), (Mandela,6), (Madiba,,1), (myself,1), (1999.,1), (disease,1), (President,3), (after,1), (grip,1), (ovation,1), (office.,1), (from,8), (prolonged,1), (Nobel,1), (sides,1), (died:,1), (other,1), (personal,1), (wounds.,1), (one,1), (Africa,2), (obscurity,1), (As,1), (forging,1), (son,1), (this,1), (president,,1), (has,2), (Mandela,,3), (apartheid,...apache
6,跑pyspark實例
cd /root/spark/python
[ALONE+LOCAL] pyspark examples/wordcount.py local[2] mandela.txt
[ALONE+HDFS] pyspark examples/wordcount.py local[2] hdfs://cent3:9000/user/root/mandela.txt
[CLUSTER+LOCAL] pyspark examples/wordcount.py spark://cent3:7077 mandela.txt 前提是全部Master和Worker主機上都有
[CLUSTER+HDFS pyspark examples/wordcount.py spark://cent3:7077 hdfs://cent3:9000/user/root/mandela.txt編程
好,至此基本上能夠隨便玩了,github上有官網python例子,省了很多事兒。下面開始他的真身驗明,交手C/CPP/HADOOPbash
環境介紹:app
1,某想 E49 Inter Core i5-3320M CPU@2.6GHz / 2048MB / 128G 某星 SSDdom
2,VituralBox 三臺虛擬機cent2,cent3,cent4。其中cent3是老大
虛擬機配置: 1 core / 2048MB / 10G VMDX(SPLIT=2G)/ CENTOS 6,不啓用過量分配。
3,單挑對象簡介
4,關聯文件,從網上DOWN篇E文小說,複製成100M/500M/1024M,作WORDCOUNT。
5,全部平臺作初始配置,不調優。
最終測得結果以下:
結論:
心得: