Spark提交任务到YARN cluster中,提示An error occurred while calling z:org.apache.spark.api.python.PythonRDD

报错日志截取部分如下:

XXXXXXXXXX ERROR YarnSchedulerBackend$YarnSchedulerEndpoint:91 - Sending RequestExecutors(0,0,Map(),Set()) to AM was unsuccessful
java.io.IOException: Failed to send RPC 7226114124420331875 to /192.168.XXX.XXX:54386: java.nio.channels.ClosedChannelException
	at org.apache.spark.network.client.TransportClient.lambda$sendRpc$2(TransportClient.java:237)
	at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:507)
	at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:481)
	at io.netty.util.concurrent.DefaultPromise.access$000(DefaultPromise.java:34)
	at io.netty.util.concurrent.DefaultPromise$1.run(DefaultPromise.java:431)
	at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:163)
	at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:403)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:463)
	at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
	at java.lang.Thread.run(Thread.java:748)
Caused by: java.nio.channels.ClosedChannelException
	at io.netty.channel.AbstractChannel$AbstractUnsafe.write(...)(Unknown Source)
py4j.protocol.Py4JJavaError: An error occurred while calling z:org.apache.spark.api.python.PythonRDD.runJob.
: org.apache.spark.SparkException: Job 0 cancelled because SparkContext was shut down

 An error occurred while calling z:org.apache.spark.api.python.PythonRDD.runJob.
: org.apache.spark.SparkException: Job 0 cancelled because SparkContext was shut down

参考了很多网上解决办法,如果排除代码问题及任务资源内存设置问题,可能还存在一种情况就是,python环境设置问题。

查看集群内的spark-env.sh环境变量设置:

发现自己环境变量配置PYSPARK_PYTHON等号前多了一个空格 【赋值语句等号两边不能有空格,中间有空格时,shell是把变量当一个命令执行

修改集群配置后,重启Spark服务及YARN服务,问题解决。

写代码报错,排查问题,要注意细节。

孔子的弟子颜回曾说“不迁怒,不贰过”,程序员更应该注意,犯过的错误,不能再有第二次!

 

你可能感兴趣的:(Spark提交任务到YARN cluster中,提示An error occurred while calling z:org.apache.spark.api.python.PythonRDD)