GVKun编程网logo

java 操作 HDFS 相关 demo(TDH,kerberos 认证)(hdfs的javaapi操作)

1

如果您想了解java操作HDFS相关demo和TDH,kerberos认证的知识,那么本篇文章将是您的不二之选。我们将深入剖析java操作HDFS相关demo的各个方面,并为您解答TDH,kerber

如果您想了解java 操作 HDFS 相关 demoTDH,kerberos 认证的知识,那么本篇文章将是您的不二之选。我们将深入剖析java 操作 HDFS 相关 demo的各个方面,并为您解答TDH,kerberos 认证的疑在这篇文章中,我们将为您介绍java 操作 HDFS 相关 demo的相关知识,同时也会详细的解释TDH,kerberos 认证的运用方法,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

java 操作 HDFS 相关 demo(TDH,kerberos 认证)(hdfs的javaapi操作)

java 操作 HDFS 相关 demo(TDH,kerberos 认证)(hdfs的javaapi操作)

public class Test {
    private static Configuration conf;
    private static FileSystem fs;
    // 开启 kerberos 认证
    static {
        System.setProperty("java.security.krb5.conf", "D:\\HDFS-test\\krb5.conf");
        conf=new Configuration();
        conf.addResource(new Path("D:\\HDFS-test\\hdfs-site.xml"));
        conf.set ("hadoop.security.authentication", "kerberos"); // 配置认证方式
        conf.set("fs.default.name", " hdfs://172.20.237.112:8020");//namenode 的地址和端口
        UserGroupInformation.setConfiguration(conf);
        try {
            UserGroupInformation.loginUserFromKeytab("hdfs/gz237-112", "D:\\HDFS-test\\hdfs.keytab");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
/**
* 未开启安全
*/
// static {
//      conf = new Configuration();
//      ip 为 Namenode master 所在节点
//      conf.set("fs.default.name", " hdfs://172.20.237.112:8020");
//       FileSystem 类在 hadoop-hdfs 包中
//       conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
// }
 
public static void main(String[] args) throws Exception {
        //mkdirCatalog ("/yfb");// 在 hdfs 上创建目录
        putfile ("D:\\test.txt", "/yfb");// 上传文件
        //createFile ("/data.txt");// 在 hdfs 上创建文件
        //deleteFile ("/data.txt");// 删除 HDFS 上的文件
        //downloadFile ("/dddd1111.txt","D:\\");// 文件下载
}
//1、创建目录
public static void mkdirCatalog(String path) throws Exception{
    // 创建连接,使用开源的进行,连接报错
 
Caused by: java.net.ConnectException: Connection refused: no further information
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)
    at org.apache.hadoop.net.SocketIOWithTimeout.connect(SocketIOWithTimeout.java:206)

    // FileSystem fs = FileSystem.get(URI.create("hdfs://172.20.237.112:9000"),conf);

    //TDH 的方式
    fs = FileSystem.get(conf);
    fs.mkdirs(new Path(path));
}
// 上传文件到 hdfs
public static void putfile(String localfile,String hdfsfile) throws IOException {
    fs = FileSystem.get(conf);
    fs.copyFromLocalFile(new Path(localfile),new Path(hdfsfile));
}
//HDFS 上创建文件
public static void createFile(String path) throws Exception {
    fs = FileSystem.get(conf);
    fs.createNewFile(new Path(path));
}
// 删除 HDFS 上的文件
public static void deleteFile(String path) throws Exception {
    fs = FileSystem.get(conf);
    if(fs.exists(new Path(path))){
        fs.delete(new Path(path),true);
    }else {
        System.out.println ("您所删除的文件不存在!");
    }
}
// 下载文件到本地
public static void downloadFile(String hdfsPath,String localPath) throws Exception {
    fs = FileSystem.get(conf);
    fs.copyToLocalFile(new Path(hdfsPath),new Path(localPath));
    }
}

beeline 如何在没有有效 kerberos tgt 的情况下列出 hdfs?

beeline 如何在没有有效 kerberos tgt 的情况下列出 hdfs?

如何解决beeline 如何在没有有效 kerberos tgt 的情况下列出 hdfs?

  1. 0: jdbc:hive2://asok-1-openstack.com:2181,aso> !sh hdfs dfs -ls /
  2. SLF4J: Class path contains multiple SLF4J bindings.
  3. SLF4J: Found binding in [jar:file:/usr/hdp/3.1.5.0-152/hive/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
  4. SLF4J: Found binding in [jar:file:/usr/hdp/3.1.5.0-152/hadoop/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
  5. SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
  6. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
  7. Found 9 items
  8. drwxrwxrwt - yarn hadoop 0 2021-01-30 08:10 /app-logs
  9. drwxr-xr-x - yarn hadoop 0 2021-01-30 08:07 /ats
  10. drwxr-xr-x - hdfs hdfs 0 2021-01-30 08:07 /atsv2
  11. drwxr-xr-x - hdfs hdfs 0 2021-01-30 08:07 /hdp
  12. drwxr-xr-x - mapred hdfs 0 2021-01-30 08:07 /mapred
  13. drwxrwxrwx - mapred hadoop 0 2021-01-30 08:07 /mr-history
  14. drwxrwxrwx - hdfs hdfs 0 2021-02-03 12:21 /tmp
  15. drwxr-xr-x - hdfs hdfs 0 2021-01-30 14:54 /user
  16. drwxr-xr-x - hdfs hdfs 0 2021-01-30 14:54 /warehouse
  17. 0: jdbc:hive2://asok-1-openstack.com:2181,aso> !sh pwd
  18. /tmp/hsperfdata_hive
  19. 0: jdbc:hive2://asok-1-openstack.com:2181,aso> !sh id
  20. uid=1008(hive) gid=1002(hadoop) groups=1002(hadoop) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
  21. 0: jdbc:hive2://asok-1-openstack.com:2181,aso> !sh klist
  22. Ticket cache: FILE:/tmp/krb5cc_1008
  23. Default principal: hive/asok-2-openstack.com@OPENSTACK.COM
  24. Valid starting Expires Service principal
  25. 05/04/2021 12:28:09 05/05/2021 12:28:09 krbtgt/OPENSTACK.COM@OPENSTACK.COM
  26. 0: jdbc:hive2://asok-1-openstack.com:2181,also>

在这里可以看到我的用户 hive 拥有仅适用于 hive 服务的有效票证。 虽然 hdfs dfs -ls / 需要有效票证才能连接到 namenode 服务;用户 hive 如何在没有有效票证的情况下连接到 namenode 服务?

clouder manager 启用 kerberos,启动 hdfs 报错

clouder manager 启用 kerberos,启动 hdfs 报错

求大虾帮忙,使用 cm5 配置启用 kerberos, 当启动 hdfs 时非 kdc 所在机器的其他节点不能启动服务,报错如下:
Exception in namenode joinjava.io.IOException: Login failure for hdfs/bj-ecs-xhm-test-yl-18.domain.com@EXAMPLE.COM from keytab hdfs.keytab at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:891) at org.apache.hadoop.security.SecurityUtil.login(SecurityUtil.java:242) at org.apache.hadoop.hdfs.server.namenode.NameNode.loginAsNameNodeUser(NameNode.java:527) at org.apache.hadoop.hdfs.server.namenode.NameNode.initialize(NameNode.java:546) at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:720) at org.apache.hadoop.hdfs.server.namenode.NameNode.<init>(NameNode.java:704) at org.apache.hadoop.hdfs.server.namenode.NameNode.createNameNode(NameNode.java:1354) at org.apache.hadoop.hdfs.server.namenode.NameNode.main(NameNode.java:1420)Caused by: javax.security.auth.login.LoginException: Client not found in Kerberos database (6) - CLIENT_NOT_FOUND at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:763) at com.sun.security.auth.module.Krb5LoginModule.login(Krb5LoginModule.java:584) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:606) at javax.security.auth.login.LoginContext.invoke(LoginContext.java:762) at javax.security.auth.login.LoginContext.access$000(LoginContext.java:203) at javax.security.auth.login.LoginContext$4.run(LoginContext.java:690) at javax.security.auth.login.LoginContext$4.run(LoginContext.java:688) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.login.LoginContext.invokePriv(LoginContext.java:687) at javax.security.auth.login.LoginContext.login(LoginContext.java:595) at org.apache.hadoop.security.UserGroupInformation.loginUserFromKeytab(UserGroupInformation.java:882) ... 7 moreCaused by: KrbException: Client not found in Kerberos database (6) - CLIENT_NOT_FOUND at sun.security.krb5.KrbAsRep.<init>(KrbAsRep.java:82) at sun.security.krb5.KrbAsReqBuilder.send(KrbAsReqBuilder.java:319) at sun.security.krb5.KrbAsReqBuilder.action(KrbAsReqBuilder.java:364) at com.sun.security.auth.module.Krb5LoginModule.attemptAuthentication(Krb5LoginModule.java:735) ... 20 moreCaused by: KrbException: Identifier doesn''t match expected value (906) at sun.security.krb5.internal.KDCRep.init(KDCRep.java:143) at sun.security.krb5.internal.ASRep.init(ASRep.java:65) at sun.security.krb5.internal.ASRep.<init>(ASRep.java:60) at sun.security.krb5.KrbAsRep.<init>(KrbAsRep.java:60) ... 23 more

com.example.demo.service.UserServiceImpl 中构造函数的参数 0 需要类型为“com.example.demo.dao.UserDao”的 bean

com.example.demo.service.UserServiceImpl 中构造函数的参数 0 需要类型为“com.example.demo.dao.UserDao”的 bean

在开发过程中,我们经常会遇到各种错误和异常。其中一个常见的问题是在使用spring框架的时候,遇到了类似于"com.example.demo.service.userserviceimpl 中构造函数的参数 0 需要类型为“com.example.demo.dao.userdao”的 bean"的错误信息。这个错误提示意味着在userserviceimpl类的构造函数中,第一个参数需要注入一个类型为userdao的bean,但是系统找不到对应的bean。解决这个问题的方法有很多,本文将为大家介绍一种简单有效的解决方案。

问题内容

谁能帮我调试这个错误

parameter 0 of constructor in com.example.demo.service.userserviceimpl required a 
bean of type ''com.example.demo.dao.userdao'' that could not be found.

action:

consider defining a bean of type ''com.example.demo.dao.userdao'' in your configuration.
登录后复制

以下是我的文件:

usercontroller.java

package com.example.demo.controller;

import com.example.demo.model.user;
import com.example.demo.service.userservice;
import org.springframework.beans.factory.annotation.autowired;
import org.springframework.web.bind.annotation.*;

import java.util.list;

@restcontroller
@requestmapping("/api/users")
public class usercontroller {

    @autowired
    private final userservice userservice;
    
    public usercontroller(userservice userservice) {
        this.userservice = userservice;
    }

    @getmapping("/{userid}")
    public user getuserbyid(@pathvariable long userid) {
        return userservice.getuserbyid(userid);
    }

    @getmapping
    public list<user> getallusers() {
        return userservice.getallusers();
    }

    @postmapping
    public long adduser(@requestbody user user) {
        return userservice.adduser(user);
    }

    @putmapping("/{userid}")
    public void updateuser(@pathvariable long userid, @requestbody user user) {
        user.setuserid(userid);
        userservice.updateuser(user);
    }

    @deletemapping("/{userid}")
    public void deleteuser(@pathvariable long userid) {
        userservice.deleteuser(userid);
    }
}
登录后复制

userservice.java

package com.example.demo.service;

import com.example.demo.model.user;
import org.springframework.stereotype.component;
import org.springframework.stereotype.service;

import java.util.list;

public interface userservice {
    user getuserbyid(long userid);

    list<user> getallusers();

    long adduser(user user);

    void updateuser(user user);

    void deleteuser(long userid);
}
登录后复制

userserviceimpl.java

package com.example.demo.service;

import com.example.demo.dao.userdao;
import com.example.demo.model.user;
import org.springframework.beans.factory.annotation.autowired;
import org.springframework.stereotype.service;

import java.util.list;

@service
public class userserviceimpl implements userservice {
    
    private final userdao userdao;

    @autowired
    public userserviceimpl(userdao userdao) {
        this.userdao = userdao;
    }

    @override
    public user getuserbyid(long userid) {
        return userdao.getuserbyid(userid);
    }

    @override
    public list<user> getallusers() {
        return userdao.getallusers();
    }

    @override
    public long adduser(user user) {
        return userdao.adduser(user);
    }

    @override
    public void updateuser(user user) {
        userdao.updateuser(user);
    }

    @override
    public void deleteuser(long userid) {
        userdao.deleteuser(userid);
    }
}
登录后复制

userdaoimpl.java

package com.example.demo.dao;

import com.example.demo.model.user;
import org.springframework.jdbc.core.beanpropertyrowmapper;
import org.springframework.jdbc.core.jdbctemplate;
import org.springframework.stereotype.repository;

import java.util.list;

@repository
public class userdaoimpl implements userdao {

    private final jdbctemplate jdbctemplate;

    public userdaoimpl(jdbctemplate jdbctemplate) {
        this.jdbctemplate = jdbctemplate;
    }

    @override
    public user getuserbyid(long userid) {
        string sql = "select * from user where user_id = ?";
        return jdbctemplate.queryforobject(sql, new object[]{userid}, new beanpropertyrowmapper<>(user.class));
    }

    @override
    public list<user> getallusers() {
        string sql = "select * from user";
        return jdbctemplate.query(sql, new beanpropertyrowmapper<>(user.class));
    }

    @override
    public long adduser(user user) {
        string sql = "insert into user (first_name, last_name, email, user_avatar_url, podcast_id) " +
                "values (?, ?, ?, ?, ?)";
        jdbctemplate.update(sql, user.getfirstname(), user.getlastname(), user.getemail(),
                user.getuseravatarurl(), user.getpodcastid());

        // retrieve the auto-generated user_id
        return jdbctemplate.queryforobject("select last_insert_id()", long.class);
    }

    @override
    public void updateuser(user user) {
        string sql = "update user set first_name = ?, last_name = ?, email = ?, " +
                "user_avatar_url = ?, podcast_id = ? where user_id = ?";
        jdbctemplate.update(sql, user.getfirstname(), user.getlastname(), user.getemail(),
                user.getuseravatarurl(), user.getpodcastid(), user.getuserid());
    }

    @override
    public void deleteuser(long userid) {
        string sql = "delete from user where user_id = ?";
        jdbctemplate.update(sql, userid);
    }
}
登录后复制

userdao.java

package com.example.demo.dao;
import com.example.demo.model.user;

import java.util.list;

public interface userdao {
    user getuserbyid(long userid);

    list<user> getallusers();

    long adduser(user user);

    void updateuser(user user);

    void deleteuser(long userid);
}
登录后复制

demoapplication.java

package com.example.demo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
//@ComponentScan("com.example.demo.service")
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}
登录后复制

我在 demoapplication.java 中尝试过 @componentscan("com.example.demo.service") 但它不起作用。

我还尝试放置@autowire并用@service标记服务。我还检查了所有其他注释,没有发现任何其他遗漏的内容

我希望有一个干净的构建和对 api 的访问

错误

解决方法

您缺少 userservice 的实现。如果您想保留 @repository (userdao) 的当前实现,那么您可以按如下方式重写您的服务:

@Service
public class UserService {

    private final UserDao userDao;

    @Autowired
    public UserService(UserDao userDao) {
        this.userDao = userDao;
    }

    // implement using your DAO
    User getUserById(Long userId);
    List<User> getAllUsers();
    Long addUser(User user);
    void updateUser(User user);
    void deleteUser(Long userId);
}
登录后复制

这应该使其可供 usercontroller 使用。

以上就是com.example.demo.service.UserServiceImpl 中构造函数的参数 0 需要类型为“com.example.demo.dao.UserDao”的 bean的详细内容,更多请关注php中文网其它相关文章!

Echarts 提供这样的 Demo 吗?或者有图标软件提供这样的 Demo 吗?

Echarts 提供这样的 Demo 吗?或者有图标软件提供这样的 Demo 吗?

除了柱状图之外,还有一个上升的箭头

我们今天的关于java 操作 HDFS 相关 demoTDH,kerberos 认证的分享就到这里,谢谢您的阅读,如果想了解更多关于beeline 如何在没有有效 kerberos tgt 的情况下列出 hdfs?、clouder manager 启用 kerberos,启动 hdfs 报错、com.example.demo.service.UserServiceImpl 中构造函数的参数 0 需要类型为“com.example.demo.dao.UserDao”的 bean、Echarts 提供这样的 Demo 吗?或者有图标软件提供这样的 Demo 吗?的相关信息,可以在本站进行搜索。

本文标签: