1. 程式人生 > >服務新資料節點和退役舊資料節點

服務新資料節點和退役舊資料節點

服務新資料節點

當原有的資料節點容量達不到儲存資料需求,需要在原有叢集基礎上動態新增新的資料節點

  1. 準備一臺虛擬機器

  2. 修改ip,主機名稱.以及hosts

  3. 配置jdk以及hadoop的環境

  4. 修改xcall和xsync檔案,增加新節點,同步ssh
    修改xcall
    在這裡插入圖片描述
    修改xsync
    在這裡插入圖片描述
    設定免密碼登入

     ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa
    

    將生成的公鑰拷貝到主機testnote1裡 .ssh目錄下 authorized_keys

     scp authorized_keys [email protected]
    :`pwd`

    同步叢集

     xsync authorized_keys
    
  5. 刪除原來HDFS檔案系統的日誌檔案以及 data

具體準備:
6. 在 namenode 的/opt/module/hadoop-2.7.2/etc/hadoop 目錄下建立 dfs.hosts 檔案

[[email protected] .ssh]# cd /opt/module/hadoop-2.7.2/etc/hadoop/
[[email protected] hadoop]# touch dfs.hosts
[[email protected] hadoop]# vim dfs.hosts
testnote01
testnote02
testnote03
testnote04
  1. 在 namenode 的 hdfs-site.xml 配置檔案中增加 dfs.hosts 屬性即testnote01的主機上

     <property>
     <name>dfs.hosts</name>
     <value>/opt/module/hadoop-2.7.2/etc/hadoop/dfs.hosts</value>
     </property>
    
  2. 重新整理namenode

     [[email protected] hadoop]# hdfs dfsadmin -refreshNodes
     Refresh nodes successfu
    
  3. 更新resourcemanager節點

     [[email protected] hadoop]# yarn rmadmin -refreshNodes
     18/11/07 03:54:31 INFO client.RMProxy: Connecting to ResourceManager at testnote02/192.168.18.51:8033
    
  4. 在namenode的slaves檔案中增加新的主機名稱

    [[email protected] hadoop]# cat slaves 
    testnote01
    testnote02
    testnote03
    testnote04
    
  5. 在單獨命令啟動新的資料節點和節點管理器

    [[email protected] .ssh]# hadoop-daemon.sh start datanode
    starting datanode, logging to /opt/module/hadoop-2.7.2/logs/hadoop-root-datanode-testnote04.out
    
    [[email protected] .ssh]# yarn-daemon.sh start nodemanager
    starting nodemanager, logging to /opt/module/hadoop-2.7.2/logs/yarn-root-nodemanager-testnote04.out
    

訪問主頁:http://testnote01:50070/dfshealth.html#tab-overview
點選liveVies
http://testnote01:50070/dfshealth.html#tab-datanode

在這裡插入圖片描述

退役舊資料節點

1)在 namenode 的/opt/module/hadoop-2.7.2/etc/hadoop 目錄下建立 dfs.hosts.exclude 檔案

[[email protected] hadoop-2.7.2]# vim dfs.hosts.exclude
[[email protected] hadoop-2.7.2]# cat dfs.hosts.exclude 
testnote04
/opt/module/hadoop-2.7.2/etc/hadoop/dfs.hosts.exclude 在這個目錄下
  1. 在namenode的hdfs-site.xml的配置檔案中增加dfs.hosts.exclude

     [[email protected] hadoop-2.7.2]# vim etc/hadoop/hdfs-site.xml 
    
     <property>
     <name>dfs.hosts.exclude</name>
     <value>/opt/module/hadoop-2.7.2/etc/hadoop/dfs.hosts.exclude</value>
     </property>
    
  2. 重新整理namenode,重新整理resourcemanager

     [[email protected] hadoop-2.7.2]# hdfs dfsadmin -refreshNodes
     Refresh nodes successful
    
     [[email protected] hadoop-2.7.2]# yarn rmadmin -refreshNodes
     18/11/07 04:39:33 INFO client.RMProxy: Connecting to ResourceManager at testnote02/192.168.18.51:8033
    

4)檢查 web 瀏覽器,退役節點的狀態為 decommission in progress(退役中),說明資料節點正在複製塊到其他節點。
在這裡插入圖片描述

  1. 等待退役節點狀態為 decommissioned(所有塊已經複製完成),停止該節點及節點資源管理器。
    在這裡插入圖片描述

注意:如果副本數是3,服務節點小於等於3,是不能退役成功的,需要修改副本數後才能退役

  1. 停止節點

     [[email protected] .ssh]# hadoop-daemon.sh stop datanode
     stopping datanode
     [[email protected] .ssh]# yarn-daemon.sh stop nodemanager
     stopping nodemanager
    
  2. 從include檔案中刪除退役節點,再執行重新整理節點的命令

     	(1)從 namenode 的 dfs.hosts 檔案中刪除退役節點 testnote04	
     	[[email protected] hadoop]# vim dfs.hosts
     	[[email protected] hadoop]# cat dfs.hosts
     	testnote01
     	testnote02
     	testnote03
     	(2)重新整理namenode,重新整理resourcemanager
     	
     	[[email protected] hadoop]# hdfs dfsadmin -refreshNodes
     	Refresh nodes successful
     	[[email protected] hadoop]# yarn rmadmin -refreshNodes
     	18/11/07 04:51:40 INFO client.RMProxy: Connecting to ResourceManager at testnote02/192.168.18.51:8033
    

在這裡插入圖片描述
沒有節點

  1. 從namenode的slave檔案中刪除退役節點testnote04

     [[email protected] hadoop]# vim slaves 
     [[email protected] hadoop]# cat slaves 
     testnote01
     testnote02
     testnote03
    
  2. 如果資料不平衡,可以用命令實現叢集的再平衡

     [[email protected] hadoop]# start-balancer.sh 
     starting balancer, logging to /opt/module/hadoop-2.7.2/logs/hadoop-root-balancer-testnote01.out
    
  3. 同步檔案實現叢集間的檔案相同

    [[email protected] hadoop]# xsync ./