MasterNotRunningException...,IOException:Failed to specify server‘s Kerberos principal name

Java 连接Hbase数据库,使用Kerberos进行认证获取连接

近期有个任务是开发Hbase元数据接口,获取Hbase的连接,然后去操作Hbase,获取其元数据等信息。

开始使用一般认证的方式,然后写好接口获取各种元数据信息方法是测试可行的。后面测试Kerberos认证的方式,写了测试连接的方法,通过Kerberos认证获取连接是成功的,但是测试接口获取元数据等信息的时候,就一直报错。报错信息如下

Sat Sep 03 09:52:28 CST 2022, RpcRetryingCaller{globalStartTime=1662169947866, pause=100, maxAttempts=16}, org.apache.hadoop.hbase.MasterNotRunningException: java.io.IOException: Call to dmp01/10.243.140.76:16000 failed on local exception: java.io.IOException: Failed to specify server's Kerberos principal name

Sat Sep 03 09:52:28 CST 2022, RpcRetryingCaller{globalStartTime=1662169947866, pause=100, maxAttempts=16}, org.apache.hadoop.hbase.MasterNotRunningException: java.io.IOException: Call to dmp01/10.243.140.76:16000 failed on local exception: java.io.IOException: Failed to specify server's Kerberos principal name

然后网上搜索,但是对应我的问题的解决方案都没有找到直接可行的解决办法,后面也是结合多种查找到的情况才解决我本省的问题。

首先Hbase通过Kerberos认证获取连接的代码如下, 下面代码通过Kerberos认证的方式仅仅获取连接没有问题

private static Connection HBaseConn(String hbaseZookeeperQuorum, String krb5Conf, String principal, String keytabFile) throws Exception{
        
            Configuration configruation = HBaseConfiguration.create();
            
            configruation.set("hadoop.security.authentication", "Kerberos");
            
            configruation.set("hbase.zookeeper.quorum",hbaseZookeeperQuorum);
            
            System.setProperty("java.security.krb5.conf",krb5Conf);
            
            UserGroupInformation.setConfiguration(configruation);

            UserGroupInformation.loginUserFromKeytab(principal,keytabFile);
            
            return ConnectionFactory.createConnection(configruation);
        }
    }

上面的代码执行没有异常,通过Kerberos认证,使用krb5.conf、keytabFile、principal参数可以正常获取连接,但是当你使用获取到的connection进行操作的时候,比如connection.getAdmin()方法时就会报异常。上面代码缺失两块,下面代码是正确的获取Hbase连接的方法

private static Connection HBaseConn(String hbaseZookeeperQuorum, String krb5Conf, String principal, String keytabFile) throws Exception{

        Configuration configruation = HBaseConfiguration.create();
        configruation.set("hadoop.security.authentication", "Kerberos");

        // 必需的参数,否则会报连接关闭的异常,异常为:
        /*
        Sat Sep 03 10:10:45 CST 2022, RpcRetryingCaller{globalStartTime=1662171044912, pause=100, maxAttempts=16}, org.apache.hadoop.hbase.MasterNotRunningException:
        java.io.IOException: Call to dmp01/10.243.140.76:16000 failed on local exception: java.io.IOException: 你的主机中的软件中止了一个已建立的连接。
        Sat Sep 03 10:10:45 CST 2022, RpcRetryingCaller{globalStartTime=1662171044912, pause=100, maxAttempts=16}, org.apache.hadoop.hbase.MasterNotRunningException:
        java.io.IOException: Call to dmp01/10.243.140.76:16000 failed on local exception: java.io.IOException: Connection closed
         */
        configruation.set("hbase.security.authentication", "Kerberos");

        configruation.set("hbase.zookeeper.quorum",hbaseZookeeperQuorum);
        System.setProperty("java.security.krb5.conf",krb5Conf);


        // 只是测试获取Kerberos认证获取HBase连接,下面两行不需要都能成功,若要进一步操作Hbase数据库,必须有"hbase.master.kerberos.principal"参数,否则会报错
        // org.apache.hadoop.hbase.MasterNotRunningException......,java.io.IOException:Failed to specify server's Kerberos principal name
        configruation.set("hbase.master.kerberos.principal", principal);

        UserGroupInformation.setConfiguration(configruation);
        UserGroupInformation.loginUserFromKeytab(principal,keytabFile);
        return ConnectionFactory.createConnection(configruation);
    }

两点需要注意:

1、缺少如下的参数设置

configruation.set("hbase.security.authentication", "Kerberos");

则会报异常为

Sat Sep 03 10:10:45 CST 2022, RpcRetryingCaller{globalStartTime=1662171044912, pause=100, maxAttempts=16}, org.apache.hadoop.hbase.MasterNotRunningException:
java.io.IOException: Call to dmp01/10.243.140.76:16000 failed on local exception: java.io.IOException: 你的主机中的软件中止了一个已建立的连接。
Sat Sep 03 10:10:45 CST 2022, RpcRetryingCaller{globalStartTime=1662171044912, pause=100, maxAttempts=16}, org.apache.hadoop.hbase.MasterNotRunningException:
java.io.IOException: Call to dmp01/10.243.140.76:16000 failed on local exception: java.io.IOException: Connection closed

加上"hbase.security.authentication"参数设置之后,此异常即可解决。

2、缺少如下所示的参数设置

configruation.set("hbase.master.kerberos.principal", principal);

则会报异常为:

Sat Sep 03 09:52:28 CST 2022, RpcRetryingCaller{globalStartTime=1662169947866, pause=100, maxAttempts=16}, org.apache.hadoop.hbase.MasterNotRunningException: java.io.IOException: Call to dmp01/10.243.140.76:16000 failed on local exception: java.io.IOException: Failed to specify server's Kerberos principal name

这个异常就是我遇到的,添加上此参数的设置异常可解决。

具体原因还未去深究,根据搜索内容结合参考解决的,后续找到具体原因,再来完善。写的比较粗糙,当作备忘,也供和我遇到相同问题的小伙伴进行参考。

有问题也可以留言,可以共同讨论学习

参考了下面博文,但是该博主说的必需和非必需的参数设置,和我验证的刚好相反,可能情况不同吧

https://blog.csdn.net/tonseal/article/details/114500794

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location \[/tmp/tomcat.8795201897594653596.8778/work/Tomcat/localhost/ROOT\] is not valid. 这个异常通常是由于临时上传目录不存在或不可用导致的。在应用中,当进行HTTP POST请求时,需要使用临时目录来存储POST数据。然而,由于某些操作系统的特性,例如CentOS,临时目录可能会被定期清理,导致目录不存在。为了解决这个问题,你可以在application.yml文件中设置multipart location,并重启项目。例如,将multipart location设置为/data/upload_tmp。这样,应用就会使用指定的目录作为临时上传目录,从而避免了该异常的发生。\[1\]\[2\]\[3\] #### 引用[.reference_title] - *1* [nested exception is java.io.IOException](https://blog.csdn.net/weixin_45313055/article/details/118000488)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* *3* [org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request;...](https://blog.csdn.net/weixin_30468137/article/details/97497705)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值