hadoop - 有什么办法可以在 Windows 环境中从虚拟机的 hdfs 系统打开文件?

标签 hadoop hdfs hortonworks-data-platform

也许我的问题有点愚蠢,但我想在主机 Windows 环境中访问 hdfs 文件,特别是在 eclipse 中。 Hadoop 和所有相关的东西都安装在 VirtualBox 上(使用 Hortonworks Sandbox 环境。使用 Centos OS)。在虚拟机上,我可以毫无问题地使用 hdfs,尝试访问 hdfs://192.168.56.101:8020/user/root/vectors/dictionary.file-0。尝试在 eclipse 上访问它,但出现异常。

那么,有什么办法吗?如果可能的话,最好能得到一个例子。

最佳答案

问题的主要原因是系统不知道我是谁。 我需要一个hadoop的客户端,所以通过在pom中添加客户端依赖来解决问题:

    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-client</artifactId>
        <version>2.2.0</version>
    </dependency>

这是工作示例:

public static void main(String[] args) throws Exception {
    try {
        Configuration conf = new Configuration();
        conf.set("fs.default.name", "hdfs://192.168.56.101:8020");
        FileSystem fs = FileSystem.get(conf);
        Path pt = new Path("/user/root/vectors/dictionary.file-0");
        BufferedReader br = new BufferedReader(new InputStreamReader(fs.open(pt)));
        try {
            String line;
            line = br.readLine();
            while (line != null) {
                System.out.println(line);
                line = br.readLine();
            }
        } finally {
            br.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

关于hadoop - 有什么办法可以在 Windows 环境中从虚拟机的 hdfs 系统打开文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20530902/

相关文章:

Hadoop:文件覆盖问题

scala - 一次处理每个分区中的每个分区和每一行

ubuntu - 在 Ubuntu 12.04 上安装 Hadoop 的问题

Hadoop 独立 - hdfs 命令很慢

hadoop - 在Mahout中根据文本创建矢量的问题

mysql - 截断命令(Hive 与 SQL)

hadoop - PIGLatin是否支持Parquet文件的谓词下推

hdfs - Cloudera 5.4.2 : Avro block size is invalid or too large when using Flume and Twitter streaming

hadoop - Hadoop安装:什么是 “This is comment for WebHCat Service (sic)”

hadoop - HDP沙箱: yum install is throwing 403 error