首先,我尝试了如何从Mapper Hadoop设置系统环境变量?但是mapred.map. child.env
不适合我。
我正在使用hadoop 0.20.1。我想将启动作业的类中的所有系统环境传递给映射器。这是我的工作:
StringBuilder envStr = new StringBuilder();
for (Entry<String, String> entry : System.getenv().entrySet()) {
envStr.append(entry.getKey() + "=" + entry.getValue() + ",");
}
if (envStr.length() > 0) {
envStr.deleteCharAt(envStr.length() - 1);
}
// System.out.println("Setting mapper child env to :" + envStr);
getConf().set("mapred.map.child.env", envStr.toString());
但是它不起作用。我也尝试过只设置一个系统值,但它也不起作用。在Mapper中,System. getenv不包含该值。但是job.xml有键和值。有什么方法可以做到这一点吗?
看来你的hadoop太老了,这是hadoop 0.20的bug。
请升级到0.21或更稳定的1.0. x。
有关详细信息,请参阅相关的jira和hadoop 0.21.0发行说明。