如题,详细报错信息如下:
20/03/05 11:20:06 ERROR ApplicationMaster: User class threw exception: java.lang.NoClassDefFoundError: org/apache/kafka/clients/consumer/Consumer java.lang.NoClassDefFoundError: org/apache/kafka/clients/consumer/Consumer at org.apache.spark.streaming.kafka010.ConsumerStrategies$.Subscribe(ConsumerStrategy.scala:256) at com.znv.facecluster.utils.SparkUtils$.getStreamFormKafka(SparkUtils.scala:40) at com.znv.facecluster.topic.FaceClusterTopic$.readPicture(FaceClusterTopic.scala:37) at com.znv.facecluster.topic.FaceClusterTopic$.process(FaceClusterTopic.scala:28) at com.znv.facecluster.entry.RealTimeFaceClusterApp$.main(RealTimeFaceClusterApp.scala:76) at com.znv.facecluster.entry.RealTimeFaceClusterApp.main(RealTimeFaceClusterApp.scala) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.spark.deploy.yarn.ApplicationMaster$$anon$4.run(ApplicationMaster.scala:721) Caused by: java.lang.ClassNotFoundException: org.apache.kafka.clients.consumer.Consumer at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ... 11 more
经测试,在集群服务器上提交是可以正常运行的,但是在集群外提交就报这个与Kafka相关的错误。
从错误日志看,是找不到Kafka Consumer这个类,但是在集群中提交是正常的,说明在集群中提交程序,spark可能把Kafka Client的jar包也上传了(仅是猜测,待考证),既然如此在集群外提交时把kafka client的jar包一同上传不久ok了,说干就干。把 kafka-clients-0.10.0.1.jar在spark-submit的--jars中增加上,提交运行,结果不如所料,问题被解决了。