大数据问题排查系列 - 开启 Kerberos 安全的大数据环境中,Yarn Container 启动失败导致 spark/hive 作业失败

前言

大家好,我是明哥!

最近在若干个不同客户现场,都遇到了
大数据集群中开启 Kerberos 后,spark/hive 作业提交到YARN 后,因 YARN Container 启动失败作业无法执行的情况,在此总结下背后的知识点,跟大家分享下,希望大家有所收获。

1 问题1问题现象

某客户现场,大数据集群中开启了 kerberos 安全认证,提交 hive on mr/hive on spark 任务给 yarn 后执行失败,查看 yarn web ui 可见报错信息:

Application xxx failed 2 times due to AM container for xxx exited with exitCode -1000
......
main : run as user is hs_cic
main : requested yarn user is hs_cic
User hs_cic not found 
Failing the application.
image.png

2 问题2问题现象

某客户现场,大数据集群中开启了 kerberos 安全认证,提交 spark on hive 任务给 yarn 后执行失败,查看 yarn web ui 可见报错信息:

main : run as user is app-user
main : requested yarn user is app-user
User app-user not found 
Failing the application.

3 问题分析

上述问题出现后,在分析过程中,笔者注意到,使用命令 yarn logs -applicationId xxx 查询作业详细日志时,查询不到任何相关日志 (以确认 yarn 已经开启了日志聚合 yarn.log-aggregation-enable),且查看 hdfs 文件系统时发现已经创建了该作业日志对应的目录但该目录下没有文件;

另外在 hive on mr/spark 作业失败的集群中,笔者留意到集群中启用了hive代理:hive.server2.enable.doAs=true.

结合 yarn web ui中的关键报错信息 "Application xxx failed 2 times due to AM container for xxx exited with exitCode -1000...
User hs_cic not found
Failing the application.",可以确认,是因为集群中 YARN nodeManager 节点上没有相关业务用户,所以启动 yarn container 失败,导致作业无法执行。

4 问题原因

  • 在没有开启 Kerberos 安全的集群里,启动 yarn container 进程时,yarn.nodemanager.container-executor.class 可以使用 DefaultContainerExecutor 或 LinuxContainerExecutor;
  • 在启用了Kerberos 安全的集群里,启动 yarn container 进程时,yarn.nodemanager.container-executor.class 只能使用 LinuxContainerExecutor,其在底层会使用 setuid 切换到业务用户以启动 container 进程,所以要求所有 nodemanager 节点必须有业务用户;
  • 当集群中仅仅在 KDC 中添加了业务用户,而没有在 yarn nodemanager 节点建立对应的业务用用户时,nodemanager 节点就会因为没有相关用户而无法启动 container进程,而作业也就会因为无法获取到 contariner 资源从而无法执行而报错了。

5 解决方案

  • 解决方案很简单,就是在集群中各个节点上(至少是yarn nodemanager 节点)使用命令 useradd 创建对应的业务用户即可(底层会创建相关用户和用户组并写入到文件/etc/passwd中);
  • 如果节点过多嫌弃操作麻烦的话,也可以配置使用 ldap 并在ldap中集中创建相关业务用户,注意是配置 NodeManager 从 LDAP 中查找相关用户,不是使用ldap认证相关用户(--enableldap vs --enableldapauth),具体细节这里不再赘述;
  • 针对 hive on mr/spark 的情形,也可以关闭 hive 的代理(hive.server2.enable.doAs=false),此时hiveserver2编译提交sql作业到yarn时,会使用系统用户 hive 的身份进行提交,由于cdh安装时已经自动在集群各节点创建了hdfs/yarn/hive等系统用户,所以执行不会有问题;

6 技术背景

  • DefaultContainerExecutor: When using the default value for yarn.nodemanager.container-executor.class,which is org.apache.hadoop.yarn.server.nodemanager.DefaultContainerExecutor, the launched container process has the same Unix user as the NodeManager,which normally is yarn;
  • LinuxContainerExecutor: The secure container executor on Linux environmentis org.apache.hadoop.yarn.server.nodemanager.LinuxContainerExecutor, this executor runs the containers as either the YARN user who submitted the application (when full security is enabled) or as a dedicated user (defaults to nobody) when full security is not enabled.
  • When full security is enabled, the LinuxContainerExecutor requires all user accounts to be created on the cluster nodes where the containers are launched. It uses a setuid executable that is included in the Hadoop distribution. The NodeManager uses this executable to launch and kill containers. The setuid executable switches to the user who has submitted the application and launches or kills the containers.
  • The LinuxContainerExecutor does have some requirements:If running in non-secure mode, by default, the LCE runs all jobs as user “nobody”. This user can be changed by setting “yarn.nodemanager.linux-container-executor.nonsecure-mode.local-user” to the desired user. However, it can also be configured to run jobs as the user submitting the job. In that case “yarn.nodemanager.linux-container-executor.nonsecure-mode.limit-users” should be set to false.
  • after integrating hadoop with openldap, hdfs/hive/sentry can find user in openldap, but yarn cannot(the only exceptional is yarn)
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,670评论 5 460
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,928评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,926评论 0 320
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,238评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,112评论 4 356
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,138评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,545评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,232评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,496评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,596评论 2 310
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,369评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,226评论 3 313
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,600评论 3 299
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,906评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,185评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,516评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,721评论 2 335

推荐阅读更多精彩内容

  • 版本:spark-2.3.0-bin-hadoop2.6http://spark.apache.org/docs/...
    金刚_30bf阅读 5,859评论 1 4
  • 转载请注明出处,谢谢合作~ 在 Yarn 上运行 Spark 安全机制(Security) 在 Yarn 上启动 ...
    Whaatfor阅读 1,188评论 0 0
  • kerberos 介绍 阅读本文之前建议先预读下面这篇博客kerberos认证原理---讲的非常细致,易懂 Ker...
    PunyGod阅读 19,946评论 7 29
  • 一、Windows中的认证 1.1 单机认证 NTLM Hash是支持Net NTML认证协议及本地认证过程中的一...
    CJ21阅读 3,136评论 1 1
  • 五、部分框架升级 5.1 Hadoop 3.1.3 5.1.1 安装 安装方式同旧版本 5.1.2 配置文件 co...
    CJ21阅读 1,124评论 0 4