二、hadoop文件操作
1、使用hadoop命令查看hdfs下文件
[root@localhost hadoop-2.7.2]# hadoop fs -ls hdfs://192.168.211.129:9000/ (最后一定要加/)
开始在xshell上执行这条命令失败,使用netstat -nltp命令查看监听的9000端口,是127.0.0.1:9000,没有找到办法更改这个监听的IP和端口
后来就把etc/hadoop/core-site.xml配置下的localhost改为192.168.211.129,保存配置重启HDFS,使用上面命令还是不行,重启系统后再启动hdfs和yarn,再用上面命令就不报错了,命令执行后没有任何反应,那是因为没有在HDFS系统上存文件
2、上传文件到HDFS系统,例子中上传/jdk-7u80-linux-x64.rpm文件
[root@localhost hadoop-2.7.2]# hadoop fs -put /jdk-7u80-linux-x64.rpm hdfs://192.168.211.129:9000/
上传完成后再查看hdfs下文件
hadoop fs -ls -h hdfs://192.168.211.129:9000//或hadoop fs -ls -h /
[root@localhost sbin]# hadoop fs -ls /
Found 1 items -rw-r--r-- 1 root supergroup 131.7 M 2017-04-19 00:00 /jdk-7u80-linux-x64.rpm
这个上传的文件就被切割成块分别存放在datanode节点上了,由于都在同一台服务器上,那么文件被分的块在路径
/home/hadoop/hadoop-2.7.2/tmp/dfs/data/current/BP-2144136712-127.0.0.1-1492526252533/current/finalized/subdir0/subdir0
进入到该目录可以查看到相关的块信息:
[root@localhost subdir0]# ll
总用量 135916
-rw-r--r--. 1 root root 134217728 4月 19 00:00 blk_1073741825
-rw-r--r--. 1 root root 1048583 4月 19 00:00 blk_1073741825_1001.meta
-rw-r--r--. 1 root root 3872558 4月 19 00:00 blk_1073741826
-rw-r--r--. 1 root root 30263 4月 19 00:00 blk_1073741826_1002.meta
[root@localhost subdir0]# pwd
/home/hadoop/hadoop-2.7.2/tmp/dfs/data/current/BP-2144136712-127.0.0.1-1492526252533/current/finalized/subdir0/subdir0
[root@localhost subdir0]#
3、下载HDFS系统文件
hadoop fs -get hdfs://192.168.211.129:9000/jdk-7u80-linux-x64.rpm或hadoop fs -get /jdk-7u80-linux-x64.rpm
先用ll命令查看当前文件夹下不存在该文件,下载后再查看,该文件已被下载
[root@localhost ~]# ll total 4 -rw-r--r--. 1 root root 8252 4月 17 23:28 install.log.syslog
[root@localhost ~]# hadoop fs -get hdfs://192.168.211.129:9000/jdk-7u80-linux-x64.rpm
[root@localhost ~]# ll
总用量 134904
-rw-------. 1 root root 998 Sep 26 17:58 anaconda-ks.cfg
-rw-r--r--. 1 root root 138090286 4月 19 00:15 jdk-7u80-linux-x64.rpm
[root@localhost ~]#
4、使用mapreduce算法统计单词数量,一般是在Java程序中使用的,这次就直接在hadoop安装目录下mapreduce下的Java例子中实验
1)、首先切换到mapreduce路径下:cd /home/hadoop/hadoop-2.7.2/share/hadoop/mapreduce会看到 hadoop-mapreduce-examples-2.7.2.jar文件
2)、新建一个测试文件,并填写测试数据:vi test.data 里面随便写入英文单词如,Youth is not a time of life; it is a state of mind; it is not a matter of rosy cheeks, red lips and supple knees; it is a matter of the will, a quality of the imagination, a vigor of the emotions; it is the freshness of the deep springs of life.
保存后上传到HDFS系统中
3)、在HDFS系统中新建文件夹存放测试数据:
[root@localhost mapreduce]# hadoop fs -mkdir /test
[root@localhost mapreduce]# hadoop fs -mkdir /test/testdata
[root@localhost mapreduce]# hadoop fs -put test.data /test/testdata
[root@localhost mapreduce]# hadoop fs -ls /
Found 2 items
-rw-r--r-- 1 root supergroup 181310701 2017-04-19 15:35 /jdk-7u80-linux-x64.rpm
drwxr-xr-x - root supergroup 0 2017-04-19 15:35 /test
[root@localhost mapreduce]#
4)、执行单词统计操作,/test/output为输出路径
[root@localhost mapreduce]# hadoop jar hadoop-mapreduce-examples-2.7.2.jar wordcount /test/testdata /test/output
5)、查看输出结果
[root@localhost mapreduce]# hadoop fs -ls /test/output
Found 2 items
-rw-r--r-- 1 root supergroup 0 2017-04-19 15:35 /test/output/_SUCCESS
-rw-r--r-- 1 root supergroup 223 2017-04-19 15:35 /test/output/part-r-00000
[root@localhost mapreduce]# hadoop fs -cat /test/output/part-r-00000
Youth 1
a 6
and 1
cheeks, 1
deep 1
emotions; 1
freshness 1
imagination, 1
is 5
it 4
knees; 1
life. 1
life; 1
lips 1
matter 2
mind; 1
not 2
of 8
quality 1
red 1
rosy 1
springs 1
state 1
supple 1
the 5
time 1
vigor 1
will, 1
二、hadoop文件操作的更多相关文章
- C语言第十二讲,文件操作.
C语言第十二讲,文件操作. 一丶文件操作概述 在操作系统中,我们的文档都称为文件.操作系统也为我们提供了接口进行操作.不同语言都是使用的相同的接口,只不过封装的上层接口不一样 操作文件的步骤 打开文件 ...
- 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作
马士兵hadoop第一课:虚拟机搭建和安装hadoop及启动 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作 马士兵hadoop第三课:java开发hdfs 马士兵hadoop第 ...
- 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作(转)
马士兵hadoop第一课:虚拟机搭建和安装hadoop及启动 马士兵hadoop第二课:hdfs集群集中管理和hadoop文件操作 马士兵hadoop第三课:java开发hdfs 马士兵hadoop第 ...
- 《Java核心技术卷二》笔记(二)文件操作和内存映射文件
文件操作 上一篇已经总结了流操作,其中也包括文件的读写.文件系统除了读写以为还有很多其他的操作,如复制.移动.删除.目录浏览.属性读写等.在Java7之前,一直使用File类用于文件的操作.Java7 ...
- python学习笔记(二)文件操作和集合
集合: 集合也是一种数据类型,一个类似列表东西,它的特点是无序的,不重复的,也就是说集合中是没有重复的数据 集合的作用: 1.它可以把一个列表中重复的数据去掉,而不需要你再写判断 2.可以做关系测试, ...
- 初识Hadoop二,文件操作
1.使用hadoop命令查看hdfs下文件 [root@localhost hadoop-2.7.3]# hadoop fs -ls hdfs://192.168.36.134:9000/ 开始在se ...
- Android入门之文件系统操作(二)文件操作相关指令
(一)获取总根 File[] fileList=File.listRoots(); //返回fileList.length为1 //fileList.getAbsolutePath()为"/ ...
- Hadoop文件操作常用命令
1.创建目录 #hdfs dfs -mkidr /test 2.查询目录结构 #hdfs dfs -ls / 子命令 -R递归查看//查看具体的某个目录:例如#hdfs dfs -ls /test 3 ...
- Java实验——输出一个数组里面连续子数组最大的和(二)文件操作
在本周的练习中,主要是对上周的实验进行健壮性的完善,即在所能考虑到的情况之中,尽量使自己的程序能够正常地运行. 在上周的实验中,我已经是在编程过程中考虑到用户输入的错误类型的问题,所以这一方面并没有多 ...
随机推荐
- 三、SpringBoot-application.properties配置文件和application.yml配置文件
其实SpringBoot的配置文件有.properties和.yml两种形式,两种配置文件的效果类似,只不过是格式不同而已,孩儿们可以根据下面这几种张截图,通过对比端口号的配置,以及连接SQLServ ...
- 开启和查看mysql的bin-log日志
[root@VM_0_7_centos data]# vim /etc/my.cnf [root@VM_0_7_centos data]# vim /etc/my.cnf [root@VM_0_7_c ...
- Linux 意外操作后如何进行数据抢救
Linux 意外操作后如何进行数据抢救 在 GUI 中使用 shift + delete 组合键或是 CLI 下使用 rm -rf 删除选项,这个文件并没有从硬盘(或是其它存储设备)上彻底销毁.当 ...
- 6.HMM
- SDUT OJ 数据结构实验之串一:KMP简单应用 && 浅谈对看毛片算法的理解
数据结构实验之串一:KMP简单应用 Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Descr ...
- docker下ubutun没有ifconfig命令问题
解决: apt-get update #更新apt-get apt install net-tools # ifconfig apt install iputils-ping # ...
- BAM/SAM格式
本质上就是二进制压缩的SAM文件,大部分生物信息学流程都需要这个格式,为了节省存储空间以及方便索引. # BiocInstaller::biocLite('Rsamtools') library(Rs ...
- win10 安装MySQL8.0.11记录。
参考了博客A:https://blog.csdn.net/m0_37788308/article/details/79965378 博客B:https://blog.csdn.net/fxbin123 ...
- 爬虫之re块解析
一.re 这个去匹配比较麻烦,以后也比较少用,简单看一个案例就行 ''' 爬取数据流程: 1.指定url 2.发起请求 3.获取页面数据 4.数据解析 5.持久化存储 ''' import reque ...
- 理解Call、Apply、bind
Apply.call 共同点: 为了改变函数执行时的上下文(简单说就是为了改变当前函数体内的This的指向) 不同点: 传入的参数不一样,func.apply(this,[arg1,arg2]).fu ...