我如何在命令行中打印hadoop属性?

问题描述 投票:20回答:3

我只找到通过hadoop dfsadmin -D xx=yy设置属性的方法,

但是如何在命令行中找到特定属性xx的值?

hadoop
3个回答
47
投票

您可以通过运行转储Hadoop配置:

$ hadoop org.apache.hadoop.conf.Configuration

6
投票

您可以使用GenericOptionsParser将Hadoop的设置加载到配置类型的对象并对其属性进行迭代。这是一个通过实用程序类(已配置)演示此方法的示例。

public class ConfigPrinter extends Configured implements Tool {
    static {
        // by default core-site.xml is already added
        // loading "hdfs-site.xml" from classpath
        Configuration.addDefaultResource("hdfs-site.xml");
        Configuration.addDefaultResource("mapred-site.xml");
    }

    @Override
    public int run(String[] strings) throws Exception {
        Configuration config =  this.getConf();
        for (Map.Entry<String, String> entry : config) {
            System.out.println(entry.getKey() + " = " + entry.getValue());
        }
        return 0;
    }

    public static void main(String[] args) throws Exception {
        ToolRunner.run(new ConfigPrinter(), args);
    }
}

1
投票

从配置中获取特定密钥

hdfs getconf -confKey [key]

hdfs getconf -confKey dfs.replication

https://hadoop.apache.org/docs/r2.7.1/hadoop-project-dist/hadoop-hdfs/HDFSCommands.html#getconf

© www.soinside.com 2019 - 2024. All rights reserved.