解决macbook中访问 HDFS 时 kerberos 认证失败问题

异常现象

在服务器上执行 hadoop fs -ls / 访问 HDFS 是没有问题的。但在 macbook 上执行同样命令会抛出异常:

23/06/08 15:58:32 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
23/06/08 15:58:32 WARN ipc.Client: Exception encountered while connecting to the server : javax.security.sasl.SaslException: GSS initiate failed [Caused by GSSException: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)]
23/06/08 15:58:33 WARN ipc.Client: Exception encountered while connecting to the server : javax.security.sasl.SaslException: GSS initiate failed [Caused by GSSException: No valid credentials provided (Mechanism level: Failed to find any Kerberos tgt)]
23/06/08 15:58:33 INFO retry.RetryInvocationHandler: Exception while invoking getFileInfo of class ClientNamenodeProtocolTranslatorPB over nanjing103/106.55.27.70:8020 after 1 fail over attempts. Trying to fail over immediately.

已经确定的是 macbook 上的大数据文件配置和 kerberos 认证文件全都正确。 异常日志显示是找不到 Kerberos tgt 服务。查资料发现找不到 tgt 的原因很多,提出修改 JDK 配置甚至是重启大数据集群,明显不靠谱。

对比服务器和 macbook 发现两者的 kerberos ticket cache 位置不同:

服务器:

# klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: test@EXAMPLE.COM

Valid starting       Expires              Service principal
06/08/2023 11:58:47  06/09/2023 11:58:47  krbtgt/EXAMPLE.COM@EXAMPLE.COM
        renew until 06/15/2023 11:58:47

MacBook:

# klist
Ticket cache: KCM:501
Default principal: test@EXAMPLE.COM

Valid starting       Expires              Service principal
08  6 2023 16:08:59  09  6 2023 16:08:59  krbtgt/EXAMPLE.COM@EXAMPLE.COM
	renew until 15  6 2023 16:08:59

服务器将认证信息缓存在文件中,macbook 默认存储在 KCM 中

猜测是 hadoop 命令不知道怎么从 KCM 中读认证信息,从而导致 tgt 找不到。

如果让 macbook 的认证信息也缓存到文件中,应该就能找见了。

解决办法

  1. 先清除之间的缓存

    kdestroy -A
    
  2. 重新认证并缓存在文件中

    kinit -kt ~/Documents/test.keytab test@EXAMPLE.COM -c /tmp/krb5cc_$UID
    
  3. 查看缓存的认证信息。

    # klist -c /tmp/krb5cc_$UID
    Ticket cache: FILE:/tmp/krb5cc_501 # 缓存在文件中。
    Default principal: test@EXAMPLE.COM
    
    Valid starting       Expires              Service principal
    08  6 2023 16:22:10  09  6 2023 16:22:10  krbtgt/EXAMPLE.COM@EXAMPLE.COM
    	renew until 15  6 2023 16:22:10
    
  4. hadoop 访问 HDFS

    # hadoop fs -ls /
    23/06/08 16:23:30 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
    Found 10 items
    drwxr-xr-x   - hbase hbase               0 2023-06-01 17:11 /hbase
    drwxr-xr-x   - hdfs  supergroup          0 2022-10-10 11:25 /public-inner
    drwx-wx-wx   - hdfs  supergroup          0 2023-05-24 15:03 /tmp
    drwxr-xr-x   - hdfs  supergroup          0 2023-04-30 17:41 /user
    

备注:上述方式缓存的认证信息使用 klistkdestroy -A 是不能查看和删除的。

删除命令:

kdestroy -c /tmp/krb5cc_$UID
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值