如何从java通过hdfs协议访问hadoop?
我找到了一种通过 hftp 连接到 hadoop 的方法,它工作正常,(只读):
uri = "hftp://172.16.xxx.xxx:50070/";
System.out.println( "uri: " + uri );
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get( URI.create( uri ), conf );
fs.printStatistics();
但是,我想读/写以及复制文件,也就是说,我想通过以下方式连接HDFS。如何启用 hdfs 连接以便可以编辑实际的远程文件系统?
我尝试从 hftp
更改上面的协议 -> hdfs
,但我得到了以下异常...
(请原谅我对 url 协议和 hadoop 的了解不足,我认为这是我问的一个有点奇怪的问题,但任何帮助将不胜感激!)
线程“main”中的异常 java.io.IOException:本地异常调用 /172.16.112.131:50070 失败:java.io.EOFException at org.apache.hadoop.ipc.Client.wrapException(Client.java:第1139章 1107 org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:226) 位于 org.apache.hadoop.ipc.RPC.getProxy(RPC.java:398) 处 $Proxy0.getProtocolVersion(未知来源) .apache.hadoop.ipc.RPC.getProxy(RPC.java:384) 在org.apache.hadoop.hdfs.DFSClient.createRPCNamenode(DFSClient.java:111) 在 org.apache.hadoop.hdfs.DFSClient.(DFSClient.java:213) 在 org.apache.hadoop.hdfs.DFSClient.(DFSClient.爪哇:180)在org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:89) 在 org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1514) 在 org.apache.hadoop.fs.FileSystem.access$200 (文件系统.java:67)位于org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:1548) 在 org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1530) 在 org.apache.hadoop.fs。 FileSystem.get(FileSystem.java:228) at sb.HadoopRemote.main(HadoopRemote.java:24)
I found a way to connect to hadoop via hftp
, and it works fine, (read only) :
uri = "hftp://172.16.xxx.xxx:50070/";
System.out.println( "uri: " + uri );
Configuration conf = new Configuration();
FileSystem fs = FileSystem.get( URI.create( uri ), conf );
fs.printStatistics();
However, I want to read/write as well as copy files, that is, I want to connect over hdfs . How can I enable hdfs connections so that i can edit the actual , remote filesystem ?
I tried to change the protocol above from hftp
-> hdfs
, but I got the following exception ...
(forgive my poor knowledge of url protocols and hadoop , I assume this is a somewhat strange question im asking, but any help would really be appreciated !)
Exception in thread "main" java.io.IOException: Call to /172.16.112.131:50070 failed on local exception: java.io.EOFException at org.apache.hadoop.ipc.Client.wrapException(Client.java:1139) at org.apache.hadoop.ipc.Client.call(Client.java:1107) at org.apache.hadoop.ipc.RPC$Invoker.invoke(RPC.java:226) at $Proxy0.getProtocolVersion(Unknown Source) at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:398) at org.apache.hadoop.ipc.RPC.getProxy(RPC.java:384) at org.apache.hadoop.hdfs.DFSClient.createRPCNamenode(DFSClient.java:111) at org.apache.hadoop.hdfs.DFSClient.(DFSClient.java:213) at org.apache.hadoop.hdfs.DFSClient.(DFSClient.java:180) at org.apache.hadoop.hdfs.DistributedFileSystem.initialize(DistributedFileSystem.java:89) at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:1514) at org.apache.hadoop.fs.FileSystem.access$200(FileSystem.java:67) at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:1548) at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:1530) at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:228) at sb.HadoopRemote.main(HadoopRemote.java:24)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需将您想要访问的 hadoop 的
core-site.xml
和hdfs-site.xml
添加到conf
中,如下所示:Just add the
core-site.xml
and thehdfs-site.xml
of the hadoop you want to hit toconf
, something like this:关于 hadoop :您需要确保
core-site.xml
namenode 条目服务于0.0.0.0
而不是127.0.0.1
(localhost )在你的hadoop配置中。重要的是,出于某种原因,clouderasvm distro
默认为localhost
。Regarding hadoop : You need to make sure the
core-site.xml
namenode entry is serving to0.0.0.0
instead of127.0.0.1
(localhost) in your hadoop configuration. Importantly, clouderasvm distro
defaults tolocalhost
for some reason.