一.创建与查看HDFS目录
每次重启后,Jps和java -version执行出来的结果不符合就使用
`source ~/.bash_profile` 是在 Unix/Linux 系统上用来重新加载用户的 Bash 配置文件 `~/.bash_profile` 的命令。这条命令的作用是使得当前的 Bash 环境重新读取并应用 `~/.bash_profile` 中的设置和变量定义。
首先检查master0、slave0虚拟机网络和java版本("1.7.0_71"),检查后再启动hadoop
[csu@master0 ~]$ cd ~/hadoop-2.6.0
[csu@master0 hadoop-2.6.0]$ sbin/start-all.sh (启动)
[csu@master0 hadoop-2.6.0]$ sbin/stop-all.sh (关闭)
再检查是否启动成功







1、创建HDFS目录:
-p可以递归创建

2、查看之前创建的HDFS目录

注意:因为登录的用户为csu,所以会显示/user/csu下的目录。
3、查看HDFS完整目录
因为hadoop fs -ls只能查看一级目录,所以必须逐级查看:

4、查看所有的HDFS子目录
HDFS提供了一个方便的选项 -R 可以递归查看目录

5、一次性创建所有HDFS子目录
逐级创建很麻烦,但是可以添加参数-p,来一次性创建多级目录:

二.从本地计算机复制文件到HDFS
1、复制本地文件到HDFS:
准备工作,创建本地文件


随便写的内容进去lc.txt
按Esc 再:wq保存退出

2、列出文件内容:

可以使用:hadoop fs -cat /user/hduser/test/test1.txt | more 进行分页显示
3、如果复制到HDFS的文件已经存在,会报错,此时可以使用-f 参数,强制复制重复文件到HDFS目录:

4、从本地复制多个文件到HDFS,中间用空格分割即可。
5、从本地复制整个目录到HDFS:

6、列出HDFS目录下的所有文件(包括这个目录下子目录的文件)

7、使用put复制文件到HDFS,这个参数与copyFromLocal的不同之处在于:
-put更宽松,可以把本地或者HDFS上的文件拷贝到HDFS中;而-copyFromLocal则更严格限制只能拷贝本地文件到HDFS中。如果本地和HDFS上都存在相同路径,则-put跟趋于优先取HDFS的源。(不用太深究两者区别,更多用-put)

三.从HDFS上复制文件到本地
1、参数 -copyToLocal

2、同样的也可以用参数-get完成上述操作:

四.复制与删除HDFS文件
1、使用-cp参数,在HDFS上进行复制文件

2、使用-rm参数,删除HDFS上的文件;添加-R参数,删除目录:


完成实验后一定要关闭 hadoop ,避免下次启动虚拟机时 hadoop 出现问题。

------------学习笔记