spark-1.2.0集环境搭建
2、解压和安装: 解压 :[spark@S1PA11 scala]$ tar -xvf scala-2.  ,安装:[spark@S1PA11 scala]$ mv scala-2.11.4
~/opt/
3、编辑 ~/.bash_profile⽂件 增加SCALA_HOME环境变量配置,
export JAVA_HOME=/home/spark/opt/java/jdk1.6.0_37
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
export SCALA_HOME=/home/spark/opt/scala-2.11.4
export HADOOP_HOME=/home/spark/opt/hadoop-2.6.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:${SCALA_HOME}/bin
⽴即⽣效 bash_profile  ,[spark@S1PA11 scala]$ source ~/.bash_profile
4、验证scala:[spark@S1PA11 scala]$ scala -version
Scala code runner version 2.11.4 -- Copyright 2002-2013, LAMP/EPFL
[spark@S1PA11 scala]$ scala
Welcome to Scala version 2.11.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
Type in expressions to have them evaluated.
Type :help for more information.
scala> var str = "SB is"+"SB"
str: String = SB isSB
scala>
5、copy到slave机器 ,[spark@S1PA11 scala]$ scp  ~/.bash_profile  spark@10.126.45.56:~/.bash_profile
7、在master主机配置spark :
将下载的spark-1.2. 解压到 ~/opt/⽬前了即 ~/opt/spark-1.2.0-bin-hadoop2.4,配置环境变量SPARK_HOME
# set  java env
export JAVA_HOME=/home/spark/opt/java/jdk1.6.0_37
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
export SCALA_HOME=/home/spark/opt/scala-2.11.4
export HADOOP_HOME=/home/spark/opt/hadoop-2.6.0
export SPARK_HOME=/home/spark/opt/spark-1.2.0-bin-hadoop2.4
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin:${SCALA_HOME}/bin:${SPARK_HOME}/bin:${HADOOP_HOME}/bin
配置完成后使⽤source命令使配置⽣效
进⼊ spark conf⽬录:
[spark@S1PA11 opt]$ cd spark-1.2.0-bin-hadoop2.4/
[spark@S1PA11 spark-1.2.0-bin-hadoop2.4]$ ls
bin  conf  data  ec2  examples  lib  LICENSE  logs  NOTICE  python  README.md  RELEASE  sbin  work
[spark@S1PA11 spark-1.2.0-bin-hadoop2.4]$ cd conf/
[spark@S1PA11 conf]$ ls
plate  slaves                      plate  plate
first :修改slaves⽂件,增加两个slave节点S1PA11、S1PA222
[spark@S1PA11 conf]$ vi slaves
S1PA11
S1PA222
second:配置spark-env.sh
⾸先把plate copy spark-env.sh
vi spark-env.sh⽂件 在最下⾯增加:
export JAVA_HOME=/home/spark/opt/java/jdk1.6.0_37
hadoop分布式集搭建export SCALA_HOME=/home/spark/opt/scala-2.11.4
export SPARK_MASTER_IP=10.58.44.47
export SPARK_WORKER_MEMORY=2g
export HADOOP_CONF_DIR=/home/spark/opt/hadoop-2.6.0/etc/hadoop
HADOOP_CONF_DIR是Hadoop配置⽂件⽬录,SPARK_MASTER_IP主机IP地址,SPARK_WORKER_MEMORY是worker使⽤的最⼤内存
完成配置后,将spark⽬录copy slave机器 scp -r ~/opt/spark-1.2.0-bin-hadoop2.4  spark@10.126.45.56:~/opt/
8、启动spark分布式集并查看信息
[spark@S1PA11 sbin]$ ./start-all.sh
查看:
[spark@S1PA11 sbin]$ jps
31233 ResourceManager
27201 Jps
30498 NameNode
30733 SecondaryNameNode
5648 Worker
5399 Master
15888 JobHistoryServer
如果HDFS没有启动 ,请启动起来,参考hadoop集搭建
查看slave节点:
[spark@S1PA222 scala]$ jps
20352 Bootstrap
30737 NodeManager
7219 Jps
30482 DataNode
29500 Bootstrap
757 Worker
9、页⾯查看集状况:
进去spark集的web管理页⾯,访问
因为我们 看到两个worker节点,因为master和slave都是worker节点我们进⼊spark的bin⽬录,启动spark-shell控制台
现在我们已经顺利进⼊spark-shell的世界了 ,O(∩_∩)O
到⽬前为⽌,我们的spark集环境搭建成功了
10、运⾏spark-shell 测试之前我们在/tmp⽬录上传了⼀个⽂件,我们现在就⽤spark读取hdfs中⽂件
取得hdfs⽂件:
count下⽂件中⽂字总数,
我们过滤
包括The单词有多个
我们算出来 ⼀共有4个The单词
我们通过wc也算出来有4个The单词
我们再实现下Hadoop wordcount功能:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。