本文主要是介绍启动hadoop集群时报错ERROR: Attempting to operate on hdfs namenode as root,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
问题描述
安装搭建了hadoop集群,然后启动时报错,错误如下:
[root@hadoop101 ~]# /opt/module/hadoop/hadoop-3.1.3/sbin/start-dfs.sh
Starting namenodes on [hadoop101]
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 [hadoop103]
ERROR: Attempting to operate on hdfs secondarynamenode as root
ERROR: but there is no HDFS_SECONDARYNAMENODE_USER defined. Aborting operation.
[root@hadoop102 ~]# /opt/module/hadoop/hadoop-3.1.3/sbin/start-yarn.sh
Starting resourcemanager
ERROR: Attempting to operate on yarn resourcemanager as root
ERROR: but there is no YARN_RESOURCEMANAGER_USER defined. Aborting operation.
Starting nodemanagers
ERROR: Attempting to operate on yarn nodemanager as root
ERROR: but there is no YARN_NODEMANAGER_USER defined. Aborting operation.
原因分析:
这个涉及到hadoop的安全机制问题,错误原因是你正在以root用户身份尝试启动Hadoop服务,但是在环境变量中没有定义Hadoop相关服务的用户。Hadoop通常不建议以root用户身份来启动服务,因为这可能会导致安全漏洞。如果以普通用户来启动就不会报这个错误。
解决方案:
1. 方法一:复制粘贴以下命令添加环境变量
echo >> ~/.bashrc
echo 'export HDFS_NAMENODE_USER=root' >> ~/.bashrc
echo 'export HDFS_DATANODE_USER=root' >> ~/.bashrc
echo 'export HDFS_SECONDARYNAMENODE_USER=root' >> ~/.bashrc
echo 'export YARN_RESOURCEMANAGER_USER=root' >> ~/.bashrc
echo 'export YARN_NODEMANAGER_USER=root' >> ~/.bashrc
source ~/.bashrc
然后分别使用ssh命令链接到其他两个节点执行这个命令
ssh root@hadoop102
echo >> ~/.bashrc
echo 'export HDFS_NAMENODE_USER=root' >> ~/.bashrc
echo 'export HDFS_DATANODE_USER=root' >> ~/.bashrc
echo 'export HDFS_SECONDARYNAMENODE_USER=root' >> ~/.bashrc
echo 'export YARN_RESOURCEMANAGER_USER=root' >> ~/.bashrc
echo 'export YARN_NODEMANAGER_USER=root' >> ~/.bashrc
source ~/.bashrc
sleep 1
exit
ssh root@hadoop103
echo >> ~/.bashrc
echo 'export HDFS_NAMENODE_USER=root' >> ~/.bashrc
echo 'export HDFS_DATANODE_USER=root' >> ~/.bashrc
echo 'export HDFS_SECONDARYNAMENODE_USER=root' >> ~/.bashrc
echo 'export YARN_RESOURCEMANAGER_USER=root' >> ~/.bashrc
echo 'export YARN_NODEMANAGER_USER=root' >> ~/.bashrc
source ~/.bashrc
sleep 1
exit
2. 方法二:手动复制以下代码添加到~/.bashrc文件中
编辑文件:
vim ~/.bashrc
添加代码:
export HDFS_NAMENODE_USER=root
export HDFS_DATANODE_USER=root
export HDFS_SECONDARYNAMENODE_USER=root
export YARN_RESOURCEMANAGER_USER=root
export YARN_NODEMANAGER_USER=root
加载环境变量:
source ~/.bashrc
然后再分别使用ssh
命令切换到其他两个节点重复以上操作。
这篇关于启动hadoop集群时报错ERROR: Attempting to operate on hdfs namenode as root的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!