java api 访问 HDFS HA(高可用)配置文件配置方法

本文介绍如何在Hadoop HDFS中配置Kerberos认证,包括设置关键的HDFS参数,如集群名称、NameNode地址及HA配置,同时详细讲解了如何使用keytab进行用户登录。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

    private static Configuration getHdfsConf() {
        String userKeytabPath = PropertiesUtil.getProperty("hive.user.keytab.path");
        String userPrincipal = PropertiesUtil.getProperty("hive.user.principal");
        
        Configuration conf = new Configuration();
        conf.set("hadoop.security.authentication", "kerberos");
        conf.set("hdfs.keytab.file", userKeytabPath);
        conf.set("fs.defaultFS", "hdfs://hdfscluster");
        conf.set("dfs.nameservices", "hdfscluster");
        conf.set("dfs.ha.namenodes.hdfscluster", "nn1,nn2");
        conf.set("dfs.namenode.rpc-address.hdfscluster.nn1", "nn-01.hadoop.citic:8020");
        conf.set("dfs.namenode.rpc-address.hdfscluster.nn2", "nn-02.hadoop.citic:8020");
        conf.set("dfs.client.failover.proxy.provider.hdfscluster", "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");
        
        String krb5Path = PropertiesUtil.getProperty("hive.krb5.path");
        System.setProperty("hadoop.home.dir", "C:/ods-parities-server/hadoop-2.6.1");
        System.setProperty("java.security.krb5.conf", krb5Path);
        
        UserGroupInformation.setConfiguration(conf);
        try {
            UserGroupInformation.loginUserFromKeytab(userPrincipal, userKeytabPath);
        } catch (IOException e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }
        
        return conf;
    }

说明:

        其中String krb5Path =......System.setProperty("java.security.krb5.conf", krb5Path);为krb5认证。

        其中hdfscluster字符串为集群配置文件hdfs-site.xml中的配置项dfs.nameservices的值。

        其中dfs.ha.namenodes.hdfscluster、dfs.namenode.rpc-address.hdfscluster.nn1、dfs.namenode.rpc-address.hdfscluster.nn2、dfs.client.failover.proxy.provider.hdfscluster的hdfscluster字符串也是集群配置文件hdfs-site.xml中的配置项dfs.nameservices的值。

        其中dfs.client.failover.proxy.provider.hdfscluster配置项对应的类应该是确保返回高可用中处于active状态的namenode节点。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值