IDEA连接kerberos环境的HDFS集群报错整理

连接hdfs代码

public class HdfsTest {
    public static void main(String[] args) throws IOException {
        System.setProperty("java.security.krb5.conf", "hdfs-conf-kerberos\\krb5.conf");
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS", "hdfs://bigdata-37-201:8020");
        conf.set("hadoop.security.authentication", "kerberos");

        try {
            UserGroupInformation.setConfiguration(conf);
            UserGroupInformation.loginUserFromKeytab("hdfs_test1/hdfs_test1@HADOOP.COM", "hdfs-conf-kerberos\\hdfs_test1.keytab");
            System.out.println("+++++++++++++="+UserGroupInformation.getCurrentUser());
        } catch (IOException e) {
            e.printStackTrace();
        }
        FileSystem fs = FileSystem.get(conf);
        FileStatus[] fsStatus = fs.listStatus(new Path("/tmp"));
        for (int i = 0; i < fsStatus.length; i++) {
            System.out.println("+++++ "+fsStatus[i].getPath().toString());
        }
    }
}

配置文件放置路径:

报错内容:

2021-02-18 15:33:50,189 INFO [org.apache.hadoop.security.UserGroupInformation] - Login successful for user hdfs_test1/hdfs_test1@HADOOP.COM using keytab file hdfs-conf-kerberos\hdfs_test1.keytab
+++++++++++++=hdfs_test1/hdfs_test1@HADOOP.COM (auth:KERBEROS)
2021-02-18 15:34:17,628 WARN [org.apache.hadoop.ipc.Client] - Couldn't setup connection for hdfs_test1/hdfs_test1@HADOOP.COM to big
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要通过Kerberos认证方式上传文件到HDFS,需要完成以下步骤: 1. 配置Kerberos客户端 在Java中使用Kerberos认证需要配置Kerberos客户端。可以通过设置以下系统属性完成配置: ``` System.setProperty("java.security.krb5.realm", "EXAMPLE.COM"); System.setProperty("java.security.krb5.kdc", "kdc.example.com"); ``` 其中,`EXAMPLE.COM`为Kerberos域名,`kdc.example.com`为Kerberos服务器地址。 同时,还需要将Kerberos的keytab文件添加到JVM的classpath中,以便在运行时自动加载。 2. 获取Kerberos票据 在进行HDFS操作之前,需要获取Kerberos票据。可以使用`LoginContext`类获取Kerberos票据: ``` LoginContext lc = new LoginContext("KerberosLogin", new Subject(), null, new KerberosConfiguration()); lc.login(); Subject subject = lc.getSubject(); ``` 其中,`KerberosLogin`为登录模块名称,`KerberosConfiguration`为Kerberos配置类。 3. 创建HDFS文件系统对象 通过Hadoop的`FileSystem`类创建HDFS文件系统对象,并设置认证方式为Kerberos: ``` Configuration conf = new Configuration(); conf.set("fs.defaultFS", "hdfs://namenode.example.com:8020"); conf.setBoolean("dfs.support.append", true); conf.set("hadoop.security.authentication", "kerberos"); conf.set("hadoop.security.authorization", "true"); UserGroupInformation.setConfiguration(conf); UserGroupInformation ugi = UserGroupInformation.getSubject(subject); FileSystem fs = ugi.doAs(new PrivilegedExceptionAction<FileSystem>() { public FileSystem run() throws Exception { return FileSystem.get(conf); } }); ``` 其中,`namenode.example.com`为HDFS的NameNode地址。 4. 上传文件到HDFS 使用HDFS文件系统对象上传文件到HDFS即可: ``` Path srcPath = new Path("/path/to/local/file"); Path dstPath = new Path("/path/to/remote/file"); fs.copyFromLocalFile(srcPath, dstPath); ``` 其中,`/path/to/local/file`为本地文件路径,`/path/to/remote/file`为HDFS文件路径。 以上就是通过Kerberos认证方式上传文件到HDFS的步骤。需要注意的是,Kerberos认证方式需要对安全性有一定的了解才能正确配置和使用。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值