参考文档:http://spark.apache.org/docs/1.6.0/building-spark.html
spark安装需要选择源码编译方式进行安装部署,cdh5.10.0提供默认的二进制安装包存在未知问题,如果直接下载spark二进制安装文件,配置完成后会发现启动spark及相关使用均会报错。
编译spark需要联网,spark使用scala语言编写,所以运行spark需要scala语言,上一步已经安装了scala,scala使用java编写,所以安装scala需要jdk支持,上文已经安装了jdk环境,同时编译spark最好手动安装maven,这里主要目的是更改maven工程镜像地址为国内镜像地址,这样可以加快spark编译安装速度,最主要的是可能你使用原生地址会出现各种奇怪问题,这也是我们独一无二的国情所决定的,国内想培养出顶尖级别计算机科学家,除了良好教育方式的欠缺,基于这些先决条件估计也是不可能的。
1、下载spark安装介质
maven安装介质:http://archive.apache.org/dist/maven/maven-3/3.3.3/binaries/apache-maven-3.3.3-bin.tar.gz
spark源码包:http://archive.apache.org/dist/spark/spark-1.6.0/spark-1.6.0.tgz
2、安装mave:
1)解压缩maven
tar -zxvf apache-maven-3.3.3-bin.tar.gz
mv apache-maven-3.3.3 /opt/service/maven-3.3.3
chown -R hadoop:hadoop /opt/service/maven-3.3.3/
2)配置maven环境变量:
export MAVEN_HOME=/opt/service/maven-3.3.3
export PATH=$MAVEN_HOME/bin:$PATH
3)本机编译环境如下:
#java -version
java version "1.7.0_67"
Java(TM) SE Runtime Environment (build 1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
# scala -version
Scala code runner version 2.10.6 -- Copyright 2002-2013, LAMP/EPFL
# mvn -version
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T19:57:37+08:00)
Maven home: /opt/service/maven-3.3.3
Java version: 1.7.0_67, vendor: Oracle Corporation
Java home: /opt/service/jdk1.7.0_67/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-514.el7.x86_64", arch: "amd64", family: "unix"
4)修改maven仓库默认位置:
vim conf/settings.xml
--添加如下内容:
<localRepository>/home/hadoop/.m2/repository/</localRepository>
5)修改maven镜像位置为阿里云的maven镜像仓库
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>alimaven</id>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/repositories/central/</url>
</mirror>
<mirror>
<id>repo1</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror</name>
<url>http://repo1.maven.org/maven2/</url>
</mirror>
<mirror>
<id>repo2</id>
<mirrorOf>central</mirrorOf>
<name>Human Readable Name for this Mirror</name>
<url>http://repo2.maven.org/maven2/</url>
</mirror>
</mirrors>
更改完成之后可以在命令行,执行命令验证一下:mvn help:system
命令执行完成后我们可以在目录/home/hadoop/.m2/repository/下看到很多文件,这时表示maven已经配置成功了。
$ ls /home/hadoop/.m2/repository/
backport-util-concurrent classworlds com commons-cli commons-lang jdom jtidy junit org plexus xmlpull xpp3
3、编译spark源码
sudo tar -zxvf spark-1.6.0.tgz
sudo chown -R hadoop:hadoop spark-1.6.0
cd spark-1.6.0
vim pom.xml
==注释掉以下部分,否则编译过程会报错:
<!-- For transitive dependencies brougt by parquet-thrift -->
<repository>
<id>twttr-repo</id>
<name>Twttr Repository</name>
<url>http://maven.twttr.com</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
1)maven方式编译spark:
export MAVEN_OPTS="-Xmx2g -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=512m"
nohup mvn -Pyarn -Phadoop-2.6 -Dhadoop.version=2.6.0 -Phive -Phive-thriftserver -Dmaven.test.skip=true package -X >> spark_build_log.output & tail -f spark_build_log.output --已测试通过
nohup mvn -Pyarn -Phadoop-2.6 -Dhadoop.version=2.6.0 -Phive -Phive-thriftserver -Pspark-ganglia-lgpl -Dmaven.test.skip=true package -X >> spark_build_log.output & tail -f spark_build_log.output --未测试
2)打包工程:
vim make-distribution.sh
修改 MVN="$SPARK_HOME/build/mvn" 为 MVN="/opt/service/maven-3.3.3/bin/mvn" 形式,保存。
./make-distribution.sh --tgz --name 2.6.0 -Pyarn -Phadoop-2.6 -Pspark-ganglia-lgpl -P hive --已测试通过
./make-distribution.sh --tgz --name -Phadoop-2.6 -Dhadoop-version=2.6.0 -Pyarn -Phive-1.1.0 -Phive-thriftserver -Pspark-ganglia-lgpl --未测试
--注意:编译过程中出现问题,根据日志输出处理问题,然后重复执行以上两步,直到编译成功为止。
3)编译成功后会在spark源码包根目录下生成spark tar包文件:
$ls spark-1.6.0-bin-2.6.0.tgz
spark-1.6.0-bin-2.6.0.tgz
4、安装spark
tar -zxvf spark-1.6.0-bin-2.6.0.tgz -C /opt/cdh5/
cd /opt/cdh5/spark-1.6.0
5、配置环境变量
:spart-env.sh
JAVA_HOME=/opt/service/jdk1.7.0_67
SCALA_HOME=/opt/service/scala-2.10.6
HADOOP_CONF_DIR=/opt/cdh5/hadoop-2.6.0-cdh5.10.0/etc/hadoop
SPARK_MASTER_IP=db01
SPARK_MASTER_PORT=7077
SPARK_MASTER_WEBUI_PORT=8080
SPARK_WORKER_CORES=8
SPARK_WORKER_MEMORY=5g
SPARK_WORKER_PORT=7078
SPARK_WORKER_WEBUI_PORT=8081
SPARK_WORKER_INSTANCES=4
SPARK_WORKER_DIR=/opt/cdh5/spark-1.6.0/data/tmp
:slaves
db02
db03
db04
db05
6、配置spark-defaults.conf文件:不配置此选项运行spark服务还是在local模式下运行。
spark.master spark://db01:7077
7、scp安装文件到其他节点
scp -r spark-1.6.0/ db02:/opt/cdh5/
scp -r spark-1.6.0/ db03:/opt/cdh5/
scp -r spark-1.6.0/ db04:/opt/cdh5/
scp -r spark-1.6.0/ db05:/opt/cdh5/
8、启动spark集群
sbin/start-master.sh
sbin/start-slaves.sh