伪分布模式hdfs
1.启动hsfs
2. 编辑vi hadoop-env.sh
![image.png](https://i-blog.csdnimg.cn/blog_migrate/0db796d1e2bf0cfd5a76927158a8dfc5.webp?x-image-process=image/format,png)
![image.png](https://i-blog.csdnimg.cn/blog_migrate/bafa90e8c1874d45e4138f14b3fadb4e.webp?x-image-process=image/format,png)
3.配置nameNode和生产文件第地址
[shaozhiqi@hadoop101 hadoop]$ vi core-site.xml
指定HDFS中NameNode的地址
<configuration>
<property>
<name>fs.defaultFS</name> <value>hdfs://hadoop101:9000</value> </property> <!--指定hadoop运行时产生的临时文件存储的目录--> <property> <name>hadoop.tmp.dir</name> <value>/opt/module/hadoop-3.1.2/data/tmp</value> </property> </configuration>
4.指定HDFS的副本数
[shaozhiqi@hadoop101 hadoop]$ vi hdfs-site.xml
<property>
<name>dfs.replication</name> <value>1</value> </property>
只有一个节点的话相同数据只存放一份,配置三没用,照样存储一份
启动hdfs
1. 格式化nameNode
hdfs namenode –format //生成name的工作空间
![image.png](https://i-blog.csdnimg.cn/blog_migrate/dfe1e8eb6983aa555a696bc2e7a8fba3.webp?x-image-process=image/format,png)
可以看到data文件夹已被创建
![image.png](https://i-blog.csdnimg.cn/blog_migrate/0695b85b61936a384dec4e0407deec3b.webp?x-image-process=image/format,png)
查看version可以看到我们的namenode id和集群id已生成
namespaceID=942797111
clusterID=CID-b853720f-e038-4541-a038-bb78bb01452a
![image.png](https://i-blog.csdnimg.cn/blog_migrate/bf2368e317af0afe2db840bf5e686d21.webp?x-image-process=image/format,png)
2. 启动
查看hadoop有哪些命令
![image.png](https://i-blog.csdnimg.cn/blog_migrate/2a1ec4b118a4b0e21c4889c6477f488e.webp?x-image-process=image/format,png)
hadoop-daemon.sh //是hadoop单节点守护进程的命令
3. 启动namenodeh
hadoop-daemon.sh start namenode
![image.png](https://i-blog.csdnimg.cn/blog_migrate/9a78126fd705e402582bfe1fb620580f.webp?x-image-process=image/format,png)
查看是否启动成功
Jsp是jdk提供的java的查看哪些java进程(linux是ps -ef)
![image.png](https://i-blog.csdnimg.cn/blog_migrate/4c33d60ed8940dd5a05fdad68dbf4c31.webp?x-image-process=image/format,png)
如图启动成功
查看namenode web页面
192.168.1.101:9870(3.x+版本),旧版本的端口是50070
如果无法访问查看防火墙是否开启,若是开启就将它关闭:
[shaozhiqi@hadoop101 hadoop-3.1.2]$ systemctl stop firewalld.service
![image.png](https://i-blog.csdnimg.cn/blog_migrate/13fcf586a78d54a8a735fb709923c612.webp?x-image-process=image/format,png)
4. 启动datenode
[shaozhiqi@hadoop101 hadoop-3.1.2]$ hadoop-daemon.sh start datanode
<div align="right">
![image.png](https://i-blog.csdnimg.cn/blog_migrate/b94b6724924303d8922e90f2700b4013.webp?x-image-process=image/format,png)
</div>
查看web端
![image.png](https://i-blog.csdnimg.cn/blog_migrate/46e25d7bbd769e6402ce2d253739779a.webp?x-image-process=image/format,png)
查看data目录返现多了一个data,之前只有name
![image.png](https://i-blog.csdnimg.cn/blog_migrate/a422d9833401da08582075c433c8f073.webp?x-image-process=image/format,png)
可以看到namenode和datanode时同一个集群
<font color="red">注意:</font>
我们重新个数话namenode时得删除date目录还有logs,否则集群起不来
![image.png](https://i-blog.csdnimg.cn/blog_migrate/c0f02f26c074e357959ba47e8525bb58.webp?x-image-process=image/format,png)
并列的logs
Logs目录
通过刚刚的一系列操作我们生成了data和logs
查看logs目录发现有datanode和namenode的日志
![image.png](https://i-blog.csdnimg.cn/blog_migrate/82f56626b8654868bea80b856fed0925.webp?x-image-process=image/format,png)
执行wordcount
在hdfs文件系统上创建输入文件input
[shaozhiqi@hadoop101 hadoop-3.1.2]$ hdfs dfs -mkdir -p /user/shaohadoop/input
这个目录会创建在我们hdfs文件系统上,不是centos的本地路径。
![image.png](https://i-blog.csdnimg.cn/blog_migrate/12aaebe423caa359b8711b4ba75290a4.webp?x-image-process=image/format,png)
将之前我们的wc.input 上传到我们的hdfs的input下
[shaozhiqi@hadoop101 hadoop-3.1.2]$ hdfs dfs -put wcinput/wc.input /user/shaohadoop/input
![image.png](https://i-blog.csdnimg.cn/blog_migrate/ccbc19fe872f62fc9a8756c2e3da7b5c.webp?x-image-process=image/format,png)
![image.png](https://i-blog.csdnimg.cn/blog_migrate/02f9afd07f6f4f24a108f9414f9ef04b.webp?x-image-process=image/format,png)
执行我们的wordcont
[shaozhiqi@hadoop101 hadoop-3.1.2]$ hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.2.jar wordcount /user/shaohadoop/input user/shaohadoop/output
输入路径我们可以用hdfs自定义,但是输出路径自动加了usershaozhiqi,还不太懂
![image.png](https://i-blog.csdnimg.cn/blog_migrate/272639e9450945ce00c082efb5a21a72.webp?x-image-process=image/format,png)
点击part-r 00000,下载后可以看到运行成功
![image.png](https://i-blog.csdnimg.cn/blog_migrate/8f72b9436d5cceaab230dac7553993ab.webp?x-image-process=image/format,png)