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

new*_*erl 19 hadoop

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

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

Pau*_*lgo 46

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

$ hadoop org.apache.hadoop.conf.Configuration
Run Code Online (Sandbox Code Playgroud)

  • 但该命令只转储核心站点,以便如何转储hdfs-site (2认同)

rys*_*sov 6

您可以使用GenericOptionsParser将Hadoop的设置加载到Configuration-typed对象并迭代其属性.以下示例通过实用程序类(已配置)演示此方法.

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


kox*_*oxt 6

从配置中获取特定键

hdfs getconf -confKey [key]

hdfs getconf -confKey dfs.replication
Run Code Online (Sandbox Code Playgroud)

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