当前目录:/opt/module/hadoop-2.7.2/logs
[atguigu@hadoop101 logs]$ ls hadoop-atguigu-datanode-hadoop.atguigu.com.log hadoop-atguigu-datanode-hadoop.atguigu.com.out hadoop-atguigu-namenode-hadoop.atguigu.com.log hadoop-atguigu-namenode-hadoop.atguigu.com.out SecurityAuth-root.audit [atguigu@hadoop101 logs]# cat hadoop-atguigu-datanode-hadoop101.log
思考:为什么不能一直格式化NameNode,格式化NameNode,要注意什么?
[atguigu@hadoop101 hadoop-2.7.2]$ cd data/tmp/dfs/name/current/ [atguigu@hadoop101 current]$ cat VERSION clusterID=CID-f0330a58-36fa-4a2a-a65f-2688269b5837 [atguigu@hadoop101 hadoop-2.7.2]$ cd data/tmp/dfs/data/current/ clusterID=CID-f0330a58-36fa-4a2a-a65f-2688269b5837注意:格式化NameNode,会产生新的集群id,导致NameNode和DataNode的集群id不一致,集群找不到已往数据。所以,格式NameNode时,一定要先删除data数据和log日志,然后再格式化NameNode。
操作集群
在HDFS文件系统上创建一个input文件夹
[atguigu@hadoop101 hadoop-2.7.2]$ bin/hdfs dfs -mkdir -p /user/atguigu/input将测试文件内容上传到文件系统上
[atguigu@hadoop101 hadoop-2.7.2]$bin/hdfs dfs -put wcinput/wc.input /user/atguigu/input/查看上传的文件是否正确
[atguigu@hadoop101 hadoop-2.7.2]$ bin/hdfs dfs -ls /user/atguigu/input/ [atguigu@hadoop101 hadoop-2.7.2]$ bin/hdfs dfs -cat /user/atguigu/ input/wc.input运行MapReduce程序
[atguigu@hadoop101 hadoop-2.7.2]$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /user/atguigu/input/ /user/atguigu/output
查看输出结果
命令行查看:
[atguigu@hadoop101 hadoop-2.7.2]$ bin/hdfs dfs -cat /user/atguigu/output/*
浏览器查看:
将测试文件内容下载到本地
[atguigu@hadoop101 hadoop-2.7.2]$ hdfs dfs -get /user/atguigu/output/part-r-00000 ./wcoutput/删除输出结果
[atguigu@hadoop101 hadoop-2.7.2]$ hdfs dfs -rm -r /user/atguigu/output YARN上运行MapReduce 程序
分析
配置集群YARN上运行
启动、测试集群增、删、查
在YARN上执行WordCount案例
执行步骤
配置集群
配置yarn-env.sh
配置一下JAVA_HOME
export JAVA_HOME=http://www.likecs.com/opt/module/jdk1.8.0_144
配置yarn-site.xml
<!-- reducer获取数据的方式 --> <property> <name>yarn.nodemanager.aux-services</name> <value>mapreduce_shuffle</value> </property> <!-- 指定YARN的ResourceManager的地址 --> <property> <name>yarn.resourcemanager.hostname</name> <value>hadoop101</value> </property>
配置:mapred-env.sh
配置一下JAVA_HOME
export JAVA_HOME=http://www.likecs.com/opt/module/jdk1.8.0_144
配置: (对mapred-site.xml.template重新命名为) mapred-site.xml
[atguigu@hadoop101 hadoop]$ mv mapred-site.xml.template mapred-site.xml [atguigu@hadoop101 hadoop]$ vi mapred-site.xml <!-- 指定MR运行在YARN上 --> <property> <name>mapreduce.framework.name</name> <value>yarn</value> </property>
启动集群
启动前必须保证NameNode和DataNode已经启动
启动ResourceManager
[atguigu@hadoop101 hadoop-2.7.2]$ sbin/yarn-daemon.sh start resourcemanager
启动NodeManager
[atguigu@hadoop101 hadoop-2.7.2]$ sbin/yarn-daemon.sh start nodemanager
集群操作
YARN的浏览器页面查看
:8088/cluster
2. 删除文件系统上的output文件 ```shell [atguigu@hadoop101 hadoop-2.7.2]$ bin/hdfs dfs -rm -R /user/atguigu/output ``` 3. 执行MapReduce程序 ```shell [atguigu@hadoop101 hadoop-2.7.2]$ bin/hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-2.7.2.jar wordcount /user/atguigu/input /user/atguigu/output ``` 4. 查看运行结果 ```shell [atguigu@hadoop101 hadoop-2.7.2]$ bin/hdfs dfs -cat /user/atguigu/output/* ``` ![](https://img2020.cnblogs.com/blog/1577985/202007/1577985-20200712095811301-1726117772.png) 配置历史服务器为了查看程序的历史运行情况,需要配置一下历史服务器
配置mapred-site.xml
[atguigu@hadoop101 hadoop]$ vi mapred-site.xml