(二)hadoop脚本分析

1.脚本分析

#启动所有hadoop守护进程
sbin/start-all.sh
    --------------
        libexec/hadoop-config.sh
        start-dfs.sh       #用于启动namenode,datanode,secondarynamenode
        start-yarn.sh      #用于启动nodemanager,resourcemanager

    #用于启动namenode,datanode,secondarynamenode
    sbin/start-dfs.sh
    --------------
        libexec/hadoop-config.sh
        sbin/hadoop-daemons.sh --config .. --hostname .. start namenode ...
        sbin/hadoop-daemons.sh --config .. --hostname .. start datanode ...
        sbin/hadoop-daemons.sh --config .. --hostname .. start sescondarynamenode ...
        sbin/hadoop-daemons.sh --config .. --hostname .. start zkfc ...         //
    
    #用于启动nodemanager,resourcemanager
    sbin/start-yarn.sh
    --------------  
        libexec/yarn-config.sh
        bin/yarn-daemon.sh start resourcemanager
        bin/yarn-daemons.sh start nodemanager
    
    #主要调用hadoop-daemon.sh,其中hadoop-daemons.sh在多个主机上启动,hadoop-daemon.sh在单个主机上启动,并且二者均可用于启动namenode,datanode,secondarynamenode
    sbin/hadoop-daemons.sh
    ----------------------
        libexec/hadoop-config.sh
        slaves
        hadoop-daemon.sh
    #主要调用hdfs命令
    sbin/hadoop-daemon.sh
    -----------------------
        libexec/hadoop-config.sh
        bin/hdfs ....
    #主要调用yarn命令,yarn-daemon.sh和yarn-daemons.sh均可用于启动nodemanager,resourcemanager
    sbin/yarn-daemon.sh
    -----------------------
        libexec/yarn-config.sh
        bin/yarn    

使用stop-dfs.sh和stop-yarn.sh关闭所有hadoop守护进程:

henry@s201:~$ xcall.sh jps
============= s201 jps =============
5828 ResourceManager
5462 NameNode
48363 Jps
5676 SecondaryNameNode
============= s202 jps =============
30546 NodeManager
68245 Jps
30415 DataNode
============= s203 jps =============
68448 Jps
30812 NodeManager
30687 DataNode
============= s204 jps =============
30289 DataNode
68112 Jps
30426 NodeManager
henry@s201:~$ 
henry@s201:~$ 
henry@s201:~$ stop-dfs.sh
Stopping namenodes on [s201]
s201: stopping namenode
s204: stopping datanode
s203: stopping datanode
s202: stopping datanode
Stopping secondary namenodes [0.0.0.0]
0.0.0.0: stopping secondarynamenode
henry@s201:~$ xcall.sh jps
============= s201 jps =============
48772 Jps
5828 ResourceManager
============= s202 jps =============
30546 NodeManager
68349 Jps
============= s203 jps =============
68553 Jps
30812 NodeManager
============= s204 jps =============
68217 Jps
30426 NodeManager
henry@s201:~$ stop-yarn.sh
stopping yarn daemons
stopping resourcemanager
s203: stopping nodemanager
s204: stopping nodemanager
s202: stopping nodemanager
no proxyserver to stop
henry@s201:~$ xcall.sh jps
============= s201 jps =============
48928 Jps
============= s202 jps =============
68453 Jps
============= s203 jps =============
68657 Jps
============= s204 jps =============
68315 Jps

使用hadoop-daemons.sh、hadoop-daemon.sh、yarn-daemons.sh、yarn-daemon.sh启动所有hadoop进程

henry@s201:~$ xcall.sh jps
============= s201 jps =============
51938 Jps
============= s202 jps =============
70422 Jps
============= s203 jps =============
70618 Jps
============= s204 jps =============
70279 Jps
henry@s201:~$ hadoop-daemon.sh start namenode
starting namenode, logging to /home/henry/soft/hadoop-2.7.2/logs/hadoop-henry-namenode-s201.out
henry@s201:~$ jps
52048 Jps
51981 NameNode
henry@s201:~$ hadoop-daemon.sh start secondarynamenode
starting secondarynamenode, logging to /home/henry/soft/hadoop-2.7.2/logs/hadoop-henry-secondarynamenode-s201.out
henry@s201:~$ jps
52128 Jps
52081 SecondaryNameNode
51981 NameNode
henry@s201:~$ hadoop-daemons.sh start datanode
s204: starting datanode, logging to /home/henry/soft/hadoop-2.7.2/logs/hadoop-henry-datanode-s204.out
s203: starting datanode, logging to /home/henry/soft/hadoop-2.7.2/logs/hadoop-henry-datanode-s203.out
s202: starting datanode, logging to /home/henry/soft/hadoop-2.7.2/logs/hadoop-henry-datanode-s202.out
henry@s201:~$ xcall.sh jps
============= s201 jps =============
52208 Jps
52081 SecondaryNameNode
51981 NameNode
============= s202 jps =============
70608 Jps
70503 DataNode
============= s203 jps =============
70698 DataNode
70797 Jps
============= s204 jps =============
70359 DataNode
70458 Jps
henry@s201:~$ yarn-daemons.sh start nodemanager
s204: starting nodemanager, logging to /home/henry/soft/hadoop-2.7.2/logs/yarn-henry-nodemanager-s204.out
s203: starting nodemanager, logging to /home/henry/soft/hadoop-2.7.2/logs/yarn-henry-nodemanager-s203.out
s202: starting nodemanager, logging to /home/henry/soft/hadoop-2.7.2/logs/yarn-henry-nodemanager-s202.out
henry@s201:~$ xcall.sh jps
============= s201 jps =============
52081 SecondaryNameNode
52301 Jps
51981 NameNode
============= s202 jps =============
70675 NodeManager
70503 DataNode
70824 Jps
============= s203 jps =============
71013 Jps
70870 NodeManager
70698 DataNode
============= s204 jps =============
70531 NodeManager
70674 Jps
70359 DataNode
henry@s201:~$ yarn-daemon.sh start resourcemanager
starting resourcemanager, logging to /home/henry/soft/hadoop-2.7.2/logs/yarn-henry-resourcemanager-s201.out
henry@s201:~$ xcall.sh jps
============= s201 jps =============
52081 SecondaryNameNode
52596 Jps
52348 ResourceManager
51981 NameNode
============= s202 jps =============
70675 NodeManager
70503 DataNode
70861 Jps
============= s203 jps =============
71056 Jps
70870 NodeManager
70698 DataNode
============= s204 jps =============
70531 NodeManager
70359 DataNode
70717 Jps

2 常用命令

bin/hadoop
    ------------------------
        hadoop verion       //版本
        hadoop fs           //文件系统客户端.
        hadoop jar          //
        hadoop classpath
        hadoop checknative

    
    bin/hdfs
    ------------------------
        dfs                     // === hadoop fs
        classpath          
        namenode -format   
        secondarynamenode  
        namenode           
        journalnode        
        zkfc               
        datanode           
        dfsadmin           
        haadmin            
        fsck               
        balancer           
        jmxget             
        mover              
                           
        oiv                
        oiv_legacy         
        oev                
        fetchdt            
        getconf            
        groups             
        snapshotDiff       
                           
        lsSnapshottableDir 
                           
        portmap            
        nfs3               
        cacheadmin         
        crypto             
        storagepolicies    
        version 

hdfs常用命令
--------------------
    $>hdfs dfs -mkdir /user/centos/hadoop
    $>hdfs dfs -ls -r /user/centos/hadoop
    $>hdfs dfs -lsr /user/centos/hadoop
    $>hdfs dfs -put index.html /user/centos/hadoop   
    $>hdfs dfs -get /user/centos/hadoop/index.html a.html
    $>hdfs dfs -rm -r -f /user/centos/hadoop
  • hadoop fs命令等价于hdfs dfs命令
  • 使用hdfs dfs -mkdir -p /usr/ubuntu/hadoop
henry@s201:~$ hdfs dfs -mkdir -p /usr/ubuntu/hadoop
henry@s201:~$ hdfs dfs -ls -R /
drwxr-xr-x   - henry supergroup          0 2018-06-26 08:46 /usr
drwxr-xr-x   - henry supergroup          0 2018-06-26 08:46 /usr/ubuntu
drwxr-xr-x   - henry supergroup          0 2018-06-26 08:46 /usr/ubuntu/hadoop

*使用hdfs dfs -put src dst命令上传文件到hadoop文件系统


henry@s201:~$ hdfs dfs -help put
-put [-f] [-p] [-l] <localsrc> ... <dst> :
  Copy files from the local file system into fs. Copying fails if the file already
  exists, unless the -f flag is given.
  Flags:
                                                                       
  -p  Preserves access and modification times, ownership and the mode. 
  -f  Overwrites the destination if it already exists.                 
  -l  Allow DataNode to lazily persist the file to disk. Forces        
         replication factor of 1. This flag will result in reduced
         durability. Use with care.
henry@s201:~$ hdfs dfs -put index.xml /usr/ubuntu/hadoop
henry@s201:~$ hdfs dfs -ls -R /
drwxr-xr-x   - henry supergroup          0 2018-06-26 08:46 /usr
drwxr-xr-x   - henry supergroup          0 2018-06-26 08:46 /usr/ubuntu
drwxr-xr-x   - henry supergroup          0 2018-06-26 08:52 /usr/ubuntu/hadoop
-rw-r--r--   3 henry supergroup        853 2018-06-26 08:52 /usr/ubuntu/hadoop/index.xml
  • 使用hdfs dfs -get命令从hadoop文件系统中下载文件到本地
henry@s201:~$ hdfs dfs -help get
-get [-p] [-ignoreCrc] [-crc] <src> ... <localdst> :
  Copy files that match the file pattern <src> to the local name.  <src> is kept. 
  When copying multiple files, the destination must be a directory. Passing -p
  preserves access and modification times, ownership and the mode.
henry@s201:~$ hdfs dfs -get /usr/ubuntu/hadoop a.xml
henry@s201:~$ ls -l a.xml
total 4
-rw-r--r-- 1 henry henry 853 6月  26 08:58 index.xml
  • 使用hdfs dfs -rm命令删除文件
henry@s201:~$ hdfs dfs -rm -f /usr/ubuntu/hadoop/*
18/06/26 09:00:03 INFO fs.TrashPolicyDefault: Namenode trash configuration: Deletion interval = 0 minutes, Emptier interval = 0 minutes.
Deleted /usr/ubuntu/hadoop/index.xml
henry@s201:~$ hdfs dfs -ls /usr/ubuntu/hadoop
henry@s201:~$ 
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,590评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,808评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,151评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,779评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,773评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,656评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,022评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,678评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 41,038评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,756评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,411评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,005评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,973评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,053评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,495评论 2 343

推荐阅读更多精彩内容