命令行读取hdfs集群的全部配置

编译以下代码并打成jar包:

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.conf.Configured;
import org.apache.hadoop.util.Tool;
import org.apache.hadoop.util.ToolRunner;

import java.util.Map.Entry;

public class HadoopConfDisplay extends Configured implements Tool {

    static {
        Configuration.addDefaultResource("core-default.xml");
        Configuration.addDefaultResource("yarn-default.xml");
        Configuration.addDefaultResource("mapred-default.xml");
        Configuration.addDefaultResource("core-site.xml");
        Configuration.addDefaultResource("hdfs-site.xml");
        Configuration.addDefaultResource("mapred-site.xml");
        Configuration.addDefaultResource("yarn-site.xml");
    }

    public int run(String[] args) throws Exception {
        Configuration conf = getConf();
        for (Entry<String, String> entry: conf) {
            System.out.printf("%s=%s\n", entry.getKey(), entry.getValue());
        }
        return 0;
    }

    public static void main(String[] args) throws Exception {
        int exitCode = ToolRunner.run(new HadoopConfDisplay(), args);
        System.exit(exitCode);
    }
}

或者使用以下已经编译好的:

hadoop-custom-tools.tar.gz

执行:

hadoop jar hadoop-custom-tools.jar HadoopConfDisplay

即可

发表评论

电子邮件地址不会被公开。

22 − 18 =