如何使用javaapi访问远程hdfs集群的配置xml文件?

2izufjch  于 2021-05-29  发布在  Hadoop
关注(0)|答案(1)|浏览(342)

我有一个namenode地址(ip地址和端口),但我不知道配置文件(即core-site.xml、hdfs site.xml等)在本地文件系统上的位置。我想访问配置详细信息。
我知道通过下面的步骤我可以得到细节,

Configuration conf = new Configuration();
conf.addResource(file path of core-site.xml);
conf.addResource(file path of hdfs-site.xml);

它在我知道文件路径的本地机器上工作。但是我不知道远程机器上文件的位置。
有没有办法访问配置?

whitzsjs

whitzsjs1#

如果真正的问题是如何在一个集群中运行代码并在另一个集群上访问hdfs,那么您不需要像大多数教程所示那样添加resource core-site.xml和hdfs-site.xml。

Configuration conf = new Configuration();
    //conf.addResource(new Path("/etc/hadoop/conf/core-site.xml"));
    //conf.addResource(new Path("/etc/hadoop/conf/hdfs-site.xml"));
    //FileSystem fs = FileSystem.get(conf);
    String fromFileName = "hdfs://my.source.cluster/a/b/c";
    String toFileName = "hdfs://my.dest.cluster/d/e/f";
    FileSystem fromFs = FileSystem.get(new URI(fromFileName),conf);
    FileSystem toFs = FileSystem.get(new URI(toFileName),conf);

相关问题