运行spark及hadoop版本不一致解决方法

时间:2022-09-22 18:56:57

目的:

希望在自己电脑上run项目组之前的代码,帮助理解代码,同时为之后的修改做铺垫。由于代码是基于 Spark 2.0.1、Scala 2.11.8 、 Hadoop 2.7.3以及JAVA 1.8,而我自己电脑配置的是 Spark 1.6.1、Scala 2.11.8 、 Hadoop 1.2.1以及JAVA 1.8。

为避免版本问题出现报错,觉得有两种解决方法:
1.将spark1.6.1版本换成spark2.0.1版本。
2.sbt版本都设置成我电脑的版本,run一下是否成功。
这篇文章记录了方法1的心路历程,其实方法2似乎更为简洁,主要是没有很好的理解sbt等工具的效果以及对依赖的版本不够了解,导致修改依赖后打包失败之后可以再尝试。

过程
、在spark官网下载了spark2.0.1的安装包,根据基于hadoop的版本分别下载了spark-2.0.1-bin-hadoop2.7(基于hadoop2.7)、spark-2.0.2-bin-without-hadoop(基于2.0之前的hadoop版本)两个压缩包。

二、解压并移动到相应目录。

三、修改相应的配置文件:
修改/etc/profie (sudo 是修改权限为root)

sudo vim /etc/profile

在其中增加如下内容:

export SPARK_HOME=/home/yy/spark-2.1.0-bin-hadoop2.7/
export PATH=$PATH:$SPARK_HOME/bin

并更新/etc/profie

source /etc/profile

四、依次尝试打开spark-shell,发现spark-2.0.2-bin-without-hadoop不能打开,所以选择使用spark-2.0.1-bin-hadoop2.7。

五、本地运行简单的例子

已将打包好的jar包放在bin目录下,在bin目录下直接运行:

spark-submit --master local[4] --class WordCount wordcount.jar 
spark-submit --master local[4] --class helloscala helloscala.jar 

六、本地运行项目代码

1.kmercounting:

./bin/spark-submit --master local[4] --class org.jgi.spark.localcluster.tools.KmerCounting bin/LocalCluster-assembly-0.1.jar -i data/small/sample.seq -o tmp/seq_result.txt --format seq -k 31  

2.KmerMapReads2

./bin/spark-submit --master local[4] --class org.jgi.spark.localcluster.tools.KmerMapReads2 bin/LocalCluster-assembly-0.1.jar --reads data/small/sample.seq --format seq -k 31 --kmer tmp/seq_result.txt  --output tmp/kmer_reads

3.GraphGen2

./bin/spark-submit --master local[4] --class org.jgi.spark.localcluster.tools.GraphGen2 bin/LocalCluster-assembly-0.1.jar -i tmp/kmer_reads.txt  -o tmp/edges.txt 

4.GraphLPA2

./bin/spark-submit --master local[4] --class org.jgi.spark.localcluster.tools.GraphLPA2  bin/LocalCluster-assembly-0.1.jar -i tmp/edges.txt  -o tmp/lpa.txt 

5.AddSeq

./bin/spark-submit --master local[4] --class org.jgi.spark.localcluster.tools.CCAddSeq bin/LocalCluster-assembly-0.1.jar --wait 1 -i tmp/lpa.txt --reads data/small/sample.seq -o tmp/lpa_seq.txt 

结合本地实验输出结果和程序步骤理解算法。

七、在独立集群上运行代码

简单例子

spark-submit --master spark://yypc:7077 --class WordCount wordcount.jar 

发现报错:
java.io.IOException: Failed to connect to yypc/58.198.102.156:7077

在网上参考各类文档,参照http://blog.csdn.net/ybdesire/article/details/70666544找到问题:

用nmap确认能连接Master主机端口7077

nmap -p 7077 master_ip

显示master并没有开:

Starting Nmap 6.40 ( http://nmap.org ) at 2017-12-04 21:06 CST 
Nmap scan report for yypc (58.198.102.156) 
Host is up (0.000018s latency). 
PORT     STATE  SERVICE 
7077/tcp closed unknown 
Nmap done: 1 IP address (1 host up) scanned in 0.40 seconds

主要原因在于我开spark集群时出现错误。
正确开spark,应该在bin目录下./start-all.sh而不是直接start-all.sh;

其次,新安装的spark要修改两个文件:conf/spark-env.sh和conf/slaves,这应该是在spark安装过程中的,但是被遗忘了。文件修改的具体过程详见https://www.cnblogs.com/zengxiaoliang/p/6478859.html Hadoop2.7.3+Spark2.1.0完全分布式集群搭建过程。

这两个问题解决完之后,wordcount能run了。

项目代码
(试了一部分)
kmercounting:

./bin/spark-submit --master spark://yypc:7077 --deploy-mode client  --conf spark.executor.extraClassPath=bin/LocalCluster-assembly-0.1.jar --conf spark.speculation=true --conf spark.speculation.multiplier=2 --conf spark.eventLog.enabled=false bin/LocalCluster-assembly-0.1.jar KmerCounting --wait 1 -i data/small/sample.seq -o tmp/seq_result2.txt --format seq -k 31 -C

KmerMapReads2:

./bin/spark-submit --master spark://yypc:7077 --deploy-mode client  --conf spark.executor.extraClassPath=bin/LocalCluster-assembly-0.1.jar --conf spark.speculation=true --conf spark.speculation.multiplier=2 --conf spark.eventLog.enabled=false bin/LocalCluster-assembly-0.1.jar KmerMapReads2 --wait 1 --reads data/small/sample.seq --format seq -k 31 --kmer tmp/seq_result2.txt  --output  tmp/kmer_reads2.txt

刚修改完文件后运行不成功,重启后再运行成功了。

当前是hadoop1.2.1版本不变,下载了spark-2.0.1-bin-hadoop2.7版本,可正常使用,能应对当前初步的写代码和调试的需要。