异常现象
在服务器上执行 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 的认证信息也缓存到文件中,应该就能找见了。
解决办法
-
先清除之间的缓存
kdestroy -A
-
重新认证并缓存在文件中
kinit -kt ~/Documents/test.keytab test@EXAMPLE.COM -c /tmp/krb5cc_$UID
-
查看缓存的认证信息。
# 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
-
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
备注:上述方式缓存的认证信息使用 klist
和 kdestroy -A
是不能查看和删除的。
删除命令:
kdestroy -c /tmp/krb5cc_$UID