WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-

1. 问题来源

hadoop 启动时 控制台一直提示 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform… using builtin-java classes where applicable

Starting namenodes on [localhost]
ERROR: Attempting to operate on hdfs namenode as root
ERROR: but there is no HDFS_NAMENODE_USER defined. Aborting operation.
Starting datanodes
ERROR: Attempting to operate on hdfs datanode as root
ERROR: but there is no HDFS_DATANODE_USER defined. Aborting operation.
Starting secondary namenodes [MacBook-Pro.local]
ERROR: Attempting to operate on hdfs secondarynamenode as root
ERROR: but there is no HDFS_SECONDARYNAMENODE_USER defined. Aborting operation.
2024-01-13 17:34:36,524 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable

虽说不是error 但是看这个错误 有点难受 ! 还是来看看是否 可以解决

2. 分析

  • hadoop的可执行文件 是在专门的机器上编译的 其中native库 不一定能适用于每个机器
  • 未正确配置hadoop加载native lib

3. 解决

  • 比较简答的解决方案 – 眼不见心不烦 直接关闭告警日志的输出
    ${HADOOP_HOME}/etc/hadoop/log4j.properties
    在这个文件 新增一句
log4j.logger.org.apache.hadoop.util.NativeCodeLoader=ERROR
  • 配置hadoop加载native lib
    修改 ${HADOOP_HOME}/etc/hadoop/hadoop-env.sh 文件
#修改为自己的hadoop 目录
export HADOOP_HOME=/usr/local/develop/hadoop-3.3.6
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export HADOOP_OPTS="$HADOOP_OPTS -Djava.library.path=$HADOOP_HOME/lib/native"
  • 编译源码 替换自带的 native lib 另外 提供了已经编译好的版本 同时也提供了使用说明 参见: https://github.com/silent-night-no-trace/mac-native-hadoop-library

    替换完成后的效果 如下
    WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-_第1张图片
    其中3.3.6 源码的编译 有点烦躁 目前只编译了重点的部分 common 和 hdfs 和 mapreduce

编译源码参考文章:

  • 源码目录下有个BUILDING.txt https://github.com/apache/hadoop/blob/trunk/BUILDING.txt

你可能感兴趣的:(大数据搭建问题,hadoop,大数据)