spark环境配置

上传人:壹****1 文档编号:513020573 上传时间:2022-08-02 格式:DOCX 页数:10 大小:40.39KB
返回 下载 相关 举报
spark环境配置_第1页
第1页 / 共10页
spark环境配置_第2页
第2页 / 共10页
spark环境配置_第3页
第3页 / 共10页
spark环境配置_第4页
第4页 / 共10页
spark环境配置_第5页
第5页 / 共10页
点击查看更多>>
资源描述

《spark环境配置》由会员分享,可在线阅读,更多相关《spark环境配置(10页珍藏版)》请在金锄头文库上搜索。

1、spark环境配置一、安装JDK、Hadoop、 Spark、Scala等,搭建spark集群 环境:CentOS 6.4, Hadoop 1.1.2, JDK 1.7, Spark 0.7.2, Scala 2.9.3 折腾了几天,终于把Spark 集群安装成功了,其实比hadoop要简单很多,由于网上搜索到的博客大部分都还停留在需要依赖mesos的版本,走了不少弯路。 1. 安装 JDK 1.7 yum search openjdk-devel sudo yum install java-1.7.0-openjdk-devel.x86_64 /usr/sbin/alternatives -

2、config java /usr/sbin/alternatives -config javac sudo vim /etc/profile # add the following lines at the end export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.19.x86_64 export JRE_HOME=$JAVA_HOME/jre export PATH=$PATH:$JAVA_HOME/bin export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.j

3、ar # save and exit vim # make the bash profile take effect immediately $ source /etc/profile # test $ java -version 参考我的另一篇博客,安装和配置CentOS服务器的详细步骤。 2. 安装 Scala 2.9.3 Spark 0.7.2 依赖 Scala 2.9.3, 我们必须要安装Scala 2.9.3. 下载 scala-2.9.3.tgz 并 保存到home目录. $ tar -zxf scala-2.9.3.tgz $ sudo mv scala-2.9.3 /usr/l

4、ib $ sudo vim /etc/profile 1 # add the following lines at the end export SCALA_HOME=/usr/lib/scala-2.9.3 export PATH=$PATH:$SCALA_HOME/bin # save and exit vim #make the bash profile take effect immediately source /etc/profile # test $ scala -version 3. 下载预编译好的Spark 下载预编译好的Spark, spark-0.7.2-prebuilt

5、-hadoop1.tgz. 如果你想从零开始编译,则下载源码包,但是我不建议你这么做,因为有一个Maven仓库,twitter4j.org, 被墙了,导致编译时需要翻墙,非常麻烦。如果你有DIY精神,并能顺利翻墙,则可以试试这种方式。 4. 本地模式 4.1 解压 $ tar -zxf spark-0.7.2-prebuilt-hadoop1.tgz 4.2 设置SPARK_EXAMPLES_JAR 环境变量 $ gedit /etc/profile # add the following lines at the end export SPARK_EXAMPLES_JAR=/home/jay

6、/spark-0.7.2/examples/target/scala-2.9.3/spark-examples_2.9.3-0.7.2.jar # save and exit vim #make the bash profile take effect immediately $ source /etc/profile 这一步其实最关键,很不幸的是,官方文档和网上的博客,都没有提及这一点。我是偶然看到了这两篇帖子,Running SparkPi, Null pointer exception when running ./run spark.examples.SparkPi local,才补上

7、了这一步,之前死活都无法运行SparkPi。 2 4.3 设置 SPARK_HOME环境变量,并将SPARK_HOME/bin加入PATH $ gedit /etc/profile # add the following lines at the end export SPARK_HOME=/home/jay/spark-0.7.2 export PATH=$PATH:$SPARK_HOME/bin # save and exit vim #make the bash profile take effect immediately $ source /etc/profile 4.4 现在可以运

8、行SparkPi了 $ cd /spark-0.7.2 $ ./run spark.examples.SparkPi local 5. 集群模式 5.1 安装Hadoop 用VMware Workstation 创建三台CentOS 虚拟机,hostname分别设置为 master, slave01, slave02,设置SSH无密码登陆,安装hadoop,然后启动hadoop集群。参考我的这篇博客,在CentOS上安装Hadoop. 5.2 Scala 在三台机器上都要安装 Scala 2.9.3 , 按照第2节的步骤。JDK在安装Hadoop时已经安装了。 5.3 在master上安装并配

9、置Spark 解压 $ tar -zxf spark-0.7.2-prebuilt-hadoop1.tgz 设置SPARK_EXAMPLES_JAR 环境变量 $ gedit /etc/profile # add the following lines at the end 3 export SPARK_EXAMPLES_JAR=/home/jay/spark-0.7.2/examples/target/scala-2.9.3/spark-examples_2.9.3-0.7.2.jar # save and exit vim #make the bash profile take effec

10、t immediately $ source /etc/profile 在 in conf/spark-env.sh 中设置$ cd /spark-0.7.2/conf $ mv spark-env.sh.template spark-env.sh $ vim spark-env.sh # add the following line export SCALA_HOME=/usr/lib/scala-2.9.3 # save and exit 在conf/slaves, 添加Spark worker的hostname, 一行一个。 $ vim slaves slave01 slave02 #

11、save and exit 设置 SPARK_HOME环境变量,并将SPARK_HOME/bin加入PATH $ gedit /etc/profile # add the following lines at the end export SPARK_HOME=/home/jay/spark-0.7.2 export PATH=$PATH:$SPARK_HOME/bin # save and exit vim #make the bash profile take effect immediately $ source /etc/profile SCALA_HOME 5.4 在所有worker

12、上安装并配置Spark 既然master上的这个文件件已经配置好了,把它拷贝到所有的worker。注意,三台机器spark所在目录必须一致,因为master会登陆到worker上执行命令,master认为worker的spark路径与自己一样。 4 $ cd $ scp -r spark-0.7.2 devslave01: $ scp -r spark-0.7.2 devslave02: 按照第5.3节设置SPARK_EXAMPLES_JAR环境变量,配置文件不用配置了,因为是直接从master复制过来的,已经配置好了。 5.5 启动 Spark 集群 在master上执行 $ cd /spa

13、rk-0.7.2 $ bin/start-all.sh 检测进程是否启动 $ jps 11055 Jps 2313 SecondaryNameNode 2409 JobTracker 2152 NameNode 4822 Master 浏览master的web UI(默认http:/localhost:8080). 这是你应该可以看到所有的word节点,以及他们的CPU个数和内存等信息。 #5.6 运行SparkPi例子 $ cd /spark-0.7.2 $ ./run spark.examples.SparkPi spark:/fang:7077 运行自带的例子,SparkLR 和 Spa

14、rkKMeans. #Logistic Regression #./run spark.examples.SparkLR spark:/fang:7077 #kmeans $ ./run spark.examples.SparkKMeans spark:/fang:7077 ./kmeans_data.txt 2 1 5.7 从HDFS读取文件并运行WordCount $ cd /spark-0.7.2 $ hadoop fs -put README.md . $ MASTER=spark:/fang:7077 ./spark-shell scala val file = sc.textFil

15、e(hdfs:/master:9000/user/dev/README.md) 5 scala val count = file.flatMap(line = line.split( ).map(word = (word, 1).reduceByKey(_+_) scala count.collect 5.8 停止 Spark 集群 $ cd /spark-0.7.2 $ bin/stop-all.sh 二、安装工具sbt,来运行Scala程序 1、下载sbt通用平台压缩包:sbt-0.13.5.tgz http:/www.scala-sbt.org/download.html 2、建立目录,解压文件到所建立目录 $ sudo mkdir /opt/scala/sbt $ sudo tar zxvf sbt-0.13.5.tgz -C /opt/scala/ 3、建立启动sbt的脚本文件 /*选定一个位置,建立启动sbt的脚本文本文件,如/opt/scala/sbt/ 目录下面新建文件名为sbt的文本文件*/ $ cd /opt/scala/sbt/ $ vim sbt 6 /*在sbt文本文件中添加 BT_OPTS=-Xms512M -Xmx1536M -Xss1M -XX:

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 建筑/环境 > 施工组织

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号