当前位置:网站首页>Spark提交参数--files的使用
Spark提交参数--files的使用
2022-06-24 09:47:00 【南风知我意丿】
项目场景:
我们有两个集群(ps:计算集群/存储集群),现在有个需求就是,计算集群运行Spark任务,从kafka取数据写到存储集群的hive
问题描述
跨集群读写数据,我们测试了写hbase是可以从计算集群向存储集群写的,而且能写进去。
但是一旦写hive 他就是写不存储集群的hive中,每次都只写到了计算集群的hive中。
这让我很费解,而且我在本地IDEA上测试的时候,就能写到存储集群的hive中,一旦上小海豚放集群上跑 他就写跑偏了,就给写到计算集群的hive里面了。我在resource文件夹下也放了存储集群的core-site.xml hdfs-site.xml hive-site.xml文件了, 代码里我也写了changeNameNode方法了。但是程序运行时好像还是无法切换到存储集群的NN上去
/*** * @Author: lzx * @Description: * @Date: 2022/5/27 * @Param session: bulid好的Sparkssion * @Param nameSpace: 集群的命名空间 * @Param nn1: nn1_ID * @Param nn1Addr: nn1对应的IP:host * @Param nn2: nn2_ID * @Param nn2Addr: nn2对应的IP:host * @return: void **/
def changeHDFSConf(session:SparkSession,nameSpace:String,nn1:String,nn1Addr:String,nn2:String,nn2Addr:String): Unit ={
val sc: SparkContext = session.sparkContext
sc.hadoopConfiguration.set("fs.defaultFS", s"hdfs://$nameSpace")
sc.hadoopConfiguration.set("dfs.nameservices", nameSpace)
sc.hadoopConfiguration.set(s"dfs.ha.namenodes.$nameSpace", s"$nn1,$nn2")
sc.hadoopConfiguration.set(s"dfs.namenode.rpc-address.$nameSpace.$nn1", nn1Addr)
sc.hadoopConfiguration.set(s"dfs.namenode.rpc-address.$nameSpace.$nn2", nn2Addr)
sc.hadoopConfiguration.set(s"dfs.client.failover.proxy.provider.$nameSpace", s"org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider")
}
原因分析:
1.我先去Spark的运行界面上查看了Environment下的hadoop的参数,我搜了nn1去看了一下,看看我的changenamenode方法到底有没有给我生效
2,结果dfs.namenode.http-address.hr-hadoop.nn1的值还是node03(计算集群的)不是node118(存储集群)说明方法还是没有生效
为什么不生效???
Configuration conf=new Configuration();
创建一个Configuration对象时,其构造方法会默认加载hadoop中的两个配置文件,分别是hdfs-site.xml以及core-site.xml,这两个文件中会有访问hdfs所需的参数值
我代码里有这个啊,怎么没有加载进去啊??
3,经过分析我发现,代码提交到集群上执行,它去加载了集群上的core/hdfs-site.xml文件,直接把代码里的配置文件给抛弃了
解决方案:
1.在代码里这样,使用自己的配置文件去替换集群的配置文件,这样就能找到存储集群的信息了
val hadoopConf: Configuration = new Configuration()
hadoopConf.addResource("hdfs-site.xml")
hadoopConf.addResource("core-site.xml")
如果这两个配置资源都包含了相同的配置项,而且前一个资源的配置项没有标记为final,那么,后面的配置将覆盖前面的配置。上面的例子中,core-site.xml中的配置将覆盖core-default.xml中的同名配置。如果在第一个资源(core-default.xml)中某配置项被标记为final,那么,在加载第二个资源的时候,会有警告提示。
2,光上面那么做是不行的,上面说了,一旦打包上集群运行,他会把resource文件夹下面的core/hdfs-site.xml文件抛弃,然后.addResource(“hdfs-site.xml”)找不到自己制定的文件,还是去找集群的配置文件
3,把自己的两个配置文件放在执行目录下 ,再提交spark任务时,在提交参数里面指定一下
--files /srv/udp/2.0.0.0/spark/userconf/hdfs-site.xml,/srv/udp/2.0.0.0/spark/userconf/core-site.xml \
4,扩展:
--files 传输的文件:
如果与当前提交集群处于同一集群,会提示当前数据源与目标文件存储系统相同,此时不会触发拷贝
INFO Client: Source and destination file systems are the same. Not copying
如果与当前提交集群处于不同集群,则会将源文件从源路径更新至当前文件存储系统
INFO Client: Uploading resource
边栏推荐
- Leetcode-1823: find the winner of the game
- tf.contrib.layers.batch_norm
- Wechat applet rich text picture width height adaptive method introduction (rich text)
- numpy. linspace()
- 跨域概述,简单积累
- Uniapp implementation forbids video drag fast forward
- JMeter接口测试工具基础 — Badboy工具
- leetCode-498: 对角线遍历
- np.float32()
- A method to solve the self-adaptive width and height of the internal picture of rich text label in wechat applet
猜你喜欢

正规方程、、、
![[energy reports] International Conference on energy and environmental engineering in 2022 (cfeee 2022)](/img/48/11bd949fa3695452270c3625d63e6d.jpg)
[energy reports] International Conference on energy and environmental engineering in 2022 (cfeee 2022)

H5网页如何在微信中自定义分享链接

6. package management business development

Uniapp implements the function of clicking to make a call

The difference between the sleep () method and the wait () method of a thread

Customize the toolbars of the kindeditor editor. Items removes unnecessary toolbars or retains some toolbars

5. dish management business development

线程运行原理

leetCode-498: 对角线遍历
随机推荐
pycharm快捷键大全
Resolved: methods with the same name as their class will not be constructors in
[resource sharing] the 5th International Conference on civil, architectural and environmental engineering in 2022 (iccaee 2022)
Normal equation
How can I solve the problem that the swiper animation animation fails when switching between left and right rotations of the swiper?
Learning to organize using kindeditor rich text editor in PHP
图解杂项【防止丢失进行存档用的】
2022全网最全最细的jmeter接口测试教程以及接口测试流程详解— JMeter测试计划元件(线程<用户>)
学习使用KindEditor富文本编辑器,点击上传图片遮罩太大或白屏解决方案
JMeter接口测试工具基础— 取样器sampler(二)
24. 图像拼接大作业
【数据分析数据源】全国各省市行政区坐标(包含边界坐标点和中心坐标点)
JMeter接口测试工具基础 — Badboy工具
跨域概述,简单积累
leetCode-2221: 数组的三角和
HBuilder制作英雄皮肤抽奖小游戏
抓包工具charles實踐分享
What are the characteristics of EDI local deployment and cloud hosting solutions?
Leetcode-223: rectangular area
Flink checkpoint and savepoint