我只找到通过hadoop dfsadmin -D xx=yy
设置属性的方法,
但是如何在命令行中找到特定属性xx
的值?
您可以通过运行转储Hadoop配置:
$ hadoop org.apache.hadoop.conf.Configuration
您可以使用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);
}
}
从配置中获取特定密钥
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