jackiehff 2017-10-17 03:45 采纳率: 0%
浏览 3680

一个Java应用如何连接两个独立的、使用Kerberos认证的Hadoop集群?

目前项目中需要连接两个不同的带认证的Hadoop集群,但是每次只能连接到一个集群,另一个集群总是认证失败,代码如下:

 public Configuration getConf(int platform) throws IOException {
        if (platform == 1 || platform == 3) {
            return initConfiguration(A_CLUSTER_CONFIG_PATH);
        } else {
            return initConfiguration(B_CLUSTER_CONFIG_PATH);
        }
    }

    private Configuration initConfiguration(String clusterConfigPath) {
        System.setProperty("java.security.krb5.conf", clusterConfigPath + "krb5.conf");
        conf = new Configuration();
        conf.set("hadoop.security.authentication", "Kerberos");
        conf.addResource(new Path(clusterConfigPath + "core-site.xml"));
        conf.addResource(new Path(clusterConfigPath + "hdfs-site.xml"));
        conf.set("fs.hdfs.impl", DistributedFileSystem.class.getName());
        conf.setBoolean("fs.hdfs.impl.disable.cache", true);
        kerberosAuthentication(conf, clusterConfigPath + "hiveConfig.properties", clusterConfigPath + "bd_user.keytab");
        return conf;
    }

    private void kerberosAuthentication(Configuration conf, String propPath, String keytabPath) {
        try {
            UserGroupInformation.setConfiguration(conf);
            PropertiesUtil.loadFromFileSystem(propPath);
            UserGroupInformation.loginUserFromKeytab(PropertiesUtil.getString("hadoop.kerberos.principal"), keytabPath);
        } catch (IOException e) {
            LogBetter.instance(LOGGER).setLevel(LogLevel.ERROR).setMsg("[ClusterConnectionManager]:Hadoop认证失败").setException(e).log();
        }
    }
  • 写回答

5条回答 默认 最新

  • qq_20701337 2017-10-20 07:33
    关注
    两个集群的krb5.conf中的default_realm不一样吗?
    
    评论

报告相同问题?

悬赏问题

  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码