我已经在服务器VM上设置了hadoop(伪分布式),并且正在尝试使用Java API访问HDFS。
我服务器上的fs.default.name是hdfs://0.0.0.0:9000
(因为localhost:9000
它不接受来自远程站点的请求)。
我可以在端口9000上连接到服务器
$ telnet srv-lab 9000
Trying 1*0.*.30.95...
Connected to srv-lab
Escape character is '^]'.
^C
这向我表明连接应该可以正常工作。我正在使用的Java代码是:
try {
Path pt = new Path(
"hdfs://srv-lab:9000/test.txt");
Configuration conf = new Configuration();
conf.set("fs.default.name", "hdfs://srv-lab:9000");
FileSystem fs = FileSystem.get(conf);
BufferedReader br = new BufferedReader(new InputStreamReader(
fs.open(pt)));
String line;
line = br.readLine();
while (line != null) {
System.out.println(line);
line = br.readLine();
}
} catch (Exception e) {
e.printStackTrace();
}
但是我得到的是:
java.net.ConnectException: Call From clt-lab/1*0.*.2*2.205 to srv-lab:9000 failed on connection exception: java.net.ConnectException: Connection refused; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused
因此,即使通过telnet进行连接也能正常工作,但为什么拒绝连接的任何提示呢?
您的hdfs输入错误。fs.default.name必须设置为hdfs://srv-lab:9000
。进行设置并重新启动集群。这将解决问题
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句