关注微信公共号:小程在线
关注CSDN博客:程志伟的博客
一、启动集群
[atguigu@hadoop103 ~]$ cd /opt/module/hadoop-3.1.3/
[atguigu@hadoop102 hadoop-3.1.3]$ sbin/start-dfs.sh
[atguigu@hadoop103 ~]$ cd /opt/module/hadoop-3.1.3/
[atguigu@hadoop103 hadoop-3.1.3]$ sbin/start-yarn.sh
查看是否启动
[atguigu@hadoop102 hadoop-3.1.3]$ jpsall
=============== hadoop102 ===============
2916 NameNode
3037 DataNode
3358 NodeManager
3486 Jps
=============== hadoop103 ===============
3137 NodeManager
2882 DataNode
3026 ResourceManager
3560 Jps
=============== hadoop104 ===============
3154 Jps
2979 NodeManager
2806 DataNode
2872 SecondaryNameNode
二、上传
创建文件夹
[atguigu@hadoop102 hadoop-3.1.3]$ hadoop fs -mkdir /sanguo
进入sanguo文件夹,里面没有数据
2.1 moveFromLocal:从本地剪切粘贴到HDFS
[atguigu@hadoop102 hadoop-3.1.3]$ vim shuguo.txt
输入:shuguo
[atguigu@hadoop102 hadoop-3.1.3]$ hadoop fs -moveFromLocal ./shuguo.txt /sanguo
shuguo.txt文件已经被剪切
刷新一下页面,可以看到shuguo.txt已经存放在sanguo文件夹下面
可以看到里面的内容是shuguo
2.2 copyFromLocal:从本地文件系统中拷贝文件到HDFS路径去
[atguigu@hadoop102 hadoop-3.1.3]$ vim weiguo.txt
输入:weiguo
[atguigu@hadoop102 hadoop-3.1.3]$ hadoop fs -copyFromLocal weiguo.txt /sanguo
从本地复制,weiguo.txt还是存在中
刷新页面,weiguo.txt已经复制到hdfs中,文件内容为weiguo
2.3 put:等同于copyFromLocal,生产环境更习惯用put
[atguigu@hadoop102 hadoop-3.1.3]$ vim wuguo.txt
输入:wuguo
[atguigu@hadoop102 hadoop-3.1.3]$ hadoop fs -put ./wuguo.txt /sanguo
刷新页面,wuguo.txt已经复制到hdfs中,文件内容为wuguo
2.4 appendToFile:追加一个文件到已经存在的文件末尾
[atguigu@hadoop102 hadoop-3.1.3]$ vim liubei.txt
输入:liubei
[atguigu@hadoop102 hadoop-3.1.3]$ hadoop fs -appendToFile liubei.txt /sanguo/shuguo.txt
刷新页面,在shuguo.txt文件下新增liubei的内容
三、下载
3.1 copyToLocal:从HDFS拷贝到本地
[atguigu@hadoop102 hadoop-3.1.3]$ hadoop fs -copyToLocal /sanguo/shuguo.txt ./
3.2 get:等同于copyToLocal,生产环境更习惯用get
[atguigu@hadoop102 hadoop-3.1.3]$ hadoop fs -get /sanguo/shuguo.txt ./shuguo2.txt