错误分析
Stopping namenodes on [node1 node2 node3]
ERROR: Attempting to operate on hdfs namenode as root
ERROR: but there is no HDFS_NAMENODE_USER defined. Aborting operation.
Stopping datanodes
ERROR: Attempting to operate on hdfs datanode as root
ERROR: but there is no HDFS_DATANODE_USER defined. Aborting operation.
Stopping journal nodes [node2 node3 node1]
ERROR: Attempting to operate on hdfs journalnode as root
ERROR: but there is no HDFS_JOURNALNODE_USER defined. Aborting operation.
Stopping ZK Failover Controllers on NN hosts [node1 node2 node3]
ERROR: Attempting to operate on hdfs zkfc as root
ERROR: but there is no HDFS_ZKFC_USER defined. Aborting operation.
原因
如果使用的是root用户则会出现以上错误。因为在 Hadoop 的默认配置中,出于安全考虑,不建议或不允许以 root 用户(或任何拥有超级用户权限的账户)来启动或停止 HDFS 。这是因为以 root 用户运行服务可能会增加系统安全风险。
解决方法
在环境变量里面添加如下内容:
export HADOOP_HOME=/opt/module/hadoop-3.1.3
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin
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
export HDFS_JOURNALNODE_USER=root
export HDFS_ZKFC_USER=root
说明:如果没有做HA,则不需要添加export HDFS_ZKFC_USER=root