Hadoop集群运行

在Hadoop文件参数配置完成之后

在master上操作

su - hadoop
cd /usr/local/src/hadoop/
./bin/hdfs namenode -format
hadoop-daemon.sh start namenode
hadoop-daemon.sh start secondarynamenode
jps

如果看到NameNode和SecondaryNameNode就表示成功

在slave上操作

su - hadoop
hadoop-daemon.sh start datanode
jps

如果看到DataNode就表示成功

在master上操作

su - hadoop
hdfs dfsadmin -report

给用户做免密

ssh-keygen -t rsa
ssh-copy-id slave1
ssh-copy-id slave2
ssh-copy-id master
stop-dfs.sh
start-dfs.sh
start-yarn.sh
jps

如果在master上看到ResourceManager,并且在slave上看到NodeManager就表示成功

hdfs dfs -mkdir /input
hdfs dfs -ls /
mkdir ~/input
vi ~/input/data.txt
hello world
hello hadoop
hello zzz

保存后执行以下命令

hdfs dfs -put ~/input/data.txt /input
hdfs dfs -cat /input/data.txt
hadoop jar /usr/local/src/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.1.jar wordcount /input/data.txt /output

执行完后要看到map是100%,reduce也是100%,还要看到successfully

hdfs dfs -cat /output/part-r-00000

在windows真机上执行

进入C:\windows\system32\drivers\etc
把此目录下的hosts文件拖到桌面上
右键打开此文件加入ip与主机名的映射关系
保存后拖回原文件
在浏览器上输入master:8088访问可以看到 MapReduce程序刚刚完成的作业
在浏览器上输入master:50070访问namenode和datanode
在浏览器上输入master:50090访问secondarynamenode

停止 Hadoop(非必要步骤)

1.步骤一:停止 yarn
[hadoop@master hadoop]$ stop-yarn.sh

步骤二:停止 DataNode
[hadoop@slave1 hadoop]$ hadoop-daemon.sh stop datanode
stopping namenode
[hadoop@slave2 hadoop]$ hadoop-daemon.sh stop datanode
stopping namenode

步骤二:停止 NameNode
[hadoop@master hadoop]$ hadoop-daemon.sh stop namenode
stopping namenode

步骤三:停止 SecondaryNameNode
[hadoop@master hadoop]$ hadoop-daemon.sh stop secondarynamenode
stopping secondarynamenode

步骤四:查看 JAVA进程,确认 HDFS进程已全部关闭
[hadoop@master hadoop]$ jps
3528 Jps
30838 RunJar

报错补充

如果报错:
hadoop-3.1.3启动HDFS时报错,具体错误信息如下:

[root@hadoop10 hadoop-3.1.3]# sbin/start-dfs.sh 
Starting namenodes on [hadoop10]
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 [hadoop12]
ERROR: Attempting to operate on hdfs secondarynamenode as root
ERROR: but there is no HDFS_SECONDARYNAMENODE_USER defined. Aborting operation.

解决方法1:

直接在环境变量中添加配置

vim /etc/profile.d/my_env.sh

*my_env.sh是自己添加的文件,不建议直接修改profile.d

添加的配置如下:

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 /etc/profile.d/my_env.sh

解决方法2:

*文件在hadoop安装目录的sbin目录下

在start-dfs.sh,stop-dfs.sh 两个文件顶部添加以下参数:

HDFS_DATANODE_USER=root
HADOOP_SECURE_DN_USER=hdfs
HDFS_NAMENODE_USER=root
HDFS_SECONDARYNAMENODE_USER=root

在start-yarn.sh,stop-yarn.sh两个文件顶部添加以下参数:

YARN_RESOURCEMANAGER_USER=root
HADOOP_SECURE_DN_USER=yarn
YARN_NODEMANAGER_USER=root

修改完成后,将修改的配置文件copy到其他的节点
配置好相应文件后
重新启动即可

sbin/start-dfs.sh
Starting namenodes on [hadoop10]
上一次登录:四 12月 10 10:15:53 CST 2020从 192.168.157.1pts/0 上
Starting datanodes
上一次登录:四 12月 10 10:53:50 CST 2020pts/0 上
hadoop12: Warning: Permanently added 'hadoop12,192.168.157.12' (ECDSA) to the list of known hosts.
localhost: Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts.
hadoop11: WARNING: /opt/module/hadoop-3.1.3/logs does not exist. Creating.
hadoop12: WARNING: /opt/module/hadoop-3.1.3/logs does not exist. Creating.
Starting secondary namenodes [hadoop12]
上一次登录:四 12月 10 10:53:53 CST 2020pts/0 上

其他报错

  • 如果start-dfs.sh之后没有namenode或者8088的网页访问不了,关闭防火墙 并 需要删除hadoop3-1.3的同级目录的hadoop目录以及hadoop3-1.3/logs文件,再次格式化hadoop(命令:hadoop namenode -format)并启动start-dfs.sh和start-yarn.sh即可!
posted @ 2022-04-09 19:43  郑琰  阅读(65)  评论(0编辑  收藏  举报
#

# #