从远程机器访问hadoop

mro*_*man 5 java hadoop

我在服务器 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
Run Code Online (Sandbox Code Playgroud)

这向我表明连接应该可以正常工作。我正在使用的 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();
    }
Run Code Online (Sandbox Code Playgroud)

但我得到的是:

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
Run Code Online (Sandbox Code Playgroud)

因此,即使通过 telnet 连接工作正常,有关为什么拒绝连接的任何提示?

Tha*_*nga 4

你的hdfs条目是错误的。fs.default.name 必须设置为hdfs://srv-lab:9000。设置此项并重新启动集群。这将解决问题