当前位置: 首页 > article >正文

Can‘t get Kerberos realm

近期封装Ozone客户端,需要走kerberos登陆,遇到了一个问题,花了很长时间解决。记录一下,跟网上能搜到的解决方案不大一样。
先看有问题的代码

            Configuration config = new Configuration();
            ConfigurationUtils.setHadoopConfig(config, basePath);
            config.set("hadoop.security.authentication", "kerberos");
            UserGroupInformation.setConfiguration(config);
            System.setProperty("java.security.krb5.conf", basePath + ozoneProperties.getKrb5Conf());
            // 登录Kerberos
            UserGroupInformation.loginUserFromKeytab(ozoneProperties.getPrincipal(), basePath + ozoneProperties.getKeytab());
//            UserGroupInformation.loginUserFromKeytab(ozoneProperties.getPrincipal(), "D:\\gitee\\bigdata-eis-platform\\eis-framework\\eis-framework-starter-ozone-oss\\src\\test\\resources\\prd\\ic.bigdatamgr.keytab");

            // 配置Ozone客户端
            OzoneConfiguration conf = new OzoneConfiguration();
            conf.addResource(new Path(basePath + ozoneProperties.getOzoneSite()));
            OzoneClient ozClient = OzoneClientFactory.getRpcClient(conf);

            return ozClient;

运行的时候报入下错误:

java.lang.IllegalArgumentException: Can't get Kerberos realm
	at org.apache.hadoop.security.HadoopKerberosName.setConfiguration(HadoopKerberosName.java:71)
	at org.apache.hadoop.security.UserGroupInformation.initialize(UserGroupInformation.java:315)
	at org.apache.hadoop.security.UserGroupInformation.setConfiguration(UserGroupInformation.java:366)
	at com.byd.bigdata.eis.framework.ozone.oss.autoconfig.OzoneAutoConfiguration.initOzoneClient(OzoneAutoConfiguration.java:44)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:208)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:955)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:921)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:583)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:147)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:731)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:408)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:307)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
	at com.byd.bigdata.eis.module.datareportsystem.DatareportSystemApplication.main(DatareportSystemApplication.java:13)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
	at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:65)
Caused by: java.lang.IllegalArgumentException: KrbException: Cannot locate default realm
	at javax.security.auth.kerberos.KerberosPrincipal.<init>(KerberosPrincipal.java:154)
	at org.apache.hadoop.security.authentication.util.KerberosUtil.getDefaultRealm(KerberosUtil.java:120)
	at org.apache.hadoop.security.HadoopKerberosName.setConfiguration(HadoopKerberosName.java:69)
	36 common frames omitted

错误原因:hadoop的配置加载放在了kerberos的配置的前面,导致hadoop加载配置找不到kerberos的相关配置,所以报这个错误
解决办法:把加载kerberos配置的代码放在最前面即可


http://www.kler.cn/a/317003.html

相关文章:

  • SQL,力扣题目1127, 用户购买平台
  • Qwen2-VL:发票数据提取、视频聊天和使用 PDF 的多模态 RAG 的实践指南
  • HarmonyOS的@State装饰器的底层实现
  • 界面控件Kendo UI for Angular中文教程:如何构建带图表的仪表板?(一)
  • JS 实现SSE通讯和了解SSE通讯
  • 3D绘制动态爱心Matlab
  • 智能体趋势:未来科技的核心驱动力
  • 4款AI生成PPT工具推荐,提升工作效率
  • 6个Python小游戏项目源码【免费】
  • 前端常见面试-首页性能提升、项目优化
  • leetcode第二十六题:删去有序数组的重复项
  • JavaScript 中的日期与时间处理
  • 設置Android設備全局代理
  • Fastapi做成docker启动失败,需要启动线程。
  • vue3 快速入门系列 —— 基础
  • OpenHarmony(鸿蒙南向开发)——小型系统内核(LiteOS-A)【内核通信机制】上
  • 第一个Java程序(二)
  • c++类中的特殊函数
  • 一篇关于网络的文章
  • electron nsis打包windows应用程序
  • Java企业面试题5
  • 【网站架构部署与优化】源码编译安装LAMP
  • 博客摘录「 SpringBoot大文件(百M以上)的上传下载实现技术」2024年8月2日
  • 2024年躺平,花大半年的时间,就弄了这一件事儿:《C++面试真题宝典》
  • Python: networkx绘图
  • zabbix入门单机部署