在Hadoop2.2基础上安装Spark(伪分布式)

没想到,在我的hadoop2.2.0小集群上上安装传说中的Spark竟然如此顺利,可能是因为和搭建Hadoop时比较像,更多需要学习的地方还是scala编程和RDD机制吧

总之,开个好头

原来的集群:全源码安装,包括hadoop2.2.0 hive0.13.0 hbase-0.96.2-hadoop2  hbase-0.96.2-hadoop2   sqoop-1.4.5.bin__hadoop-2.0.4-alpha  pig-0.12.1

hive和hbase的版本要求比较严格,才能相互调用,所以,虽然hadoop可以升级到2.6,0,先保险起见。还是不单独升级。

Spark的伪分布式安装

1.下载合适的版本
http://spark.apache.org/downloads.html
这里下载的是spark-1.0.2-bin-hadoop2
http://www.scala-lang.org/download/2.11.0.html

2.解压到/usr/local/hadoop
tar -zxvf ...
建立软连接:
ln -s spark-1.0.2-bin-hadoop2 spark
ln -s scala-2.11.0 scala

3.配置路径
进入SPARK_HOME/conf目录,复制一份spark-env.sh.template并更改文件名为spark-env.sh
vim /etc/profile
export JAVA_HOME=/usr/java/jdk1.8.0_25
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
export HADOOP_HOME=/usr/local/hadoop-2.2.0
export HBASE_HOME=/usr/local/hbase
export HIVE_HOME=/usr/local/hive
export SQOOP_HOME=/usr/local/sqoop
export PIG_HOME=/usr/local/pig
export PIG_CALSSPATH=$HADOOP_HOME/etc/hadoop
export MAVEN_HOME=/opt/apache-maven-3.2.3
export ANT_HOME=/opt/apache-ant-1.9.4
export PATH=$PATH:$HADOOP_HOME/:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HBASE_HOME/bin:$HIVE_HOME/bin:$MAVEN_HOME/bin:$ANT_HOME/bin:$SQOOP_HOME/bin:$PIG_HOME/bin
export SCALA_HOME=/usr/local/scala
export SPARK_MASTER=localhost
export SPARK_LOCAL_IP=localhost
export SPARK_HOME=/usr/local/spark
export YARN_CONF_DIR=$HADOOP_HOME/etc/hadoop
export SPARK_LIBARY_PATH=.:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$HADOOP_HOME/lib/native
export PATH=$PATH:$SCALA_HOME/bin:$SPARK_HOME/bin
export YARN_CONF_DIR=$HADOOP_HOME/etc/hadoop
。。。安装了这么多东西,都要配置

让配置生效:
source /etc/profile

4.查看scala版本
[root@centos local]# scala -version
Scala code runner version 2.11.0 -- Copyright 2002-2013, LAMP/EPFL

5.启动spark
进入到SPARK_HOME/sbin下,运行:
start-all.sh
[root@centos local]# jps
7953 DataNode
8354 NodeManager
8248 ResourceManager
8104 SecondaryNameNode
10396 Jps
7836 NameNode
7613 Worker
7485 Master
有一个Master跟Worker进程 说明启动成功
可以通过http://localhost:8080/查看spark集群状况

6.两种模式运行Spark例子程序
1.Spark-shell
此模式用于interactive programming,具体使用方法如下(先进入bin文件夹)

./spark-shell

Welcome to
____ __
/ __/__ ___ _____/ /__
_\ \/ _ \/ _ `/ __/ '_/
/___/ .__/\_,_/_/ /_/\_\ version 1.0.2
/_/

Using Scala version 2.10.4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_25)
Type in expressions to have them evaluated.
Type :help for more information.
15/03/17 19:15:18 INFO spark.SecurityManager: Changing view acls to: root

scala> val days = List("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday")
days: List[String] = List(Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday)

scala> val daysRDD =sc.parallelize(days)
daysRDD: org.apache.spark.rdd.RDD[String] = ParallelCollectionRDD[0] at parallelize at <console>:14

scala>daysRDD.count()

  

显示以下信息:
res0:Long =7

2.运行脚本
运行Spark自带的example中的SparkPi,在
这里要注意,以下两种写法都有问题
./bin/run-example org.apache.spark.examples.SparkPi spark://localhost:7077
./bin/run-example org.apache.spark.examples.SparkPi local[3]
local表示本地,[3]表示3个线程跑

这样就可以:

./bin/run-example org.apache.spark.examples.SparkPi 2 spark://192.168.0.120:7077

15/03/17 19:23:56 INFO scheduler.DAGScheduler: Completed ResultTask(0, 0)
15/03/17 19:23:56 INFO scheduler.DAGScheduler: Stage 0 (reduce at SparkPi.scala:35) finished in 0.416 s
15/03/17 19:23:56 INFO spark.SparkContext: Job finished: reduce at SparkPi.scala:35, took 0.501835986 s
Pi is roughly 3.14086

  

 7.scala特点

MR不理想的最主要的原因有几个: 
1.它是以job形式进行提交的 
2.它的Job相对来说比较重,包括步骤jar到各个节点, Job进行数据的迭代等,一个最简单的Job都要秒计MP

Scala的几个特性,让你有兴趣去学这门新语言: 
1. 它最终也会编译成Java VM代码,看起来象不象Java的壳程序?-至少做为一个Java开发人员,你会松一口气 
2. 它可以使用Java包和类 - 又放心了一点儿,这样不用担心你写的包又得用另外一种语言重写一遍 
3. 更简洁的语法和更快的开发效率

posted @ 2015-03-17 19:25 晋心 阅读(...) 评论(...) 编辑 收藏