ecplise提交JOB到spark on yarn/standalone

以前我通常是把scala或者java程序打包,这样在发布的时候可以结合传统运维的jekins发布规则,只需要运维手动点击发布即可,不需要每次手动发布。

最近我手动使用ecplise来提交JOB,碰到一些问题做个记录:

1. ecplise提交JOB到spark on yarn

下面是一个很简单的程序,统计a.sql行数

public class App {
	public static void main(String[] args) {
		//System.setProperty("HADOOP_USER_NAME", "hdfs");
		SparkConf sparkConf = new SparkConf().setAppName("JavaWordCount");
		sparkConf.setMaster("yarn-client");	
		//sparkConf.set("spark.yarn.jar", "hdfs:///tmp/spark-assembly_2.10-1.6.0-cdh5.10.2.jar");
	//	sparkConf.set("spark.yarn.appMasterEnv.CLASSPATH","$CLASSPATH:/opt/cloudera/parcels/CDH/lib/hadoop-mapreduce/*");
		JavaSparkContext ctx = new JavaSparkContext(sparkConf);
		JavaRDD<String> lines = ctx.textFile("hdfs:///tmp/a.sql");
		System.out.println(lines.count());
	}
}

提交之后 yarn的日志显示找不到mapreduce的类的错误:

18/12/18 08:48:46 INFO yarn.ApplicationMaster$AMEndpoint: Add WebUI Filter. AddWebUIFilter(org.apache.hadoop.yarn.server.webproxy.amfilter.AmIpFilter,Map(PROXY_HOSTS -> tsczbdnndev1.trinasolar.com, PROXY_URI_BASES -> http://tsczbdnndev1.trinasolar.com:8088/proxy/application_1542688914382_0086),/proxy/application_1542688914382_0086)
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/hadoop/mapreduce/MRJobConfig
	at org.apache.spark.deploy.yarn.Client$$anonfun$21.apply(Client.scala:1206)
	at org.apache.spark.deploy.yarn.Client$$anonfun$21.apply(Client.scala:1205)
	at scala.util.Try$.apply(Try.scala:161)
	at org.apache.spark.deploy.yarn.Client$.getDefaultMRApplicationClasspath(Client.scala:1205)
	at org.apache.spark.deploy.yarn.Client$.getMRAppClasspath(Client.scala:1182)
	at org.apache.spark.deploy.yarn.Client$.populateHadoopClasspath(Client.scala:1167)
	at org.apache.spark.deploy.yarn.Client$.populateClasspath(Client.scala:1269)
	at org.apache.spark.deploy.yarn.ExecutorRunnable.prepareEnvironment(ExecutorRunnable.scala:284)
	at org.apache.spark.deploy.yarn.ExecutorRunnable.launchContextDebugInfo(ExecutorRunnable.scala:70)
	at org.apache.spark.deploy.yarn.ApplicationMaster$$anonfun$registerAM$1.apply(ApplicationMaster.scala:297)
	at org.apache.spark.deploy.yarn.ApplicationMaster$$anonfun$registerAM$1.apply(ApplicationMaster.scala:291)
	at org.apache.spark.Logging$class.logInfo(Logging.scala:58)
	at org.apache.spark.deploy.yarn.ApplicationMaster.logInfo(ApplicationMaster.scala:51)
	at org.apache.spark.deploy.yarn.ApplicationMaster.registerAM(ApplicationMaster.scala:291)
	at org.apache.spark.deploy.yarn.ApplicationMaster.runExecutorLauncher(ApplicationMaster.scala:377)
	at org.apache.spark.deploy.yarn.ApplicationMaster.run(ApplicationMaster.scala:199)
	at org.apache.spark.deploy.yarn.ApplicationMaster$$anonfun$main$1.apply$mcV$sp(ApplicationMaster.scala:681)
	at org.apache.spark.deploy.SparkHadoopUtil$$anon$1.run(SparkHadoopUtil.scala:69)
	at org.apache.spark.deploy.SparkHadoopUtil$$anon$1.run(SparkHadoopUtil.scala:68)
	at java.security.AccessController.doPrivileged(Native Method)
	at javax.security.auth.Subject.doAs(Subject.java:415)
	at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1920)
	at org.apache.spark.deploy.SparkHadoopUtil.runAsSparkUser(SparkHadoopUtil.scala:68)
	at org.apache.spark.deploy.yarn.ApplicationMaster$.main(ApplicationMaster.scala:679)
	at org.apache.spark.deploy.yarn.ExecutorLauncher$.main(ApplicationMaster.scala:698)
	at org.apache.spark.deploy.yarn.ExecutorLauncher.main(ApplicationMaster.scala)
Caused by: java.lang.ClassNotFoundException: org.apache.hadoop.mapreduce.MRJobConfig
	at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
	at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

查看spark提交的环境变量,spark.yarn.appMasterEnv.CLASSPATH,添加mapreduce的lib目录$CLASSPATH:/opt/cloudera/parcels/CDH/lib/hadoop-mapreduce/*

 

2. ecplise提交给spark standalone

这个地方没有什么特殊的,就是要注意版本一定要一致。pom文件的JAR版本和服务器的版本能对应上。 否者容易出现不能初始化SparkContext的错误。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tom_fans

谢谢打赏

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值