一、HDFS基本命令

  1.创建目录:-mkdir

[jun@master ~]$ hadoop fs -mkdir /test
[jun@master ~]$ hadoop fs -mkdir /test/input

  2.查看文件列表:-ls

[jun@master ~]$ hadoop fs -ls /
Found items
drwxr-xr-x - jun supergroup -- : /test
[jun@master ~]$ hadoop fs -ls /test
Found items
drwxr-xr-x - jun supergroup -- : /test/input

  3.上传文件到HDFS

  在/home/jun下新建两个文件jun.dat和jun.txt

  (1)使用-put将文件从本地复制到HDFS集群

[jun@master ~]$ hadoop fs -put /home/jun/jun.dat /test/input/jun.dat

  (2)使用-copyFromLocal将文件从本地复制到HDFS集群

[jun@master ~]$ hadoop fs -copyFromLocal -f /home/jun/jun.txt  /test/input/jun.txt

  (3)查看是否复制成功

[jun@master ~]$ hadoop fs -ls /test/input
Found items
-rw-r--r-- jun supergroup -- : /test/input/jun.dat
-rw-r--r-- jun supergroup -- : /test/input/jun.txt

  4.下载文件到本地

  (1)使用-get将文件从HDFS集群复制到本地

[jun@master ~]$ hadoop fs -get /test/input/jun.dat /home/jun/jun1.dat

  (2)使用-copyToLocal将文件从HDFS集群复制到本地

[jun@master ~]$ hadoop fs -copyToLocal /test/input/jun.txt /home/jun/jun1.txt

  (3)查看是否复制成功

[jun@master ~]$ ls -l /home/jun/
total
drwxr-xr-x. jun jun Jul : Desktop
drwxr-xr-x. jun jun Jul : Documents
drwxr-xr-x. jun jun Jul : Downloads
drwxr-xr-x. jun jun Jul : hadoop
drwxrwxr-x. jun jun Jul : hadoopdata
-rw-r--r--. jun jun Jul : jun1.dat
-rw-r--r--. jun jun Jul : jun1.txt
-rw-rw-r--. jun jun Jul : jun.dat
-rw-rw-r--. jun jun Jul : jun.txt
drwxr-xr-x. jun jun Jul : Music
drwxr-xr-x. jun jun Jul : Pictures
drwxr-xr-x. jun jun Jul : Public
drwxr-xr-x. jun jun Jul : Resources
drwxr-xr-x. jun jun Jul : Templates
drwxr-xr-x. jun jun Jul : Videos

  5.查看HDFS集群中的文件

[jun@master ~]$ hadoop fs -cat /test/input/jun.txt
This is the txt file.
[jun@master ~]$ hadoop fs -text /test/input/jun.txt
This is the txt file.
[jun@master ~]$ hadoop fs -tail /test/input/jun.txt
This is the txt file.

  6.删除HDFS文件

[jun@master ~]$ hadoop fs -rm /test/input/jun.txt
Deleted /test/input/jun.txt
[jun@master ~]$ hadoop fs -ls /test/input
Found items
-rw-r--r-- jun supergroup -- : /test/input/jun.dat

  7.也可以在slave节点上执行命令

[jun@slave0 ~]$ hadoop fs -ls /test/input
Found items
-rw-r--r-- jun supergroup -- : /test/input/jun.dat

  二、在Hadoop集群中运行程序

  Hadoop安装文件中有一个MapReduce示例程序,该程序用来计算圆周率pi的Java程序包,

  参数说明:pi(类名)、10(Map次数)、10(随机生成点的次数)

[jun@master ~]$ hadoop jar /home/jun/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.8..jar pi
Number of Maps =
Samples per Map =
Wrote input for Map #
Wrote input for Map #
Wrote input for Map #
Wrote input for Map #
Wrote input for Map #
Wrote input for Map #
Wrote input for Map #
Wrote input for Map #
Wrote input for Map #
Wrote input for Map #
Starting Job
// :: INFO client.RMProxy: Connecting to ResourceManager at master/192.168.1.100:
// :: INFO input.FileInputFormat: Total input files to process :
// :: INFO mapreduce.JobSubmitter: number of splits:
// :: INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1532226440522_0001
// :: INFO impl.YarnClientImpl: Submitted application application_1532226440522_0001
// :: INFO mapreduce.Job: The url to track the job: http://master:18088/proxy/application_1532226440522_0001/
// :: INFO mapreduce.Job: Running job: job_1532226440522_0001
// :: INFO mapreduce.Job: Job job_1532226440522_0001 running in uber mode : false
// :: INFO mapreduce.Job: map % reduce %
// :: INFO mapreduce.Job: map % reduce %
// :: INFO mapreduce.Job: map % reduce %
// :: INFO mapreduce.Job: map % reduce %
// :: INFO mapreduce.Job: map % reduce %
// :: INFO mapreduce.Job: map % reduce %
// :: INFO mapreduce.Job: Job job_1532226440522_0001 completed successfully
// :: INFO mapreduce.Job: Counters:
File System Counters
FILE: Number of bytes read=
FILE: Number of bytes written=
FILE: Number of read operations=
FILE: Number of large read operations=
FILE: Number of write operations=
HDFS: Number of bytes read=
HDFS: Number of bytes written=
HDFS: Number of read operations=
HDFS: Number of large read operations=
HDFS: Number of write operations=
Job Counters
Launched map tasks=
Launched reduce tasks=
Data-local map tasks=
Total time spent by all maps in occupied slots (ms)=
Total time spent by all reduces in occupied slots (ms)=
Total time spent by all map tasks (ms)=
Total time spent by all reduce tasks (ms)=
Total vcore-milliseconds taken by all map tasks=
Total vcore-milliseconds taken by all reduce tasks=
Total megabyte-milliseconds taken by all map tasks=
Total megabyte-milliseconds taken by all reduce tasks=
Map-Reduce Framework
Map input records=
Map output records=
Map output bytes=
Map output materialized bytes=
Input split bytes=
Combine input records=
Combine output records=
Reduce input groups=
Reduce shuffle bytes=
Reduce input records=
Reduce output records=
Spilled Records=
Shuffled Maps =
Failed Shuffles=
Merged Map outputs=
GC time elapsed (ms)=
CPU time spent (ms)=
Physical memory (bytes) snapshot=
Virtual memory (bytes) snapshot=
Total committed heap usage (bytes)=
Shuffle Errors
BAD_ID=
CONNECTION=
IO_ERROR=
WRONG_LENGTH=
WRONG_MAP=
WRONG_REDUCE=
File Input Format Counters
Bytes Read=
File Output Format Counters
Bytes Written=
Job Finished in 88.689 seconds
Estimated value of Pi is 3.20000000000000000000

  最后可以看到,得到的结果近似为3.2。

HDFS基本命令与Hadoop MapReduce程序的执行的更多相关文章

  1. 使用Python实现Hadoop MapReduce程序

    转自:使用Python实现Hadoop MapReduce程序 英文原文:Writing an Hadoop MapReduce Program in Python 根据上面两篇文章,下面是我在自己的 ...

  2. 简单的java Hadoop MapReduce程序(计算平均成绩)从打包到提交及运行

    [TOC] 简单的java Hadoop MapReduce程序(计算平均成绩)从打包到提交及运行 程序源码 import java.io.IOException; import java.util. ...

  3. [python]使用python实现Hadoop MapReduce程序:计算一组数据的均值和方差

    这是参照<机器学习实战>中第15章“大数据与MapReduce”的内容,因为作者写作时hadoop版本和现在的版本相差很大,所以在Hadoop上运行python写的MapReduce程序时 ...

  4. 用Python语言写Hadoop MapReduce程序Writing an Hadoop MapReduce Program in Python

    In this tutorial I will describe how to write a simple MapReduce program for Hadoop in the Python pr ...

  5. Python实现Hadoop MapReduce程序

    1.概述 Hadoop Streaming提供了一个便于进行MapReduce编程的工具包,使用它可以基于一些可执行命令.脚本语言或其他编程语言来实现Mapper和 Reducer,从而充分利用Had ...

  6. Intellij idea开发Hadoop MapReduce程序

    1.首先下载一个Hadoop包,仅Hadoop即可. http://mirrors.hust.edu.cn/apache/hadoop/common/hadoop-2.6.0/hadoop-2.6.0 ...

  7. Hadoop MapReduce程序中解决第三方jar包问题方案

    hadoop怎样提交多个第三方jar包? 方案1:把所有的第三方jar和自己的class打成一个大的jar包,这种方案显然笨拙,而且更新升级比较繁琐. 方案2: 在你的project里面建立一个lib ...

  8. hadoop——在命令行下编译并运行map-reduce程序 2

     hadoop map-reduce程序的编译需要依赖hadoop的jar包,我尝试javac编译map-reduce时指定-classpath的包路径,但无奈hadoop的jar分布太散乱,根据自己 ...

  9. hadoop-初学者写map-reduce程序中容易出现的问题 3

    1.写hadoop的map-reduce程序之前所必须知道的基础知识: 1)hadoop map-reduce的自带的数据类型: Hadoop提供了如下内容的数据类型,这些数据类型都实现了Writab ...

随机推荐

  1. Java 提取Word中的文本和图片

    本文将介绍通过Java来提取或读取Word文档中文本和图片的方法.这里提取文本和图片包括同时提取文档正文当中以及页眉.页脚中的的文本和图片. 使用工具:Free Spire.Doc for Java ...

  2. Android组件化路由实践

    Android应用组件化各个组件页面之间要实现跳转使用路由是一个很好的选择.本文将实现一个比较轻量级的路由组件,主要涉及以下知识: Annotation (声明路由目标信息) AnnotationPr ...

  3. SD-WAN 配置及应用模板**(二)

    目录 0. 前言 1. 配置模板 1.1 创建各类 'Feature' 模板: 1.1.1 添加波特率模板 1.1.2 添加 'VPN0' 模板 1.1.3 添加 'VPN10' 模板 1.1.4 添 ...

  4. Java利用反射排序

    前言 Java为我们提供了几种排序得方法,比如Arrays和Collections类,但是前提是数组或者集合中的元素都必须实现Comparable接口,基本的数据类型都已经实现了Comparable接 ...

  5. springcloud --- spring cloud sleuth和zipkin日志管理(spring boot 2.18)

    前言 在spring cloud分布式架构中,系统被拆分成了许多个服务单元,业务复杂性提高.如果出现了异常情况,很难定位到错误位置,所以需要实现分布式链路追踪,跟进一个请求有哪些服务参与,参与的顺序如 ...

  6. Future类型的连锁的运用

    Future类型的连锁的运用: 洗脸 刷牙 吃早饭 看电视 出门 串行: import scala.concurrent.{Await, Future} import scala.util.{Fail ...

  7. Eclipse导入别人项目爆红叉

    1.导入项目之前,请确认工作空间编码已设置为utf-8:window->Preferences->General->Wrokspace->Text file encoding- ...

  8. 如何写md格式的文档

    一.标题 标题其实和HTML中的h系列很像,想要设置为标题的文字前面加#来表示一个#是一级标题,二个#是二级标题,以此类推.支持六级标题. 注:标准语法一般在#后跟个空格再写文字, 示例: 效果如下: ...

  9. SQL SERVER数据库,按年、月、日、时、分、秒计算两个时间字段之间的间隔时间样例

    使用DATEDIFF(取值,时间字段1,时间字段2) 举例: SELECT DATEDIFF(YEAR,DRYSJ,DCYSJ),* FROM YXHIS2019..TBZYBR2019 --SQL ...

  10. MySQL复制从库建立-mysqldump方式

    环境准备: master:192.168.0.106:3306slave:192.168.0.105:3306 主和从都必须配置有唯一的ID(server_id:建议ip最后一组+MySQL端口号,例 ...