spark的新人会有什么坑
spark是一个以java为基础的,以Scala实现的,所以在你在安装指定版本的spark,需要检查你用的是对应spark使用什么版本的scala,可以通过spark-shel --version进行查看,也需要看一下scala使用的什么版本的jdk运行,在scala官方下载页面会有说明jdk版本,然后在编译时使用指定版本的jdk。并且jdk8是jdk1.8,哈哈,讨论很深的。
mac的java目录在/Library/Java/JavaVirtualMachines/,找到指定版本进去找Home目录,IntelliJ IDA添加sdk时,需要找sdk home,
如果编译时出现类似以下错误,找不到类依赖,spark内部的包是有互相依赖的,比如:
missing or invalid dependency detected while loading class file 'StreamingContext.class'. Could not access term conf in package org.apache.hadoop, because it (or its dependencies) are missying. Check your build definition for missing or conflicting dependencies. (Re-run with -Ylog-classpath to see the problematic classpath.) A full rebuild may help if 'StreamingContext.class' was compiled against an incompatible version of org.apache.hadoop.
我目前的解决方式比较笨,直接将spark_folder/jars/*.jar文件添加的项目的Libraryy依赖中,这样都找到了 ,嘿嘿,
项目发布时,不要发布这些包,否则发则会慢,并且会spark中的包冲突
spark-submit时提示:
ERROR spark.SparkContext: Error initializing SparkContext.
java.lang.IllegalStateException: Spark context stopped while waiting for backen
这个错误是因为yarn在java8环境下出现的bug,需要增加配置项hadoop/etc/hadoop/yarn-site.xml:
<property>
<name>yarn.nodemanager.pmem-check-enabled</name>
<value>false</value>
</property>
yum install atlas
rpm -i scala-2.12.4.rpm
下载spark对应版本的scala,然后设置全局变量:
export SPARK_HOME="/usr/local/spark2"
export PATH="$PATH:$SPARK_HOME/bin"
export SCALA_HOME="/usr/share/scala"
export PATH="$PATH:$SCALA_HOME/bin"
配置:
conf/spark_env.sh
export SPARK_MASTER_HOST=master
conf/slaves
slave1
slave2
17/12/10 22:08:56 WARN Client: Neither spark.yarn.jars nor spark.yarn.archive is set, falling back to uploading libraries under SPARK_HOME.
这个问题是说,spark的jar运行库需要在集群上才可以运行:
/usr/local/spark2/conf/spark-defaults.conf
spark.yarn.jars hdfs://master:9000/spark_jars
然后将运行命令:hadoop fs -mkdir /spark_jars
hadoop fs -put ./* /spark_jars/
spark-submit/spark-shell在使用yarn时一直没有反应,一直运行,一直等待,我的原因是spark-env中slave机器上没有添加master_host原因
我在提交了一个mllib的als推荐算法,提示:
17/12/11 19:14:39 WARN BLAS: Failed to load implementation from: com.github.fommil.netlib.NativeSystemBLAS
17/12/11 19:14:39 WARN BLAS: Failed to load implementation from: com.github.fommil.netlib.NativeRefBLAS
17/12/11 19:14:39 WARN LAPACK: Failed to load implementation from: com.github.fommil.netlib.NativeSystemLAPACK
17/12/11 19:14:39 WARN LAPACK: Failed to load implementation from: com.github.fommil.netlib.NativeRefLAPACK
这个问题是因为als是一个分布式算法,在本地执行时失败,在--master yarn模式下执行正常