HDFS、MapRed、YARN是Hadoop大数据的基础组件,安装好Hadoop之后,这些组件自然包含在里面。
正常安装Hadoop之后,通常可以通过环境变量$HADOOP_HOME知道Hadoop的安装位置:
$ echo $HADOOP_HOME
切换到Hadoop的安装目录,就可以愉快地使用hadoop、hdfs、mapred、yarn命令啦。
Web UI地址:http://localhost:50070,可以看到Hadoop集群的基本状态。
$ hadoop -help # 看一下有什么命令
Usage: hadoop [--config confdir] [COMMAND | CLASSNAME]
CLASSNAME run the class named CLASSNAME
or
where COMMAND is one of:
fs run a generic filesystem user client
version print the version
jar run a jar file
note: please use "yarn jar" to launch
YARN applications, not this command.
checknative [-a|-h] check native hadoop and compression libraries availability
distcp copy file or directories recursively
archive -archiveName NAME -p * create a hadoop archive
classpath prints the class path needed to get the
credential interact with credential providers
Hadoop jar and the required libraries
daemonlog get/set the log level for each daemon
trace view and modify Hadoop tracing settings
Most commands print help when invoked w/o parameters.
$ hadoop version # 查看版本
$ hadoop fs # 文件系统,其实就是HDFS中hdfs dfs命令
所有命令请参考:Hadoop Commands Guide
HDFS(Hadoop Distributed File System)也就是分布式文件系统,使用时当做一个Linux文件系统就OK。
Web UI地址也是:http://localhost:50070,在Utilities选项卡下Browse the file system。
$ hdfs -help
Usage: hdfs [--config confdir] [--loglevel loglevel] COMMAND
where COMMAND is one of:
dfs run a filesystem command on the file systems supported in Hadoop.
classpath prints the classpath
namenode -format format the DFS filesystem
secondarynamenode run the DFS secondary namenode
namenode run the DFS namenode
journalnode run the DFS journalnode
zkfc run the ZK Failover Controller daemon
datanode run a DFS datanode
dfsadmin run a DFS admin client
haadmin run a DFS HA admin client
fsck run a DFS filesystem checking utility
balancer run a cluster balancing utility
jmxget get JMX exported values from NameNode or DataNode.
mover run a utility to move block replicas across
storage types
oiv apply the offline fsimage viewer to an fsimage
oiv_legacy apply the offline fsimage viewer to an legacy fsimage
oev apply the offline edits viewer to an edits file
fetchdt fetch a delegation token from the NameNode
getconf get config values from configuration
groups get the groups which users belong to
snapshotDiff diff two snapshots of a directory or diff the
current directory contents with a snapshot
lsSnapshottableDir list all snapshottable dirs owned by the current user
Use -help to see options
portmap run a portmap service
nfs3 run an NFS version 3 gateway
cacheadmin configure the HDFS cache
crypto configure HDFS encryption zones
storagepolicies list/get/set block storage policies
version print the version
Most commands print help when invoked w/o parameters.
查看文件系统空间大小:
$ hdfs dfs -df [-h]
查看文件大小:
$ hdfs dfs -du [-s] [-h] ...
列出文件:
$ hdfs dfs -ls [-d] [-h] [-R] [ ...]
既然是文件系统,最常用的命令当然是文件的增删改查。
HDFS管理命令,最常用的-report选项可以查看集群运行状态
$ hdfs dfsadmin -report
所有命令请参考:HDFS Commands Guide
查看Block大小和副本数:/app/hadoop/conf/hdfs-site.xml
dfs.block.size
536870912
dfs.replication
3
$ mapred -help
Usage: mapred [--config confdir] [--loglevel loglevel] COMMAND
where COMMAND is one of:
pipes run a Pipes job
job manipulate MapReduce jobs
queue get information regarding JobQueues
classpath prints the class path needed for running
mapreduce subcommands
historyserver run job history servers as a standalone daemon
distcp copy file or directories recursively
archive -archiveName NAME -p * create a hadoop archive
hsadmin job history server admin interface
Most commands print help when invoked w/o parameters.
$ mapred pipes
运行Pipes任务,此功能允许用户使用C++语言进行MapReduce程序设计。它采用的主要方法是将应用逻辑相关的C++代码放在单独的进程中,然后通过Socket让Java代码与C++代码通信。
列出所有队列:
$ mapred queue -list
列出所有任务:
$ mapred job -list all
YARN(Yet Another Resource Negotiator),Hadoop 2.x 新引入的资源管理系统。
Hadoop 1.0采用了JobTracker和TaskTracker来管理资源,但存在单点问题和资源利用率问题。
Web UI地址:http://localhost:8088。
$ yarn -help
Usage: yarn [--config confdir] [COMMAND | CLASSNAME]
CLASSNAME run the class named CLASSNAME
or
where COMMAND is one of:
resourcemanager -format-state-store deletes the RMStateStore
resourcemanager run the ResourceManager
nodemanager run a nodemanager on each slave
timelineserver run the timeline server
rmadmin admin tools
sharedcachemanager run the SharedCacheManager daemon
scmadmin SharedCacheManager admin tools
version print the version
jar run a jar file
application prints application(s)
report/kill application
applicationattempt prints applicationattempt(s)
report
container prints container(s) report
node prints node report(s)
queue prints queue information
logs dump container logs
classpath prints the class path needed to
get the Hadoop jar and the
required libraries
cluster prints cluster information
daemonlog get/set the log level for each
daemon
Most commands print help when invoked w/o parameters.
ResourceManager(RM)
负责对各NM上的资源进行统一管理和调度。将AM分配空闲的Container运行并监控其运行状态。对AM申请的资源请求分配相应的空闲Container。主要由两个组件构成:调度器和应用程序管理器:
调度器(Scheduler):调度器根据容量、队列等限制条件(如每个队列分配一定的资源,最多执行一定数量的作业等),将系统中的资源分配给各个正在运行的应用程序。调度器仅根据各个应用程序的资源需求进行资源分配,而资源分配单位是Container,从而限定每个任务使用的资源量。Shceduler不负责监控或者跟踪应用程序的状态,也不负责任务因为各种原因而需要的重启(由ApplicationMaster负责)。总之,调度器根据应用程序的资源要求,以及集群机器的资源情况,为应用程序分配封装在Container中的资源。 调度器是可插拔的,例如CapacityScheduler、FairScheduler。
应用程序管理器(Applications Manager):应用程序管理器负责管理整个系统中所有应用程序,包括应用程序提交、与调度器协商资源以启动AM、监控AM运行状态并在失败时重新启动等,跟踪分给的Container的进度、状态也是其职责。
NodeManager (NM)
NM是每个节点上的资源和任务管理器。它会定时地向RM汇报本节点上的资源使用情况和各个Container的运行状态;同时会接收并处理来自AM的Container 启动/停止等请求。
ApplicationMaster (AM):
用户提交的应用程序均包含一个AM,负责应用的监控,跟踪应用执行状态,重启失败任务等。ApplicationMaster是应用框架,它负责向ResourceManager协调资源,并且与NodeManager协同工作完成Task的执行和监控。MapReduce就是原生支持的一种框架,可以在YARN上运行Mapreduce作业。有很多分布式应用都开发了对应的应用程序框架,用于在YARN上运行任务,例如Spark,Storm等。如果需要,我们也可以自己写一个符合规范的YARN application。
Container:
Container是YARN中的资源抽象(启动一个Container相当于启动一个进程),它封装了某个节点上的多维度资源,如内存、CPU、磁盘、网络等,当AM向RM申请资源时,RM为AM返回的资源便是用Container 表示的。 YARN会为每个任务分配一个Container且该任务只能使用该Container中描述的资源。
以上摘自此博客。