首页 文章 精选 留言 我的

精选列表

搜索[scratch],共333篇文章
优秀的个人博客,低调大师

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

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(Configurationconf,StringexecutionId){ this .conf=conf; this .executionId=executionId; if (HiveConf.getBoolVar(conf,HiveConf.ConfVars.HIVE_USE_CUSTOM_PROXY)){ StringproxyUser=HiveConf.getVar(conf,HiveConf.ConfVars.HIVE_CUSTOM_PROXY_USER); LOG.warn( "usecustomproxy,genScratchpath,proxyuseris" +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( "inContextinitfunctionnonLocalScratchPathis" +nonLocalScratchPath); LOG.warn( "inContextinitfunctionlocalScratchPathis" +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 PathgetScratchDir(Stringscheme,Stringauthority, boolean mkdir,StringscratchDir){ //如果是explain语句mkdir为false StringfileSystem=scheme+ ":" +authority; Pathdir=fsScratchDirs.get(fileSystem+ "-" +TaskRunner.getTaskRunnerID()); if (dir== null ){ PathdirPath= new Path(scheme,authority, scratchDir+ "-" +TaskRunner.getTaskRunnerID()); if (mkdir){ try { FileSystemfs=dirPath.getFileSystem(conf); dirPath= new Path(fs.makeQualified(dirPath).toString()); FsPermissionfsPermission= new FsPermission(Short.parseShort(scratchDirPermission.trim(), 8 )); //目录权限由HiveConf.ConfVars.SCRATCHDIRPERMISSION设置 if (!Utilities.createDirsWithPermission(conf,dirPath,fsPermission)){ throw new RuntimeException( "Cannotmakedirectory:" +dirPath.toString()); } if (isHDFSCleanup){ fs.deleteOnExit(dirPath); } } catch (IOExceptione){ 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(Configurationconf,Pathmkdir, FsPermissionfsPermission) 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,umask000 fsPermission= new FsPermission(( short ) 00777 ); } //ifwemadeitsofarwithoutexceptionwearegood! return createDirsWithPermission(conf,mkdir,fsPermission,recursive); //默认recursive为false } ..... public static boolean createDirsWithPermission(Configurationconf,PathmkdirPath, FsPermissionfsPermission, boolean recursive) throws IOException{ StringorigUmask= null ; LOG.warn( "Createdirs" +mkdirPath+ "withpermission" +fsPermission+ "recursive" + recursive); if (recursive){ //如果recursive为true,origUmask为000,否则为null origUmask=conf.get( "fs.permissions.umask-mode" ); //thisumaskisrequiredbecausebydefaultthehdfsmaskis022resultingin //allparentsgettingthefsPermission&!(022)permissioninsteadoffsPermission conf.set( "fs.permissions.umask-mode" , "000" ); } FileSystemfs=ShimLoader.getHadoopShims().getNonCachedFileSystem(mkdirPath.toUri(),conf); LOG.warn( "fs.permissions.umask-modeis" +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 (IOExceptionioe){ try { resetConfAndCloseFS(conf,recursive,origUmask,fs); } catch (IOExceptione){ //donothing-doublefailure } } return retval; } hdfs中关于fs.permissions.umask-mode的配置,默认是002 1 2 public static final StringFS_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(Configurationconf,Pathmkdir, FsPermissionfsPermission) 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 ); } //ifwemadeitsofarwithoutexceptionwearegood! return createDirsWithPermission(conf,mkdir,fsPermission,recursive); } 这样,就可以创建出777的hdfs目录了。 本文转自菜菜光 51CTO博客,原文链接:http://blog.51cto.com/caiguangguang/1589879,如需转载请自行联系原作者

优秀的个人博客,低调大师

《Linux From Scratch》第三部分:构建LFS系统 第八章:让LFS系统可引导 - 8.3. Linux-3.19

Linux 软件包包含 Linux 内核。 大概编译时间:3.0 - 49.0 SBU (一般 6 SBU) 所需磁盘空间:700 - 6800 MB (一般 800-900 MB) 8.3.1. 安装内核 编译内核包括以下步骤—配置、编译和安装。阅读内核源码树中的 README 可以获得替代本手册配置的方法。 注意 本章节里的命令都要在 chroot 环境下运行。如果因为某种原因(比如说重启)离开了这个环境,请保证要按照 6.2.2,“挂载和激活/dev” 和 6.2.3,“挂载虚拟内核文件系统” 里所说的那样挂载虚拟内核文件系统,然后按照 6.72.清理 介绍的方法重新进入 chroot 环境。否则运行下面的 make 命令会提示段错误。并进入源码目录(sources),解压 Linux-3.19.tar.gz 文件并进入解压后的目录。 运行以下命令准备编译: make mrproper 这将保证内核树的绝对干净。内核小组建议在每次编译之前都执行此命令,无用的代码将会在解压后删除。 通过菜单界面配置内核。配置内核的一般信息请查看:http://www.linuxfromscratch.org/hints/downloads/files/kernel-configuration.txt。BLFS 包含有一些内核的特殊配置,可以查看:http://www.linuxfromscratch.org/blfs/view/systemd/longindex.html#kernel-config-index. 内核配置和编译的附加信息可查看:http://www.kroah.com/lkn/ 注意 配置内核的一个好的起点是运行 make defconfig。这样会参考你的机器架构生成一份基本能用的基础配置。 注意要确保打开或关闭下面这些特性,否则系统也许不能正常工作甚至根本无法启动: General setup ---> [*] open by fhandle syscalls [CONFIG_FHANDLE] [ ] Auditing support [CONFIG_AUDIT] [*] Control Group support [CONFIG_CGROUPS] Processor type and features ---> [*] Enable seccomp to safely compute untrusted bytecode [CONFIG_SECCOMP] Networking support ---> Networking options ---> <*> The IPv6 protocol [CONFIG_IPV6] Device Drivers ---> Generic Driver Options ---> [ ] Support for uevent helper [CONFIG_UEVENT_HELPER] [*] Maintain a devtmpfs filesystem to mount at /dev [CONFIG_DEVTMPFS] [ ] Fallback user-helper invocation for firmware loading [CONFIG_FW_LOADER_USER_HELPER] Firmware Drivers ---> [*] Export DMI identification via sysfs to userspace [CONFIG_DMIID] File systems ---> [*] Inotify support for userspace [CONFIG_INOTIFY_USER] <*> Kernel automounter version 4 support (also supports v3) [CONFIG_AUTOFS4_FS] Pseudo filesystems ---> [*] Tmpfs POSIX Access Control Lists [CONFIG_TMPFS_POSIX_ACL] [*] Tmpfs extended attributes [CONFIG_TMPFS_XATTR] 注意 尽管 "The IPv6 Protocol" 不是必须打开,但它是 systemd 开发人员强烈推荐的。 上述配置项的一些原理说明: Support for uevent helper 打开这个选项会影响 Udev/Eudev 设备管理。 Maintain a devtmpfs 这个选项允许内核在 Udev 运行之前就创建自动设备节点。之后 Udev 在这个基础上运行,管理权限以及增加软链接。对于所有 Udev/Eudev 用户,这个配置项是必须的。 make LANG=<host_LANG_value> LC_ALL= menuconfig make 参数的含义: LANG=<host_LANG_value> LC_ALL= 使用主机的语言环境。这样就方便在使用 menuconfig 时显示合适的 ncurse 界面,它在 linux 字符终端里显示 UTF-8 字符。 注意把 <host_LANG_value> 替换为自己主机上环境变量 $LANG 的值。如果这个变量没有设定,你可以使用变量 $LC_ALL 或 $LC_CTYPE 的值代替。 另外,make oldconfig 在某些情况下可能更合适。查看 README 文件了解更多信息。 想偷懒的话,可以拷贝主机系统的内核配置文件 .config(如果有的话)到解压后的 linux-3.19 目录下来跳过内核配置。不过,我们不建议这样做。最好是探索一下整个内核配置菜单,从最开始配置内核。 编译内核映像和模块: make 如果使用内核模块,需要 /etc/modprobe.d 文件里的模块配置。关于模块和内核配置的信息可以查看 7.3, “LFS 系统中的设备和模块控制” 以及 linux-3.19/Documentation 目录下的内核文档。 还有,modprobe.d(5) 也可以看一下。 如果内核配置里用到,需要安装模块: make modules_install 在内核编译完成后,还需要一个额外步骤来完成安装。有些文件需要拷贝到 /boot 目录下。 内核映像文件所在的实际目录根据主机系统架构可能会不一样。下面的文件名你也可以改成你喜欢的,不过开头最好是 vmlinuz 才可以兼容下一节要讲的配置引导过程的自动设定。下面的命令假设主机是 x86 架构: cp -v arch/x86/boot/bzImage /boot/vmlinuz-3.19-lfs-7.7-systemd System.map 是内核的符号文件。它映射了每一个内核 API 函数的入口,以及内核运行时的数据结构地址。是调试内核问题时的资源。运行下面的命令安装映射文件: cp -v System.map /boot/System.map-3.19 在之前命令 make menuconfig 里生成的内核配置文件 .config 包含了当前编译的内核的所有配置。最好能保存下来留作参考: cp -v .config /boot/config-3.19 安装 Linux 内核文档: install -d /usr/share/doc/linux-3.19 cp -r Documentation/* /usr/share/doc/linux-3.19 需要注意一下内核源代码目录下的文件属主并不是 root。在以 root 用户解压包的时候(我们在 chroot 环境里做的),解压出来的文件会拥有生成这个包的电脑里用户和组。在安装其他包的时候这并不是问题,因为它们的源代码在安装完后就删除了。不过,Linux 内核的源代码经常会保留比较长时间。这样的话,就有可能会把软件包作者的用户 ID 对应到本机的某个用户上。从而这个用户就会拥有内核源代码的写权限。 如果要保留内核源代码的虎啊,对目录 linux-3.19 运行 chown -R 0:0 命令来保证所有文件属主更改为 root。 警告 一些内核文档里建议创建软链接 /usr/src/linux 指向内核源代码目录。这是 2.6 及以前版本内核的特定要求,而在 LFS 系统里 一定不要 创建这个链接,因为这样的话,在你的基础 LFS 系统完成后安装某些软件包时可能引起问题。 警告 系统 include 目录(/usr/include)下的头文件应该 总是 和编译 Glibc 时用到的头文件保持一致,就是,在 6.7, “Linux-3.19 API 头文件” 里整理过的头文件。因此,它们 不能 替换成原始内核头文件或任何清理过的内核头文件。 8.3.2. 配置 Linux 模块加载顺序 虽然大多数情况下,Linux 模块自动加载就好,但是有时候需要特别指定加载顺序。modprobe 或 insmod 在加载模块时会读取 /etc/modprobe.d/usb.conf 。如果将 USB 设备(ehci_hcd、ohci_hcd 和 uhci_hcd) 编译为模块,则需要此文件,这样它们就会以正确的顺序加载。ehci_hcd 需要在 ohci_hcd 和 uhci_hcd 之前加载,否则在系统启动过程中将会输出警告。 运行以下命令建立 /etc/modprobe.d/usb.conf 文件: install -v -m755 -d /etc/modprobe.d cat > /etc/modprobe.d/usb.conf << "EOF" # Begin /etc/modprobe.d/usb.conf install ohci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i ohci_hcd ; true install uhci_hcd /sbin/modprobe ehci_hcd ; /sbin/modprobe -i uhci_hcd ; true # End /etc/modprobe.d/usb.conf EOF 8.3.3. Linux 的内容 安装的文件:config-3.19, vmlinuz-3.19-lfs-7.7-systemd, and System.map-3.19 安装的目录:/lib/modules, /usr/share/doc/linux-3.19 简要说明 config-3.19 包含内核的所有配置选项 vmlinuz-3.19-lfs-7.7-systemd Linux 系统的引擎。当电脑启动时,内核作为整个系统的第一部分载入。它首先检测和初始化所有的电脑硬件,然后将这些硬件模块抽象成文件树让软件访问,并把单个 CPU 转换成多任务系统,可以看上去同时地运行多个程序。 System.map-3.19 地址和符号列表;包含有入口点的映射以及所有函数和内核数据结构的地址 创建者:Gerard Beekmans 编辑者:Matthew Burgess 和 Armin K. 翻译团队:LCTT 译者/校对:zpl1025,dongfengweixiao,wxy,ictlyh 原文链接

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册