欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

如何解决WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform...

程序员文章站 2022-03-22 20:15:17
...

1、在启动和操作Hadoop过程中,总是会提示warning信息:

WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable
如何解决WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform...

搜索的结果大部分说是操作系统与hadoop的位数不一致造成的,然而事实并非如此。

由于上述warning并不能提供更多有效的信息,需要增加debug信息:

export HADOOP_ROOT_LOGGER=DEBUG,console

再次执行./stop-dfs.sh,这次debug到一些有用的信息:

16/07/05 15:33:54 DEBUG util.Shell: setsid exited with exit code 0
16/07/05 15:33:54 DEBUG lib.MutableMetricsFactory: field org.apache.hadoop.metrics2.lib.MutableRate org.apache.hadoop.security.UserGroupInformation$UgiMetrics.loginSuccess with annotation @org.apache.hadoop.metrics2.annotation.Metric(value=[Rate of successful kerberos logins and latency (milliseconds)], about=, valueName=Time, type=DEFAULT, always=false, sampleName=Ops)
16/07/05 15:33:54 DEBUG lib.MutableMetricsFactory: field org.apache.hadoop.metrics2.lib.MutableRate org.apache.hadoop.security.UserGroupInformation$UgiMetrics.loginFailure with annotation @org.apache.hadoop.metrics2.annotation.Metric(value=[Rate of failed kerberos logins and latency (milliseconds)], about=, valueName=Time, type=DEFAULT, always=false, sampleName=Ops)
16/07/05 15:33:54 DEBUG lib.MutableMetricsFactory: field org.apache.hadoop.metrics2.lib.MutableRate org.apache.hadoop.security.UserGroupInformation$UgiMetrics.getGroups with annotation @org.apache.hadoop.metrics2.annotation.Metric(value=[GetGroups], about=, valueName=Time, type=DEFAULT, always=false, sampleName=Ops)
16/07/05 15:33:54 DEBUG impl.MetricsSystemImpl: UgiMetrics, User and group related metrics
16/07/05 15:33:55 DEBUG security.Groups:  Creating new Groups object
16/07/05 15:33:55 DEBUG util.NativeCodeLoader: Trying to load the custom-built native-hadoop library...
<span style="color:#FF0000;">16/07/05 15:33:55 DEBUG util.NativeCodeLoader: Failed to load native-hadoop with error: java.lang.UnsatisfiedLinkError: no hadoop in java.library.path
16/07/05 15:33:55 DEBUG util.NativeCodeLoader: java.library.path=/usr/local/sinasrv2/hadoop/hadoop-2.6.4/lib
16/07/05 15:33:55 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable</span>
16/07/05 15:33:55 DEBUG util.PerformanceAdvisory: Falling back to shell based
16/07/05 15:33:55 DEBUG security.JniBasedUnixGroupsMappingWithFallback: Group mapping impl=org.apache.hadoop.security.ShellBasedUnixGroupsMapping
16/07/05 15:33:55 DEBUG security.Groups: Group mapping impl=org.apache.hadoop.security.JniBasedUnixGroupsMappingWithFallback; cacheTimeout=300000; warningDeltaMs=5000
16/07/05 15:33:55 DEBUG security.UserGroupInformation: hadoop login
16/07/05 15:33:55 DEBUG security.UserGroupInformation: hadoop login commit
16/07/05 15:33:55 DEBUG security.UserGroupInformation: using local user:UnixPrincipal: hadoop
16/07/05 15:33:55 DEBUG security.UserGroupInformation: Using user: "UnixPrincipal: hadoop" with name hadoop
16/07/05 15:33:55 DEBUG security.UserGroupInformation: User entry: "hadoop"
16/07/05 15:33:55 DEBUG security.UserGroupInformation: UGI loginUser:hadoop (auth:SIMPLE)
16/07/05 15:33:55 DEBUG security.UserGroupInformation: PrivilegedAction as:hadoop (auth:SIMPLE) from:org.apache.hadoop.hdfs.tools.GetConf.run(GetConf.java:314)

我们发现,libhadoop.so是存放在/usr/local/sinasrv2/hadoop/hadoop-2.6.4/lib/native下的
在hadoop包中搜索发现,java.library.path被定义为$JAVA_LIBRARY_PATH

$ grep -R 'java.library.path' *
bin/yarn:  YARN_OPTS="$YARN_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
bin/yarn.cmd:    set YARN_OPTS=%YARN_OPTS% -Djava.library.path=%JAVA_LIBRARY_PATH%
etc/hadoop/yarn-env.sh:  YARN_OPTS="$YARN_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
etc/hadoop/yarn-env.cmd:  set YARN_OPTS=%YARN_OPTS% -Djava.library.path=%JAVA_LIBRARY_PATH%
libexec/hadoop-config.sh:# setup 'java.library.path' for native-hadoop code if necessary
libexec/hadoop-config.sh:  HADOOP_OPTS="$HADOOP_OPTS -Djava.library.path=$JAVA_LIBRARY_PATH"
libexec/hadoop-config.cmd:@rem setup 'java.library.path' for native hadoop code if necessary
libexec/hadoop-config.cmd:  set HADOOP_OPTS=%HADOOP_OPTS% -Djava.library.path=%JAVA_LIBRARY_PATH%
share/doc/hadoop/common/CHANGES.txt:    HADOOP-8756. Fix SEGV when libsnappy is in java.library.path but
share/doc/hadoop/common/CHANGES.txt:    HADOOP-1660. Add the cwd of the map/reduce task to the java.library.path
share/doc/hadoop/common/CHANGES.txt: 50. HADOOP-1493.  Permit specification of "java.library.path" system
share/doc/hadoop/common/CHANGES.txt:10. HADOOP-873.      Pass java.library.path correctly to child processes.
share/doc/hadoop/common/CHANGES.txt:42. HADOOP-838.  Fix tasktracker to pass java.library.path to
share/doc/hadoop/mapreduce/CHANGES.txt:    MAPREDUCE-4458. Warn if java.library.path is used for AM or Task
share/doc/hadoop/mapreduce/CHANGES.txt:    MAPREDUCE-4072. User set java.library.path seems to overwrite default
share/doc/hadoop/mapreduce/CHANGES.txt:    MAPREDUCE-3259. Added java.library.path of NodeManager to

但是此时发现环境变量JAVALIBRARYPATHvim /.bashrcJAVA_LIBRARY_PATH环境变量

export JAVA_LIBRARY_PATH=’/usr/local/sinasrv2/hadoop/hadoop-2.6.4/lib/native’
如何解决WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform...

这里还要特别说明的是,一定要注意自己的Hadoop以及JDK版本型号,配置环境变量的时候不能有丝毫差错!
还有一点就是有些人在/etc/profile文件中配置变量,那就要在该文件中进行修改,本人是在~/.bashrc文件中进行修改的。
source ~/.bashrc 使之生效。
再执行,则不会出现上述warning信息
如何解决WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform...
希望对大家有所帮助,此文是本人在借鉴前人的经验上总结出来的,我们热爱开源,于是将此文放到网上,谢谢!

相关标签: hadoop