Hbase/Hdfs刪除節點

jopen 9年前發布 | 23K 次閱讀 分布式/云計算/大數據 HBase

線上有臺服務器隨時可能會掛掉,所以需要把在這個服務器上hbase的regionserver和hdfs的datanode節點移除。然后重新拿臺新服務器部署接管。

之前在文章 http://openskill.cn/article/178 中講到怎么新增一個hdfs的datanode,所以我先講一下怎么添加一個hbase的regionserver,然后再講怎么刪除!

添加hbase regionserver節點

</blockquote>
添加步驟如下:
1、在hbase master上修改regionservers文件
# cd hbase_install_dir/conf

echo "new_hbase_node_hostname" >> ./regionservers</pre>2、如果你hbase集群使用自身zk集群的話,還需要修改hbase-site.xml文件,反之不用操作!
# cd hbase_install_dir/conf

vim hbase-site.xml

找到hbase.zookeeper.quorum屬性 -->加入新節點</pre>3、同步以上修改的文件到hbase的各個節點上
4、在新節點上啟動hbase regionserver

# cd hbase_install_dir/bin/

./hbase-daemon.sh start regionserver</pre>5、在hbasemaster啟動hbase shell
用status命令確認一下集群情況
hbase新增一個 regionserver節點補充完成了,下面介紹刪除hbase和hdfs節點!


集群上既部署有Hadoop,又部署有HBase,因為HBase存儲是基于Hadoop HDFS的, 所以先要移除HBase節點,之后再移除Hadoop節點。添加則反之。

移除hbase regionserver節點

</blockquote>
1、在0.90.2之前,我們只能通過在要卸載的節點上執行;我的hbase版本(0.98.7)
# cd hbase_install_dir

./bin/hbase-daemon.sh stop regionserver</pre>來實現。這條語句執行后,該RegionServer首先關閉其負載的所有Region而后關閉自己。在關閉時,RegionServer在ZooKeeper中的"Ephemeral Node"會失效。此時,Master檢測到RegionServer掛掉并把它作為一個宕機節點,并將該RegionServer上的Region重新分配到其他RegionServer。


注意:使用此方法前,一定要關閉HBase Load Balancer。關閉方法:

hbase(main):001:0> balance_switch false

true

0 row(s) in 0.3290 seconds</pre>總結:

這種方法很大的一個缺點是該節點上的Region會離線很長時間。因為假如該RegionServer上有大量Region的話,因為Region的關閉是順序執行的,第一個關閉的Region得等到和最后一個Region關閉并Assigned后一起上線。這是一個相當漫長的時間。以我這次的實驗為例,現在一臺RegionServer平均有1000個Region,每個Region Assigned需要4s,也就是說光Assigned就至少需要1個小時。
2、自0.90.2之后,HBase添加了一個新的方法,即"graceful_stop",只需要在HBase Master節點執行:
# cd hbase_install_dir

./bin/graceful_stop.sh hostname</pre>該命令會自動關閉Load Balancer,然后Assigned Region,之后會將該節點關閉。除此之外,你還可以查看remove的過程,已經assigned了多少個Region,還剩多少個Region,每個Region 的Assigned耗時。


補充graceful stop的一些其他命令參數:

# ./bin/graceful_stop.sh

Usage: graceful_stop.sh [--config &conf-dir>] [--restart] [--reload] [--thrift] [--rest] &hostname>

thrift If we should stop/start thrift before/after the hbase stop/start

rest If we should stop/start rest before/after the hbase stop/start

restart If we should restart after graceful stop

reload Move offloaded regions back on to the stopped server

debug Move offloaded regions back on to the stopped server

hostname Hostname of server we are to stop</pre>最終都需要我們手動打開load balancer:

hbase(main):001:0> balance_switch true

false

0 row(s) in 0.3290 seconds</pre>對比兩種方法,建議使用"graceful_stop"來移除hbase RegionServer節點。

移除hdfs datanode節點

</blockquote>
1、在core-site.xml文件下新增如下內容
<property>

   <name>dfs.hosts.exclude</name>

   <value>/hdfs_install_dir/conf/excludes</value>

</property></pre>2、創建exclude文件,把需要刪除節點的主機名寫入

# cd hdfs_install_dir/conf

vim excludes

添加需要刪除的節點主機名,比如 hdnode1 保存退出</pre>3、 然后在namenode節點執行如下命令,強制讓namenode重新讀取配置文件,不需要重啟集群。

# cd hdfs_install_dir/bin/

./hadoop dfsadmin -refreshNodes</pre>它會在后臺進行Block塊的移動 4、 查看狀態

等待第三步的操作結束后,需要下架的機器就可以安全的關閉了。

# ./hadoop dfsadmin -report
可以查看到現在集群上連接的節點
正在執行Decommission,會顯示:

Decommission Status : Decommission in progress

執行完畢后,會顯示:

Decommission Status : Decommissioned</pre>如下:

Name: 10.0.180.6:50010

Decommission Status : Decommission in progress

Configured Capacity: 917033340928 (10.83 TB)

DFS Used: 7693401063424 (7 TB)

Non DFS Used: 118121652224 (110.00 GB)

DFS Remaining: 4105510625280(3.63 TB)

DFS Used%: 64.56%

DFS Remaining%: 34.45%

Last contact: Mon Nov 29 23:53:52 CST 2015</pre>也可以直接通過Hadoop 瀏覽器查看:
LIVE的節點可以查看到: http://master_ip:50070/dfsnodelist.jsp?whatNodes=LIVE
查看看到卸載的節點狀態是:Decommission in progress
等待節點完成移除后,瀏覽: http://master_ip:50070/dfsnodelist.jsp?whatNodes=DEAD 結果如下:

 Hbase/Hdfs刪除節點

完成后,刪除的節點顯示在dead nodes中。且其上的服務停止。Live Nodes中僅剩had2,had3
以上即為從Hadoop集群中Remove Node的過程,但是,有一點一定要注意:
hdfs-site.xml配置文件中dfs.replication值必須小于或者等于踢除節點后正常datanode的數量,即:
dfs.replication <= 集群所剩節點數
修改備份系數可以參考: http://heylinux.com/archives/2047.html

重載入刪除的datanode節點

</blockquote>
1、修改namenode的core-site.xml文件,把我們剛剛加入的內容刪除或者注釋掉,我這里選擇注釋掉。
<!--

<property>

    <name>dfs.hosts.exclude</name>

    <value>/root/hadoop/conf/excludes</value>

</property>

--></pre>2、 再執行重載namenode的配置文件

# ./bin/hadoop dfsadmin -refreshNodes
3、最后去啟動datanode上的datanode
# ./bin/hadoop-daemon.sh start datanode

starting datanode, logging to /usr/local/hadoop/bin/../logs/hadoop-root-datanode-had1.out</pre>4、查看啟動情況

# jps

18653 Jps

19687 DataNode ---->啟動正常</pre>重新載入HBase RegionServer節點
只需要重啟regionserver進程即可。

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!