实现hive proxy4-scratch目录权限问题解决

Hiveserver2的代理执行之路 hiveserver2的代理访问可以使得平台端代理任意用户执行SQL操作就像该用户自己执行的操作一样(就像一个普通用户直接使用hive CLI执行操作),本文主要探索hiveserver2是如何使用代理的方式实现支持不同用户完成SQL操作,为修改impala支持对应的操作做铺垫。 阅读详情

 

科技小先锋 2017-11-14 01:34:00 浏览419

  hive在hdfs中的job中间文件是根据当前登陆用户产生的,其默认值为/tmp/hive-${user.name},这就导致实现proxy的功能时会遇到临时文件的权限问题,比如在实现了proxy功能后,以超级用户hdfs proxy到普通用户user时,在hdfs中的临时文件在/tmp/hive-user目录中,而目录的属主是hdfs,这时再以普通用户user运行job时,对这个目录就会有权限问题,下面说下这里proxy的实现和解决权限问题的方法:
1.实现proxy功能
更改org.apache.hadoop.hive.ql.Context类的构造方法:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

public Context(Configuration conf, String executionId)  {

  this.conf = conf;

  this.executionId = executionId;

  if(HiveConf.getBoolVar(conf,HiveConf.ConfVars.HIVE_USE_CUSTOM_PROXY)){

      String proxyUser = HiveConf.getVar(conf, HiveConf.ConfVars.HIVE_CUSTOM_PROXY_USER);

      LOG.warn("use custom proxy,gen Scratch path,proxy user is " + proxyUser);

      if(("").equals(proxyUser)||proxyUser == null||("hdfs").equals(proxyUser)){

          nonLocalScratchPath = new Path(HiveConf.getVar(conf, HiveConf.ConfVars.SCRATCHDIR),executionId);

          localScratchDir = new Path(HiveConf.getVar(conf, HiveConf.ConfVars.LOCALSCRATCHDIR),executionId).toUri().getPath();

      }else{

          localScratchDir = new Path((System.getProperty("java.io.tmpdir") + File.separator + proxyUser),executionId).toUri().getPath();

          nonLocalScratchPath = new Path(("/tmp/hive-" + proxyUser),executionId);

          }

  }else{

      nonLocalScratchPath = new Path(HiveConf.getVar(conf, HiveConf.ConfVars.SCRATCHDIR),executionId);

      localScratchDir = new Path(HiveConf.getVar(conf, HiveConf.ConfVars.LOCALSCRATCHDIR),executionId).toUri().getPath();

  }

  LOG.warn("in Context init function nonLocalScratchPath is " + nonLocalScratchPath);

  LOG.warn("in Context init function localScratchPath is " + localScratchDir);

  scratchDirPermission= HiveConf.getVar(conf, HiveConf.ConfVars.SCRATCHDIRPERMISSION);

}

2.权限问题的解决
在上面的代码中可以看到scratchDirPermission的设置,这个是指创建的目录的权限,默认是700,因为是中间文件,我们可以把权限设置的大一点,比如777,在设置了777之后,却发现目录的权限是755.
根据报错的堆栈可以看到方法在Context中调用的情况:

1

getExternalTmpPath--->getExternalScratchDir-->getScratchDir-->Utilities.createDirsWithPermission

(目录不存在时,根据HiveConf.ConfVars.SCRATCHDIRPERMISSION的设置创建hdfs tmp目录)
看下getScratchDir方法:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

private final Map<String, Path> fsScratchDirs = new HashMap<String, Path>();

.....

  private Path getScratchDir(String scheme, String authority,

                               boolean mkdir, String scratchDir) { // 如果是explain语句mkdir为false

    String fileSystem =  scheme + ":" + authority;

    Path dir = fsScratchDirs.get(fileSystem + "-" + TaskRunner.getTaskRunnerID());

    if (dir == null) {

      Path dirPath = new Path(scheme, authority,

          scratchDir + "-" + TaskRunner.getTaskRunnerID());

      if (mkdir) {

        try {

          FileSystem fs = dirPath.getFileSystem( conf);

          dirPath = new Path(fs.makeQualified(dirPath).toString());

          FsPermission fsPermission = new FsPermission(Short.parseShort(scratchDirPermission.trim(), 8)); 

// 目录权限由HiveConf.ConfVars.SCRATCHDIRPERMISSION 设置

          if (!Utilities.createDirsWithPermission(conf , dirPath, fsPermission)) {

            throw new RuntimeException("Cannot make directory: "

                                       + dirPath.toString());

          }

          if (isHDFSCleanup ) {

            fs.deleteOnExit(dirPath);

          }

        } catch (IOException e) {

          throw new RuntimeException (e);

        }

      }

      dir = dirPath;

      fsScratchDirs.put(fileSystem + "-" + TaskRunner.getTaskRunnerID(), dir);

    }

    return dir;

  }

调用Utilities.createDirsWithPermission方法时,传入的目录的权限(由HiveConf.ConfVars.SCRATCHDIRPERMISSION 设置)默认是700
org.apache.hadoop.hive.ql.exec.Utilities类的createDirsWithPermission方法内容如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

public static boolean createDirsWithPermission(Configuration conf, Path mkdir,

    FsPermission fsPermission) throws IOException {

  boolean recursive = false; 

  if (SessionState.get() != null) {

    recursive = SessionState.get().isHiveServerQuery() &&

        conf.getBoolean(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS.varname,

            HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS.defaultBoolVal); 

            //如果是来自hiverserver的请求,并且开启了doas,recursive为true,权限设置为777,umask 000

    fsPermission = new FsPermission((short)00777);

  }

  // if we made it so far without exception we are good!

  return createDirsWithPermission(conf, mkdir, fsPermission, recursive); //默认recursive为false

}

.....

public static boolean createDirsWithPermission(Configuration conf, Path mkdirPath,

    FsPermission fsPermission, boolean recursive) throws IOException {

  String origUmask = null;

  LOG.warn("Create dirs " + mkdirPath + " with permission " + fsPermission + " recursive " +

      recursive);

      

  if (recursive) { //如果recursive为true,origUmask 为000,否则为null

    origUmask = conf.get("fs.permissions.umask-mode");

    // this umask is required because by default the hdfs mask is 022 resulting in

    // all parents getting the fsPermission & !(022) permission instead of fsPermission

    conf.set("fs.permissions.umask-mode", "000"); 

  }

  FileSystem fs = ShimLoader.getHadoopShims().getNonCachedFileSystem(mkdirPath.toUri(), conf);

  LOG.warn("fs.permissions.umask-mode is " + conf.get("fs.permissions.umask-mode"));  //默认为022

  boolean retval = false;

  try {

    retval = fs.mkdirs(mkdirPath, fsPermission);

    resetConfAndCloseFS(conf, recursive, origUmask, fs); 

    //这里因为recursive为false,导致不会重置fs.permissions.umask-mode的配置,

    即fs.permissions.umask-mode为022,因此导致即使设置了权限为777,创建的目录权限最终还是为755

  } catch (IOException ioe) {

    try {

      resetConfAndCloseFS(conf, recursive, origUmask, fs);

    }

    catch (IOException e) {

      // do nothing - double failure

    }

  }

  return retval;

}

hdfs中关于fs.permissions.umask-mode的配置,默认是002

1

2

public static final String  FS_PERMISSIONS_UMASK_KEY = "fs.permissions.umask-mode";

public static final int     FS_PERMISSIONS_UMASK_DEFAULT = 0022;

为了实现可以创建777权限的临时文件目录,更改createDirsWithPermission方法如下:

1

2

3

4

5

6

7

8

9

10

11

12

public static boolean createDirsWithPermission(Configuration conf, Path mkdir,

    FsPermission fsPermission) throws IOException {

  boolean recursive = false; 

  if (SessionState.get() != null) {

    recursive = (SessionState.get().isHiveServerQuery() &&

        conf.getBoolean(HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS.varname,

            HiveConf.ConfVars.HIVE_SERVER2_ENABLE_DOAS.defaultBoolVal))||(HiveConf.getBoolVar(conf,HiveConf.ConfVars.HIVE_USE_CUSTOM_PROXY)); 

    fsPermission = new FsPermission((short)00777);

  }

  // if we made it so far without exception we are good!

  return createDirsWithPermission(conf, mkdir, fsPermission, recursive); 

}

这样,就可以创建出777的hdfs目录了。

spark 写文件 与hive写文件 出现 权限对比 背景描述 从spark on yarn 迁移到 k8s 的过程中,发现写到hive表中的数据的权限是不一致的。原来的权限是 现在的权限是 对比两次的提交不一致的地方,发现在提交的时候有加一个参数 spark.sql.hive.convertInsertingPartitionedTable = true 加上之后会出现问题,改为false 不会出现权限的丢失。 问题复现 在了解到qtt-hive和社区的hive的修改的部分问题后,发现qtt-hive是通过修改部分代码来保... 阅读详情

相关推荐

Spark1.6 java.lang.NoSuchFieldError: HIVE_SCRATCH_DIR_LOCK

Spark1.6查询Hive数据,报错: java.lang.NoSuchFieldError: HIVE_SCRATCH_DIR_LOCK   解决方法:   pom文件中spark-hive以及hive-jdbc包冲突,注释上hive-jdbc即可

杨鑫newlife的专栏 1487

HIVE执行计划(未完)

目录 语法 基本信息 扩展信息 依赖信息 授权信息 参考文章 语法 EXPLAIN [EXTENDED|CBO|AST|DEPENDENCY|AUTHORIZATION|LOCKS|VECTORIZATION|ANALYZE] query AUTHORIZATION从 HIVE 0.14.0 通过HIVE-5961开始支持,VECTORIZATION从 Hive 2.3....

hysfwjr的专栏 698

hive-proxy:mag自动代理服务器:satellite_antenna:

:satellite_antenna: WEBGATE:自动代理服务器 :satellite_antenna: API网关,代理服务器,负载均衡器,虚拟域,ACME HTTPS证书 :spouting_whale:

kylin使用时候出现的问题及处理方式(二)

文章主要针对kylingence或者kylin及hadoop的各个组件使用的问题汇总: 问题7 Hive 重启后,Kyligence Enterprise 报错 "/tmp/hive-scratch on HDFS should be writable" 问题8问题描述: 在 FushionInsight C70 中重新启动 Hive 后,Kyligence Enterprise 报告 "...

king_hui719的博客 2302

常见机械臂模型不用找!Mujoco这儿都有!

高质量的模型集合,franka panda,so-arm100,ur之类的机械臂都有。常见机械臂模型不用找!Mujoco这儿都有!大概346M,网速不行的可以下载zip。

darcsdn 1000

基于Simulink的防空导弹六自由度弹道建模与仿真实战

本文详细介绍了基于Simulink的防空导弹六自由度弹道建模与仿真方法。通过分析导弹动力学原理、Simulink环境配置、气动力建模、推进与控制系统设计等关键环节,提供了一套完整的实战指南。文章特别强调了六自由度模型在防空导弹仿真中的重要性,并分享了常见问题排查与优化建议,为相关领域工程师提供实用参考。

apple5的专栏 871

大数据之Hadoop数据仓库Hive

Hive 是一个构建在 Hadoop 之上的数据仓库,它可以将结构化的数据文件映射成表,并提供类 SQL 查询功能,用于查询的 SQL 语句会被转化为 MapReduce 作业,然后提交到 Hadoop 上运行。简单、容易上手 (提供了类似 sql 的查询语言 hql),使得精通 sql 但是不了解 Java 编程的人也能很好地进行大数据分析;灵活性高,可以自定义用户函数 (UDF) 和存储格式;为超大的数据集设计的计算和存储能力,集群扩展容易;

zouyang920的博客 2275

别再问ARM麒麟怎么装微信了!手把手教你用铠大师搞定Windows软件(飞腾/海思芯片实测)

本文详细介绍了如何在ARM架构的信创电脑(如飞腾/海思芯片)上使用铠大师安装和运行Windows软件,解决微信、Office等常用软件的兼容性问题。通过实测数据对比,铠大师在性能和易用性上显著优于传统方案,为麒麟系统用户提供了一套完整的解决方案。

weixin_28736355的博客 918

实现hive proxy1-hive认证实现

扩展HadoopDefaultAuthenticator类的setConf方法,实现可以代理用户运行的功能,主要需求如下:1.不传入参数时,按本用户执行2.传入参数时,按传入参数执行3.对设置为hdfs用户进行限制主要更改HiveConf类和HadoopDefaultAuthenticator类HiveConf增加:HIVE_USE_CUSTOM_PROXY("use.cus...

weixin_34396103的博客 172

基于深度强化学习技术优化无线网络中的资源分配(一)DQN部分代码

这是一个GitHub上的开源项目,链接:https://github.com/alexis-anzaldo/Deep-Reinforcement-Learning-for-resource-allocation-in-wireless-networks该项目旨在通过深度强化学习DQL技术优化无线网络中的资源分配,特别关注小型蜂窝和超密集无线蜂窝网络中的功率控制问题,主要目标是提高DRL模型的学习效率和网络吞吐量。

m0_46292040的博客 1541

信号处理领域的研究生看过来:手把手教你搞定ICASSP 2025论文投稿(附Latex模板与格式检查清单)

本文为信号处理领域研究生提供ICASSP 2025论文投稿的详细指南,涵盖Latex模板使用、格式检查清单及投稿流程。特别针对IEEE旗舰会议的严格要求和2025年可能出现的新变化,提供预判性建议和实战技巧,帮助作者高效完成论文投稿。

程涛 564

HIVE 权限配置 [没有趟过坑的人生是不完美的]

这两天被hive的权限问题,折腾的不轻.记录一下 1.命令行配置,其实这样是最基本的配置. core-site.xml

张伯毅的专栏 1万+

R语言使用rms包的psm函数拟合参数生存模型(parametric survival model)、并可视化列线图(诺模图、nomogram)

R语言使用rms包的psm函数拟合参数生存模型(parametric survival model)、并可视化列线图(诺模图、nomogram)

statistics+insight+vista+power 909

hive与hdfs整合过程

hive与hdfs整合过程---coco # by coco # 2014-07-25 hive的具体练习:(以下4个目标) 1. 第一普通的hdfs文件能导入到hive中,以供我们查询。 2. 第二hbase中的表,能导入hive中,以供我们查询。 3. 第三mysql中的表,能导入hive中,以供我们查询。 4. hive中的各种查询分析结果,能导入到mysql当

wulantian的专栏 3万+

OpenClaw人人养虾:配置通义千问(Qwen)

通义千问(Qwen)是阿里云推出的大语言模型系列。OpenClaw 支持通过 Qwen Portal 插件实现 OAuth 免费额度认证,每日可免费使用 2000 次请求,无需绑定支付方式。

王国平的博客 1281

LeRobot 官方论文:一个用于端到端机器人学习的开源库

本文介绍了一个名为LeRobot的开源库,旨在解决机器人学习领域的碎片化问题。该库提供了端到端的技术栈,包括统一的机器人中间件API、标准化的数据集格式(LeRobotDataset)、优化的推理栈以及多种最先进机器人学习算法的实现。LeRobot支持多种低成本开源机器人平台(如SO-10X、ALOHA-2等),通过共享中间件实现便捷的遥操作和数据收集。其数据集格式已广泛应用于社区,截至2025年9月已有16,000多个数据集公开共享。该库还支持流式处理大规模数据,降低了研究门槛。在模型方面,LeRobot

2506_90492529的博客 917

排查 Hive 任务导致磁盘写满的过程

计算的中间结果会写到 HDFS,如果用户写的SQL 有问题。,如 A 表 dt=20230101 分区 1000万行,B 表 dt=20230101 有 1万行记录。由于 SQL 没有关联条件,结果有1000亿行。

houzhizhen的专栏 909

全球国家地区城市数据

MySQL全球国家地区城市数据报。。。。。。。。。。。。

Hive CLI和Beeline命令行的基本使用

Hive CLI和Beeline命令行的基本使用

mxk4869的博客 3281

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Hive【基础知识 04】【Hive 属性配置的三种方式及配置的优先级说明】

1. 方式一【配置文件】 使用配置文件指定的配置是永久有效的,Hive 有以下三个可选的配置文件: hive-site.xml :Hive 的主要配置文件; hivemetastore-site.xml: 关于元数据的配置; hiveserver2-site.xml:关于 HiveServer2 的配置。 示例如下,在 hive-site.xml 配置 hive.exec.scratchdir 【这个目录是hdfs系统的】: <property> <name>hive.ex

シ風 1716

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Hive Hive配置详解

整理自 https://www.cnblogs.com/hark0623/p/5650075.html在Hive 安装后,  hive 主要的配置文件为 conf 中  hive-site.xml那该文件中那么多的配置选项都是什么含义呢。下面这篇文章带你解密这些配置请跟随以下这些问题来看以下配置:1.hive输出格式的配置项是哪个?2.hive被各种语言调用如何配置?3.hive提交作业是在hiv...

迎难而上 2万+

Hadoop之Hive的安装配置(详细步骤)

配置前准备 下载apache-hive-2.1.1-bin.tar.gz安装包并上传到XShell 在XShell上解压

大数据 8714

hive 启动问题记录 及解决方法

问题1: Caused by: javax.jdo.JDODataStoreException: Required table missing : "`VERSION`" in Catalog "" Schema "". DataNucleus requires this table to perform its persistence operations. Either your Met

JIM110的专栏 4万+

hive启动出现权限错误 /tmp/hive on HDFS should be writable.

启动hive时出现Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: The root scratch dir: /tmp/hive on HDFS should be writable.Current permissions are: rwxr-xr-x

bear 1万+

The root scratch dir: /tmp/hive on HDFS should be writable. Current permissions are: rw-rw-rw-

It is easy to follow the instructions on http://spark.apache.org/docs/latest/ and download Spark 1.6.0 (Jan 04 2016) with the “Pre-build for Hadoop 2.6 and later” package type from http://spark.apac

zgjdzwhy的博客 8251
上一篇: SDK 使用指南
下一篇: Java双重检查锁定(Double-checked locking)与延迟初始化(Initialization on demand holder)
王树民
博客等级 码龄10年 912粉丝 560原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值
⌂ 换网址