spark on yarn cluster模式,出现异常NoSuchMethodError: com.google.common.base.Stopwatch

异常出现

调用的命令如下:

spark2-submit \
--master yarn \
--deploy-mode cluster \
--class com.bigdata.PreWarningScalaAppV2 \
--jars /var/lib/hadoop-hdfs/converter-moshi-2.1.0.jar,/var/lib/hadoop-hdfs/fastjson-1.2.58.jar,/var/lib/hadoop-hdfs/guava-20.0.jar,/var/lib/hadoop-hdfs/influxdb-java-2.5.jar,file:/var/lib/hadoop-hdfs/kafka-clients-2.0.0.jar,file:/var/lib/hadoop-hdfs/logging-interceptor-3.5.0.jar,file:/var/lib/hadoop-hdfs/moshi-1.2.0.jar,file:/var/lib/hadoop-hdfs/okhttp-3.5.0.jar,file:/var/lib/hadoop-hdfs/okio-1.11.0.jar,file:/var/lib/hadoop-hdfs/retrofit-2.1.0.jar,file:/var/lib/hadoop-hdfs/spark-streaming-kafka-0-10_2.11-2.4.4.jar,file:/var/lib/hadoop-hdfs/mysql-connector-java-5.1.48.jar \
/var/lib/hadoop-hdfs/prewarning-1.0.jar

查看日志,异常如下:
spark on yarn cluster模式,出现异常NoSuchMethodError: com.google.common.base.Stopwatch_第1张图片
一般这种情况是版本冲突导致的

版本查看

我们的版本是20.0
在这里插入图片描述
而系统环境自带的guava版本是11.0
在这里插入图片描述
说明用的是自带的11.0版本,低版本里可能没有这个新的类Stopwatch
所以我们要让系统用我们的jar包

解决问题

添加如下的配置

--conf "spark.driver.userClassPathFirst=true" \

官网的说明:是否使用用户添加的jars
在这里插入图片描述
最后执行命令

spark2-submit \
--master yarn \
--deploy-mode cluster \
--class com.bigdata.PreWarningScalaAppV2 \
--jars /var/lib/hadoop-hdfs/converter-moshi-2.1.0.jar,/var/lib/hadoop-hdfs/fastjson-1.2.58.jar,/var/lib/hadoop-hdfs/guava-20.0.jar,/var/lib/hadoop-hdfs/influxdb-java-2.5.jar,file:/var/lib/hadoop-hdfs/kafka-clients-2.0.0.jar,file:/var/lib/hadoop-hdfs/logging-interceptor-3.5.0.jar,file:/var/lib/hadoop-hdfs/moshi-1.2.0.jar,file:/var/lib/hadoop-hdfs/okhttp-3.5.0.jar,file:/var/lib/hadoop-hdfs/okio-1.11.0.jar,file:/var/lib/hadoop-hdfs/retrofit-2.1.0.jar,file:/var/lib/hadoop-hdfs/spark-streaming-kafka-0-10_2.11-2.4.4.jar,file:/var/lib/hadoop-hdfs/mysql-connector-java-5.1.48.jar \
--conf "spark.driver.userClassPathFirst=true" \
/var/lib/hadoop-hdfs/prewarning-1.0.jar

效果如下,运行ok:
spark on yarn cluster模式,出现异常NoSuchMethodError: com.google.common.base.Stopwatch_第2张图片
CDH也显示一直运行了
spark on yarn cluster模式,出现异常NoSuchMethodError: com.google.common.base.Stopwatch_第3张图片

你可能感兴趣的:(CDH)